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

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

		dt.html('basic');
		it('Count the arguments', function() {
			table = $('#example').DataTable({
				infoCallback: function() {
					args = arguments;
					return 'unit test';
				}
			});
			expect(args.length).toBe(6);
		});
		it('First arg is settings', function() {
			expect(args[0]).toBe(table.settings()[0]);
		});
		it('Second arg is start position', function() {
			expect(typeof args[1]).toBe('number');
		});
		it('Third arg is end position', function() {
			expect(typeof args[2]).toBe('number');
		});
		it('Fourth arg is max', function() {
			expect(typeof args[3]).toBe('number');
		});
		it('Fifth arg is total', function() {
			expect(typeof args[4]).toBe('number');
		});
		it('Sixth arg is pre', function() {
			expect(typeof args[5]).toBe('string');
		});
		it('Return values is used', function() {
			expect($('div.dataTables_info').text()).toBe('unit test');
		});
	});

	describe('Functional tests', function() {
		function check(start, end, max, total, pre) {
			expect(args[1]).toBe(start);
			expect(args[2]).toBe(end);
			expect(args[3]).toBe(max);
			expect(args[4]).toBe(total);
			expect(args[5]).toBe(pre);
		}

		let args;
		let table;
		let testString = 'unit test';

		dt.html('basic');
		it('At initialisation', function() {
			table = $('#example').DataTable({
				infoCallback: function() {
					args = arguments;
					return testString;
				}
			});

			check(1, 10, 57, 57, 'Showing 1 to 10 of 57 entries');
		});
		it('At page change', function() {
			table.page(1).draw('page');
			check(11, 20, 57, 57, 'Showing 11 to 20 of 57 entries');
		});
		it('Searching', function() {
			table.search('Cox').draw();
			check(1, 1, 57, 1, 'Showing 1 to 1 of 1 entries (filtered from 57 total entries)');
		});

		dt.html('basic');
		it('info option disabled', function() {
			args = null;
			table = $('#example').DataTable({
				info: false,
				infoCallback: function() {
					args = arguments;
					return testString;
				}
			});
			expect(args).toBe(null);
		});

		dt.html('basic');
		it('info option disabled in DOM', function() {
			args = null;
			table = $('#example').DataTable({
				dom: 'lfrtp',
				infoCallback: function() {
					args = arguments;
					return testString;
				}
			});
			expect(args).toBe(null);
		});
	});
});