File: isDataTable%28%29.js

package info (click to toggle)
datatables.js 1.10.21%2Bdfsg-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,604 kB
  • sloc: javascript: 64,254; xml: 10,441; php: 4,623; sh: 523; makefile: 21
file content (59 lines) | stat: -rw-r--r-- 2,117 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
describe('Static method - isDataTable()', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

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

	describe('Functional tests', function() {
		let table;
		dt.html('basic');
		it('Returns false before initialisation', function() {
			expect($.fn.dataTable.isDataTable($('#example'))).toBe(false);
		});
		it('Accepts a DataTable table node', function() {
			table = $('#example').DataTable();
			expect($.fn.dataTable.isDataTable($('#example'))).toBe(true);
		});
		it('Other nodes return false', function() {
			expect($.fn.dataTable.isDataTable($('th').get(0))).toBe(false);
			expect($.fn.dataTable.isDataTable($('td').get(0))).toBe(false);
			expect($.fn.dataTable.isDataTable($('div').get(0))).toBe(false);
		});
		it('Can accept  a jQuery selector', function() {
			expect($.fn.dataTable.isDataTable('table.dataTable')).toBe(true);
			expect($.fn.dataTable.isDataTable('div')).toBe(false);
		});
		it('Can accept a DataTable API instance', function() {
			expect($.fn.dataTable.isDataTable(table)).toBe(true);
			expect($.fn.dataTable.isDataTable(1)).toBe(false);
		});

		dt.html('basic');
		it('Returns true for the header in a scrolling table', function() {
			table = $('#example').DataTable({
				scrollY: 200
			});

			var scrollingTable = $(table.table().header()).closest('table');
			expect($.fn.dataTable.isDataTable(scrollingTable)).toBe(true);
		});
		it('Returns true for the body in a scrolling table', function() {
			var scrollingTable = $(table.table().body()).closest('table');
			expect($.fn.dataTable.isDataTable(scrollingTable)).toBe(true);
		});
		it('Returns true for the footer in a scrolling table', function() {
			var scrollingTable = $(table.table().footer()).closest('table');
			expect($.fn.dataTable.isDataTable(scrollingTable)).toBe(true);
		});
	});
});