File: rows%28%29.invalidate%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 (187 lines) | stat: -rw-r--r-- 6,224 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
describe('rows- rows().invalidate()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	let table;

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Exists and is a function', function() {
			table = $('#example').DataTable();
			expect(typeof table.rows().invalidate).toBe('function');
		});
		dt.html('basic');
		it('Returns API instance', function() {
			expect(table.rows().invalidate() instanceof $.fn.dataTable.Api).toBe(true);
		});
	});

	function updateRows() {
		for (let i = 0; i < 10; i++) {
			$('#example tbody tr:eq(' + i + ') td:eq(0)').text(
				'Test ' + $('#example tbody tr:eq(' + i + ') td:eq(0)').text()
			);
		}
	}

	describe('Functional tests - DOM sourced', function() {
		dt.html('basic');
		it('Update value in the table', function() {
			table = $('#example').DataTable();

			updateRows();

			expect(table.row(2).data()[0]).toBe('Ashton Cox');
		});
		it('Remains changed when invalidated', function() {
			table.rows([2, 3]).invalidate();
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Test Ashton Cox');
			expect(table.cell(2, 0).data()).toBe('Test Ashton Cox');
			expect(table.cell(3, 0).data()).toBe('Test Cedric Kelly');
		});
		it('Draw causes a reordering', function() {
			table.draw();
			expect(table.cell(2, 0).data()).toBe('Test Ashton Cox');
			expect(table.cell(3, 0).data()).toBe('Test Cedric Kelly');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Test Bradley Greer');
			expect($('#example tbody tr:eq(9) td:eq(0)').text()).toBe('Colleen Hurst');
		});
		it('Same number of rows (not duplicated)', function() {
			expect(table.rows().count()).toBe(57);
		});
		it('Ordering uses new value', function() {
			table.page(4).draw(false);
			expect($('#example tbody tr:eq(7) td:eq(0)').text()).toBe('Test Ashton Cox');
			expect($('#example tbody tr:eq(8) td:eq(0)').text()).toBe('Test Cedric Kelly');
		});
		it('Filtering uses new value', function() {
			table.search('Test Ashton').draw();
			expect($('#example tbody tr').length).toBe(1);
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Test Ashton Cox');
		});

		dt.html('basic');
		it('Column renderer is not called', function() {
			table = $('#example').DataTable({
				columnDefs: [
					{
						targets: 0,
						render: function(data) {
							return data.toUpperCase();
						}
					}
				]
			});

			updateRows();

			table.rows([2, 3]).invalidate();

			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Test ASHTON COX');
			expect($('#example tbody tr:eq(3) td:eq(0)').text()).toBe('Test BRADLEY GREER');
		});
		it('After the draw', function() {
			table.draw();
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Test BRADLEY GREER');
			expect($('#example tbody tr:eq(3) td:eq(0)').text()).toBe('Test BRENDEN WAGNER');
		});

		dt.html('basic');
		it('Use auto for the source', function() {
			table = $('#example').DataTable();
			let data = table.row(2).data();
			data[0] = 'Fred';
			table.rows([2, 3]).invalidate('auto');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Ashton Cox');
			expect(table.row(2).data()[0]).toBe('Ashton Cox');
		});
		it('Use data for the source', function() {
			let data = table.row(2).data();
			data[0] = 'Fred';
			table.rows([2, 3]).invalidate('data');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Fred');
			expect(table.row(2).data()[0]).toBe('Fred');
		});
		it('Use dom for the source', function() {
			let data = table.row(2).data();
			data[0] = 'Stan';
			table.rows([2, 3]).invalidate('dom');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Fred');
			expect(table.row(2).data()[0]).toBe('Fred');
		});
	});

	describe('Functional tests - JS sourced', function() {
		dt.html('empty');
		let table;
		it('Load data', function(done) {
			table = $('#example').DataTable({
				ajax: '/base/test/data/array.txt',
				deferRender: true,
				initComplete: function(settings, json) {
					done();
				}
			});
		});
		it('Update row data', function() {
			let data = table.row(2).data();
			data[0] = 'Fred';
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Ashton Cox');
			expect(table.row(2).data()[0]).toBe('Fred');
		});
		it('Changed when invalidated', function() {
			table.rows([2.3]).invalidate();
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Fred');
			expect(table.row(2).data()[0]).toBe('Fred');
		});
		it('Draw causes a reordering', function() {
			table.draw();
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Bradley Greer');
			expect(table.row(2).data()[0]).toBe('Fred');
		});
		it('Same number of rows (not duplicated)', function() {
			expect(table.rows().count()).toBe(57);
		});
		it('Ordering uses new value', function() {
			table.page(1).draw(false);
			expect($('#example tbody tr:eq(6) td:eq(0)').text()).toBe('Fred');
		});
		it('Filtering uses new value', function() {
			table.search('Fred').draw();
			expect($('#example tbody tr').length).toBe(1);
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Fred');
		});

		dt.html('empty');
		it('Load data', function(done) {
			table = $('#example').DataTable({
				ajax: '/base/test/data/array.txt',
				deferRender: true,
				initComplete: function(settings, json) {
					done();
				}
			});
		});
		it('Use auto for the source', function() {
			table = $('#example').DataTable();
			$('#example tbody tr:eq(2) td:eq(0)').text('Fred');
			table.rows([2, 3]).invalidate('auto');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Ashton Cox');
			expect(table.row(2).data()[0]).toBe('Ashton Cox');
		});
		it('Use data for the source', function() {
			$('#example tbody tr:eq(2) td:eq(0)').text('Fred');
			table.rows([2, 3]).invalidate('data');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Ashton Cox');
			expect(table.row(2).data()[0]).toBe('Ashton Cox');
		});
		it('Use dom for the source', function() {
			$('#example tbody tr:eq(2) td:eq(0)').text('Fred');
			table.rows([2, 3]).invalidate('dom');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Fred');
			expect(table.row(2).data()[0]).toBe('Fred');
		});
	});
});