File: column%28%29.header%28%29.js

package info (click to toggle)
datatables.js 1.10.13%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,232 kB
  • ctags: 1,329
  • sloc: xml: 10,249; php: 4,387; sh: 492; makefile: 21
file content (101 lines) | stat: -rw-r--r-- 3,711 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// todo tests
// - Confirm it exists and is a function
// - Confirm it returns a node
// - One row in header:
//   - Select the first column and get its header cell
//   - Select the last column and get its header cell
// - Two rows in header:
//   - Select the first column and get its header cell - only bottom cell for that column is returned
//   - Select the last column and get its header cell - only bottom cell for that column is returned
//   - Set `orderCellsTop: true` and repeat above two tests to check the top cell is returned
// - Test with a scrolling table
// - Hide a column - ensure that its header node can still be accessed with this method

describe( "columns- column().header()", function() {
	dt.libs( {
		js:  [ 'jquery', 'datatables' ],
		css: [ 'datatables' ]
	} );

	describe("Check the defaults", function () {
		dt.html( 'basic' );
		it("Exists and is a function", function () {
			var table = $('#example').DataTable();
			expect(typeof table.column().header).toBe('function');
		});
		dt.html( 'basic' );
		it("Returns an API instance", function () {
			var table = $('#example').DataTable();
			expect(table.column().header() instanceof Node).toBe(true);
		});
		dt.html( 'basic' );
		it("One row in header: Select first column return header cell", function () {
			var table = $('#example').DataTable();
			var returnData = table.column(0).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Name").toBe(true);
		});
		dt.html( 'basic' );
		it("One row in header: Select last column return header cell", function () {
			var table = $('#example').DataTable();
			var returnData = table.column(-1).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Salary").toBe(true);
		});
		dt.html( 'two_headers' );
		it("Two rows in header: Selecting column returns bottom row", function () {
			var table = $('#example').DataTable();
			var returnData = table.column(0).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Name1").toBe(true);
		});
		dt.html( 'two_headers' );
		it("Two rows in header: Selecting last column returns bottom row", function () {
			var table = $('#example').DataTable();
			var returnData = table.column(-1).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Salary1").toBe(true);
		});
		dt.html( 'two_headers' );
		it("orderCellsTop: true- Selecting first column returns top row", function () {
			var table = $('#example').DataTable({
				"orderCellsTop": true
			});
			var returnData = table.column(0).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Name").toBe(true);

		});
		dt.html( 'two_headers' );
		it("orderCellsTop: true- Selecting last column returns top row", function () {
			var table = $('#example').DataTable({
				"orderCellsTop": true
			});
			var returnData = table.column(-1).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Salary").toBe(true);
		});


		dt.html('basic');
		it("Scrolling table with header", function () {
			var table = $('#example').DataTable({
				"scrollY":        "200px",
				"scrollCollapse": true,
				"paging":         false
			});
			var returnData = table.column(0).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Name").toBe(true);
		});
		dt.html( 'basic' );
		it("Hidden column", function () {
			var table = $('#example').DataTable({
				"columnDefs": [
					{
						"targets": [ 0 ],
						"visible": false,
						"searchable": false
					}
				]
			});
			var returnData = table.column(0).header();
			expect(returnData.nodeName == "TH" && returnData.textContent == "Name").toBe(true);
		});

	});

});