File: columns%28%29.cache%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 (163 lines) | stat: -rw-r--r-- 6,085 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
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
describe('columns- columns().cache()', 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.columns().cache).toBe('function');
		});
		it('Returns an API instance', function() {
			expect(table.columns().cache('search') instanceof $.fn.dataTable.Api).toBe(true);
		});
		it('Defaults to "order"', function() {
			expect(table.columns().cache()[1][0]).toBe(undefined);
		});
		it('Returns data for entire column', function() {
			expect(table.columns().cache().length).toBe(6);
			expect(table.columns().cache()[0].length).toBe(57);

		});
	});

	describe('Check the behaviour (no orthogonal data)', function() {
		dt.html('basic');
		it('Get initial cached order data', function() {
			table = $('#example').DataTable();
			expect(table.columns().cache('order')[0][0]).toBe('airi satou');
		});
		it('Get initial cached search data', function() {
			expect(table.columns().cache('search')[0][0]).toBe('Airi Satou');
		});
		it('Unordered columns not order cached', function() {
			expect(table.columns().cache('order')[1][0]).toBe(undefined);
		});
		it('Unordered columns are search cached', function() {
			expect(table.columns().cache('search')[1][0]).toBe('Accountant');
		});
		it('... after ordering columns are cached for order', function() {
			table.order([1, 'asc']).draw();
			expect(table.columns().cache('order')[1][0]).toBe('accountant');
		});
		it('... after ordering columns are still cached for search', function() {
			expect(table.columns().cache('search')[1][0]).toBe('Accountant');
		});
		it('cache updated if data changed - before draw', function() {
			table.order([0, 'asc']).draw();
			table.cell(2, 0).data('Ashton Coxxx');
			// failing due to DD-975
			// expect(table.columns().cache('search')[0][2]).toBe('ashton coxxx');
		});
		it('cache updated if data changed - after draw', function() {
			table.draw();
			expect(table.columns().cache('search')[0][2]).toBe('Ashton Coxxx');
		});
		it('cache updated if data changed and cell invalidated - before draw', function() {
			$('tbody tr:eq(2) td:eq(0)').html('Ashtonnn');
			table.cell(2, 0).invalidate();
			// failing due to DD-944
			// expect(table.columns().cache('search')[0][2]).toBe('Ashton Coxxx');
		});
		it('cache updated if data changed and cell invalidated - after draw', function() {
			table.draw();
			expect(table.columns().cache('search')[0][2]).toBe('Ashtonnn');
		});
	});

	describe('Check the behaviour (orthogonal data)', function() {
		dt.html('basic');
		it('Get table data', function() {
			table = $('#example').DataTable({
				columnDefs: [
					{
						targets: 0,
						render: function(data, type, row, meta) {
							if (type === 'filter') return 'Filter ' + data;
							if (type === 'sort') return 'Sort ' + data;

							return data;
						}
					}
				]
			});
			expect(table.columns().data()[0][1]).toBe('Angelica Ramos');
		});
		it('Get cached order data', function() {
			expect(table.columns().cache('order')[0][1]).toBe('sort angelica ramos');
		});
		it('Get cached search data', function() {
			expect(table.columns().cache('search')[0][1]).toBe('Filter Angelica Ramos');
		});
		it('cache updated if data changed - before draw', function() {
			table.order([0, 'asc']).draw();
			table.cell(2, 0).data('Ashton Coxxx');
			// failing due to DD-975
			// expect(table.columns().cache('search')[0][2]).toBe('ashton coxxx');
		});
		it('cache updated if data changed - after draw', function() {
			table.draw();
			expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Coxxx');
		});
		it('cache updated if data changed and cell invalidated - before draw', function() {
			$('tbody tr:eq(2) td:eq(0)').html('Filter Ashtonnn');
			table.cell(2, 0).invalidate();
			// failing due to DD-975
			// expect(table.columns().cache('search')[0][2]).toBe('Ashton Coxxx');
		});
		it('cache updated if data changed and cell invalidated - after draw', function() {
			table.draw();
			// failing due to DD-975
			// expect(table.columns().cache('search')[0][2]).toBe('Ashtonnn');
		});
	});

	describe('Functional tests - html5', function() {
		dt.html('html5');
		it('Default - only filter', function() {
			table = $('#example').DataTable();
			expect(table.columns().cache()[0][2]).toBe('ashton cox');
			expect(table.columns().cache()[1][2]).toBe(undefined);
		});
		it('search - only filter', function() {
			expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox');
		});
		it('order - only filter', function() {
			expect(table.columns().cache('order')[0][2]).toBe('ashton cox');
		});
		it('Default - only sort', function() {
			table.order([1, 'asc']).draw();
			expect(table.columns().cache('order')[1][2]).toBe('order chief executive officer (ceo)');
		});
		it('search - only sort', function() {
			expect(table.columns().cache('search')[1][2]).toBe('Chief Executive Officer (CEO)');
		});
		it('Default - only sort', function() {
			expect(table.columns().cache()[1][2]).toBe('order chief executive officer (ceo)');
		});
		it('cache updated if data changed - before draw', function() {
			table.order([0, 'asc']).draw();
			table.cell(2, 0).data('Ashton Coxxx');
			// failing due to DD-975
			// expect(table.column().cache('search')[0][2]).toBe('Filter Ashton Cox');
		});
		it('cache updated if data changed - after draw', function() {
			table.draw();
			expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox');
		});
		it('cache updated if data changed and cell invalidated - before draw', function() {
			$('tbody tr:eq(2) td:eq(0)').html('Ashtonnn');
			table.cell(2, 0).invalidate();
			// failing due to DD-944
			// expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox');
		});
		it('cache updated if data changed and cell invalidated - after draw', function() {
			table.draw();
			expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox');
		});
	});
});