File: tables%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 (123 lines) | stat: -rw-r--r-- 3,851 bytes parent folder | download
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
describe('Static method - tables()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	let tables;

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Exists and is a function', function() {
			expect(typeof $.fn.dataTable.tables).toBe('function');
			expect(typeof $.fn.dataTable.tables).toBe('function');

		});
		it('Returns empty array if no tables', function() {
			tables = $.fn.dataTable.tables();
			expect(tables instanceof Array).toBe(true);
			expect(tables.length).toBe(0);

			tables = DataTable.tables();
			expect(tables instanceof Array).toBe(true);
			expect(tables.length).toBe(0);
		});
		it('Returns HTML elements by default', function() {
			$('#example').DataTable();
			tables = $.fn.dataTable.tables();

			expect(tables.length).toBe(1);
			expect(tables[0] instanceof HTMLElement).toBe(true);

			tables = DataTable.tables();

			expect(tables.length).toBe(1);
			expect(tables[0] instanceof HTMLElement).toBe(true);
		});
		it('Returns API instance', function() {
			tables = $.fn.dataTable.tables({ api: true });
			expect(tables.length).toBe(0);
			expect(tables instanceof $.fn.dataTable.Api).toBe(true);

			tables = DataTable.tables({ api: true });
			expect(tables.length).toBe(0);
			expect(tables instanceof $.fn.dataTable.Api).toBe(true);			
		});
		it('Returns visible tables', function() {
			tables = $.fn.dataTable.tables({ visible: true });
			expect(tables.length).toBe(1);
			expect(tables[0] instanceof HTMLElement).toBe(true);

			tables = DataTable.tables({ visible: true });
			expect(tables.length).toBe(1);
			expect(tables[0] instanceof HTMLElement).toBe(true);
		});
		it('Returns hidden tables', function() {
			$('div.dataTables_wrapper').hide();
			tables = $.fn.dataTable.tables({ visible: false });
			expect(tables.length).toBe(1);
			expect(tables[0] instanceof HTMLElement).toBe(true);

			tables = DataTable.tables({ visible: false });
			expect(tables.length).toBe(1);
			expect(tables[0] instanceof HTMLElement).toBe(true);
		});
		it('Doesnt return hidden tables', function() {
			$('div.dataTables_wrapper').hide();
			tables = $.fn.dataTable.tables({ visible: true });
			expect(tables.length).toBe(0);

			tables = DataTable.tables({ visible: true });
			expect(tables.length).toBe(0);
		});
	});

	describe('Functional tests', function() {
		let table1, table2;

		dt.html('two_tables');
		it('Returns empty array if no tables', function() {
			tables = $.fn.dataTable.tables();
			expect(tables instanceof Array).toBe(true);
			expect(tables.length).toBe(0);
		});
		it('Initialise one', function() {
			table1 = $('#example_two').DataTable();
			tables = $.fn.dataTable.tables();

			expect(tables.length).toBe(1);
			expect($(tables[0]).attr('id')).toBe('example_two');
		});
		it('Initialise both', function() {
			table1 = $('#example_one').DataTable();
			tables = $.fn.dataTable.tables();

			expect(tables.length).toBe(2);
			expect($(tables[0]).attr('id')).toBe('example_two');
			expect($(tables[1]).attr('id')).toBe('example_one');
		});
		it('Can issue API calls on both', function() {
			table1 = $('#example_one').DataTable();
			$.fn.dataTable
				.tables({ api: true })
				.search('Cox')
				.draw();

			expect($('#example_one tbody tr:eq(0) td:eq(0)').text()).toBe('Ashton Cox');
			expect($('#example_two tbody tr:eq(0) td:eq(0)').text()).toBe('No matching records found');
		});
		it('Returns visible tables', function() {
			$('div.dataTables_wrapper:eq(0)').hide();

			tables = $.fn.dataTable.tables({ visible: true });
			expect(tables.length).toBe(1);
			expect($(tables[0]).attr('id')).toBe('example_two');
		});
		it('Returns all tables', function() {
			$('div.dataTables_wrapper:eq(0)').hide();

			tables = $.fn.dataTable.tables({ visible: false });
			expect(tables.length).toBe(2);
		});
	});
});