File: rows%28%29.nodes%28%29.js

package info (click to toggle)
datatables.js 1.11.5%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 22,848 kB
  • sloc: javascript: 65,075; xml: 10,712; php: 4,741; sh: 544; makefile: 18
file content (138 lines) | stat: -rw-r--r-- 3,613 bytes parent folder | download | duplicates (4)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
describe('rows - rows().nodes()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	function checkNodes(nodes, length) {
		expect(nodes.count()).toBe(length);
		for (let i = 0; i < length; i++) {
			expect(nodes[i] instanceof HTMLTableRowElement).toBe(true);
		}
	}

	function checkNodeContent(node, expected) {
		expect(node.textContent.trim().split('\n')[0]).toBe(expected);
	}

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Exists and is a function', function() {
			let table = $('#example').DataTable();
			expect(typeof table.rows().nodes).toBe('function');
		});

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

	describe('Check API behaviour', function() {
		dt.html('basic');
		it('Returns an array of HTML elements', function() {
			let table = $('#example').DataTable();
			let nodes = table.rows(0).nodes();

			checkNodes(nodes, 1);
			checkNodeContent(nodes[0], 'Tiger Nixon');
		});

		dt.html('basic');
		it('Returns all rows', function() {
			let table = $('#example').DataTable();
			let nodes = table.rows().nodes();

			checkNodes(nodes, 57);
			checkNodeContent(nodes[0], 'Airi Satou');
			checkNodeContent(nodes[56], 'Zorita Serrano');
		});

		dt.html('basic');
		it('Correct rows assigned class on current page', function() {
			let table = $('#example').DataTable();
			$(table.rows([2, 3]).nodes()).addClass('myTest');

			let nodes = table.rows('.myTest').nodes();

			checkNodes(nodes, 2);
			checkNodeContent(nodes[0], 'Ashton Cox');
			checkNodeContent(nodes[1], 'Cedric Kelly');
		});

		dt.html('basic');
		it('Correct rows assigned class on different page', function() {
			let table = $('#example').DataTable();
			$(table.rows([0, 2]).nodes()).addClass('myTest');

			let nodes = table.rows('.myTest').nodes();

			checkNodes(nodes, 2);
			checkNodeContent(nodes[0], 'Ashton Cox');
			checkNodeContent(nodes[1], 'Tiger Nixon');
		});

		dt.html('basic');
		it('Classes can be added and removed', function() {
			let table = $('#example').DataTable();
			$(table.rows([1, 2]).nodes()).addClass('myTest');
			expect(
				table
					.rows('.myTest')
					.nodes()
					.count()
			).toBe(2);

			$(table.rows([1, 2]).nodes()).removeClass('myTest');
			expect(
				table
					.rows('.myTest')
					.nodes()
					.count()
			).toBe(0);
		});
	});

	describe('Check DOM access', function() {
		dt.html('basic');
		it('Correct DOM rows assigned class on current page', function() {
			let table = $('#example').DataTable();
			$(table.rows([2, 3]).nodes()).addClass('myTest');

			let nodes = $('.myTest');

			expect(nodes.length).toBe(2);
			checkNodeContent(nodes[0], 'Ashton Cox');
			checkNodeContent(nodes[1], 'Cedric Kelly');
		});

		dt.html('basic');
		it('Correct DOM rows assigned class only on current page', function() {
			let table = $('#example').DataTable();
			$(table.rows([0, 2]).nodes()).addClass('myTest');

			let nodes = $('.myTest');

			expect(nodes.length).toBe(1);
			checkNodeContent(nodes[0], 'Ashton Cox');
		});

		dt.html('basic');
		it('Correct DOM rows assigned class only on scrolling table', function() {
			let table = $('#example').DataTable({
				scrollY: '200px',
				scrollCollapse: true,
				paging: false
			});

			$(table.rows([0, 2]).nodes()).addClass('myTest');

			let nodes = $('.myTest');

			expect(nodes.length).toBe(2);
			checkNodeContent(nodes[0], 'Ashton Cox');
			checkNodeContent(nodes[1], 'Tiger Nixon');
		});
	});
});