File: footerCallback.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 (95 lines) | stat: -rw-r--r-- 2,516 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
describe('footerCallback Option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Check the arguments', function() {
		let args;

		dt.html('basic');
		it('Default should not be true', function() {
			$('#example').dataTable();
			expect($.fn.dataTable.defaults.fnFooterCallback).not.toBe(true);
		});

		dt.html('basic');
		it('Five arguments', function() {
			$('#example').DataTable({
				footerCallback: function() {
					args = arguments;
					$(args[0])
						.find('th')
						.eq(0)
						.html('unit test');
				}
			});
			expect(args.length).toBe(5);
		});
		it('First arg is the tfoot', function() {
			expect(args[0] instanceof HTMLTableRowElement).toBe(true);
		});
		it('Second arg is data', function() {
			expect(args[1] instanceof Array).toBe(true);
		});
		it('Third arg is start position', function() {
			expect(typeof args[2]).toBe('number');
		});
		it('Fourth arg is end position', function() {
			expect(typeof args[3]).toBe('number');
		});
		it('Fifth arg is index array', function() {
			expect(args[4] instanceof Array).toBe(true);
		});
		it('Return value is used', function() {
			expect($('table tfoot tr th:eq(0)').text()).toBe('unit test');
		});
	});

	describe('Functional tests', function() {
		let args;
		let count = 0;
		let table;

		dt.html('basic');
		it('Called only on a draw', function() {
			table = $('#example').DataTable({
				footerCallback: function() {
					count++;
					args = arguments;
				}
			});
			expect(count).toBe(1);
		});
		it('Subsequent draws call the function', function() {
			table.draw();
			expect(count).toBe(2);
		});
		it('Start contains correct page information', function() {
			expect(args[2]).toBe(0);
		});
		it('End contains correct page information', function() {
			expect(args[3]).toBe(10);
		});
		it('Called on paging (ie another draw)', function() {
			$('a.paginate_button.next').click();
			expect(count).toBe(3);
		});
		it('Data array has length matching original data', function() {
			expect(args[1].length).toBe(57);
		});
		it('Start contains correct page information', function() {
			expect(args[2]).toBe(10);
		});
		it('End contains correct page information', function() {
			expect(args[3]).toBe(20);
		});
		it('Display length is full data when not filtered', function() {
			expect(args[4].length).toBe(57);
		});
		it('Display length is 12 when filtering on London', function() {
			table.search('London').draw();
			expect(args[4].length).toBe(12);
		});
	});
});