File: cell%28%29.data%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 (90 lines) | stat: -rw-r--r-- 2,600 bytes parent folder | download | duplicates (3)
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
describe('cells - cell().data()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Check the defaults', function() {
		dt.html('basic');
		let table;
		it('Exists and is a function', function() {
			table = $('#example').DataTable();
			expect(typeof table.cell().data).toBe('function');
		});
		it('Getter returns an array', function() {
			expect(typeof table.cell().data()).toBe('string');
		});
		it('Setter returns an API instance', function() {
			expect(table.cell().data('Fred') instanceof $.fn.dataTable.Api).toBe(true);
		});
	});

	describe('Functional tests - Getter', function() {
		dt.html('basic');
		it('Returns expected data', function() {
			let table = $('#example').DataTable();
			expect(table.cell(2, 0).data()).toBe('Ashton Cox');
		});

		dt.html('basic');
		it('Returns original data, not rendered', function() {
			table = $('#example').DataTable({
				columnDefs: [
					{
						targets: 0,
						render: function(data) {
							return data.toUpperCase();
						}
					}
				]
			});
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('ASHTON COX');
			expect(table.cell(2, 0).data()).toBe('Ashton Cox');
		});
	});

	describe('Functional tests - Setter', function() {
		dt.html('basic');
		let table;
		it('Updates before the draw', function() {
			table = $('#example').DataTable();
			table.cell(2, 0).data('Fred');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('Fred');
			expect(table.cell(2, 0).data()).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.cell(2, 0).data()).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('basic');
		it('Column renderer is still called', function() {
			table = $('#example').DataTable({
				columnDefs: [
					{
						targets: 0,
						render: function(data) {
							return data.toUpperCase();
						}
					}
				]
			});
			table.cell(2, 0).data('Fred');
			expect($('#example tbody tr:eq(2) td:eq(0)').text()).toBe('FRED');
			expect(table.cell(2, 0).data()).toBe('Fred');
		});
	});
});