File: cells%28%29.indexes%28%29.js

package info (click to toggle)
datatables.js 1.10.19%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,348 kB
  • sloc: xml: 10,397; php: 4,448; sh: 521; makefile: 21
file content (71 lines) | stat: -rw-r--r-- 2,000 bytes parent folder | download
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
describe('cells - cells().indexes()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Check the defaults', function() {
		dt.html('basic');

		it('Exists and is a function', function() {
			let table = $('#example').DataTable();
			expect(typeof table.cells().indexes).toBe('function');
		});

		it('Returns an API instance', function() {
			let table = $('#example').DataTable();
			expect(table.cells().indexes() instanceof $.fn.dataTable.Api).toBe(true);
		});

		it('Returns an object containing three integers', function() {
			let table = $('#example').DataTable();
			let cellIdx = table.cells(0, 0).indexes()[0];

			expect(Object.keys(cellIdx).length).toBe(3);

			expect(Number.isInteger(cellIdx.row)).toBe(true);
			expect(Number.isInteger(cellIdx.column)).toBe(true);
			expect(Number.isInteger(cellIdx.columnVisible)).toBe(true);
		});
	});

	describe('Check behaviour', function() {
		dt.html('basic');

		it('Correct cell indexes when no columns hidden', function() {
			let table = $('#example').DataTable();

			$(table.row(2).node()).addClass('selected');
			let cellIdx = table.cells('.selected', '*').indexes();

			expect(cellIdx.length).toBe(6);

			for (let i = 0; i < table.columns().count(); i++) {
				expect(cellIdx[i].row).toBe(2);
				expect(cellIdx[i].column).toBe(i);
				expect(cellIdx[i].columnVisible).toBe(i);
			}
		});

		dt.html('basic');

		it('Correct indexes if one column is hidden', function() {
			let table = $('#example').DataTable();
			$(table.row(2).node()).addClass('selected');
			table.column(1).visible(false);

			let cellIdx = table.cells('.selected', '*').indexes();
			let columnVisible = null;

			expect(cellIdx.length).toBe(6);

			for (let i = 0; i < table.columns().count(); i++) {
				expect(cellIdx[i].row).toBe(2);
				expect(cellIdx[i].column).toBe(i);

				columnVisible = i == 1 ? null : i < 1 ? i : i - 1;
				expect(cellIdx[i].columnVisible).toBe(columnVisible);
			}
		});
	});
});