File: page.len%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 (149 lines) | stat: -rw-r--r-- 3,706 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
describe('core - page.len()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	function checkTableLength(pageLen, infoLength = pageLen, tableLength = pageLen) {
		let table = $('#example').DataTable();

		// check APIs knowledge of the table
		expect(table.page.len()).toBe(pageLen);
		expect(table.page.info().length).toBe(infoLength);

		// check DOM for number of rows and the reported number of rows
		expect($('#example tbody tr').length).toBe(tableLength);
		expect(
			parseInt(
				$('div.dataTables_info')
					.text()
					.split(' ')[3]
			)
		).toBe(tableLength);
	}

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Exists and is a function', function() {
			let table = $('#example').DataTable();
			expect(typeof table.page.len).toBe('function');
		});

		it('Getter returns an integer', function() {
			let table = $('#example').DataTable();
			expect(Number.isInteger(table.page.len())).toBe(true);
		});

		it('Setter returns an API instance', function() {
			var table = $('#example').DataTable();
			expect(table.page.len(5) instanceof $.fn.dataTable.Api).toBe(true);
		});
	});

	describe('Check the getter behaviour', function() {
		dt.html('basic');
		it('Expected default length', function() {
			let table = $('#example').DataTable();
			checkTableLength(10);
		});

		dt.html('basic');
		it('Page lengthcan be set to 1 during initialisation', function() {
			let table = $('#example').DataTable({
				pageLength: 1
			});
			checkTableLength(1);
		});

		dt.html('basic');
		it('Page lengthcan be set to 5 during initialisation', function() {
			let table = $('#example').DataTable({
				pageLength: 5
			});
			checkTableLength(5);
		});

		dt.html('basic');
		it('Page lengthcan be set to 10 during initialisation', function() {
			let table = $('#example').DataTable({
				pageLength: 10
			});
			checkTableLength(10);
		});

		dt.html('basic');
		it('Ensure page length greater than the number of records', function() {
			let table = $('#example').DataTable({
				pageLength: 100
			});
			checkTableLength(100, 100, 57);
		});

		dt.html('basic');
		it('Ensure setting page length to be -1 during initialisation shows all', function() {
			let table = $('#example').DataTable({
				pageLength: -1
			});
			checkTableLength(-1, -1, 57);
		});
	});

	describe('Check the setter behaviour', function() {
		dt.html('basic');
		it('Page length in the DOM does not change before the draw', function() {
			$('#example')
				.DataTable()
				.page.len(15);
			checkTableLength(15, 15, 10);
		});

		it('Page length can be set to 1 through the API', function() {
			$('#example')
				.DataTable()
				.page.len(1)
				.draw();
			checkTableLength(1);
		});

		it('Page lengthcan be set to 5 through the API', function() {
			$('#example')
				.DataTable()
				.page.len(5)
				.draw();
			checkTableLength(5);
		});

		it('Page lengthcan be set to 10 through the API', function() {
			$('#example')
				.DataTable()
				.page.len(10)
				.draw();
			checkTableLength(10);
		});

		it('Ensure page length greater than the number of records', function() {
			$('#example')
				.DataTable()
				.page.len(100)
				.draw();
			checkTableLength(100, 100, 57);
		});

		it('Ensure setting page length to be -1 through the API shows all', function() {
			$('#example')
				.DataTable()
				.page.len(-1)
				.draw();
			checkTableLength(-1, -1, 57);
		});
	});

	describe('Advanced behaviour', function() {
		dt.html('basic');
		it('Has no effect if paging disabled at initialisation', function() {
			let table = $('#example').DataTable({ paging: false });
			table.page.len(15);
			checkTableLength(15, -1, 57);
		});
	});
});