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

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

		dt.html('basic');
		it('One argument passed', function() {
			let test = 0;
			$('#example').dataTable({
				drawCallback: function() {
					test = arguments.length;
				}
			});
			expect(test).toBe(1);
		});

		dt.html('basic');
		it('That one argument is the settings object', function() {
			let table = $('#example').DataTable({
				drawCallback: function(settings) {
					test = settings;
				}
			});
			expect(table.settings()[0]).toBe(test);
		});

		dt.html('basic');
		it('Context is correct', function() {
			let test = 0;
			$('#example').dataTable({
				drawCallback: function() {
					test = this.api()
						.columns()
						.count();
				}
			});
			expect(test).toBe(6);
		});
	});

	describe('Functional tests', function() {
		dt.html('basic');
		it('drawCallback called after the draw', function() {
			let test = 0;
			$('#example').dataTable({
				drawCallback: function() {
					test = $('#example tbody tr').length;
				}
			});
			$('div.dataTables_filter input')
				.val('developer')
				.keyup();
			expect(test).toBe(8);
		});

		dt.html('basic');
		let test = 0;
		it('drawCallback called once on first draw', function() {
			$('#example').dataTable({
				drawCallback: function() {
					test++;
				}
			});
			expect(test).toBe(1);
		});

		it('drawCallback called once when paging', function() {
			$('.paginate_button.next').click();
			expect(test).toBe(2);
		});

		it('drawCallback called once when filtering', function() {
			$('div.dataTables_filter input')
				.val('Accountant')
				.keyup();
			expect(test).toBe(3);
		});

		it('drawCallback called once when ordering', function() {
			$('#example thead th:eq(3)').click();
			expect(test).toBe(4);
		});
	});

	describe('Integration style tests', function() {
		dt.html('basic');
		it('Server-side processing', function(done) {
			let test = 0;
			let table = $('#example').DataTable({
				processing: true,
				serverSide: true,
				displayStart: 20,
				lengthMenu: [15, 30, 45, 60],
				ajax: dt.serverSide,
				drawCallback: function() {
					test++;
				},
				initComplete: function(setting, json) {
					expect(test).toBe(1);
					done();
				}
			});
		});

		dt.html('basic');
		it('Server-side processing', function(done) {
			let test = 0;
			let table = $('#example').DataTable({
				processing: true,
				serverSide: true,
				displayStart: 20,
				deferRendering: true,
				lengthMenu: [15, 30, 45, 60],
				ajax: dt.serverSide,
				drawCallback: function() {
					test++;
				},
				initComplete: function(setting, json) {
					expect(test).toBe(1);
					done();
				}
			});
		});
	});
});