File: orderClasses.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 (101 lines) | stat: -rw-r--r-- 3,642 bytes parent folder | download | duplicates (4)
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
describe('orderClasses option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Enabled by default', function() {
			$('#example').dataTable();
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1'));
		});

		dt.html('basic');
		it('Applied to single column', function() {
			$('#example').dataTable({
				order: [[0, 'desc']]
			});

			expect($('#example tbody tr:eq(0) td:eq(0)').attr('class')).toBe('sorting_1');

			expect($('#example tbody tr:eq(0) td:eq(1)').attr('class')).toBe(undefined);
			expect($('#example tbody tr:eq(0) td:eq(2)').attr('class')).toBe(undefined);
			expect($('#example tbody tr:eq(0) td:eq(3)').attr('class')).toBe(undefined);
			expect($('#example tbody tr:eq(0) td:eq(4)').attr('class')).toBe(undefined);
			expect($('#example tbody tr:eq(0) td:eq(5)').attr('class')).toBe(undefined);
		});

		dt.html('basic');
		it('Applied to multiple columns', function() {
			$('#example').dataTable({
				order: [[0, 'desc'], [1, 'desc']]
			});
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2')).toBe(true);
		});

		dt.html('basic');
		it('Applied to a third column', function() {
			$('#example').dataTable({
				order: [[0, 'desc'], [1, 'desc'], [2, 'asc']]
			});
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3')).toBe(true);
		});

		dt.html('basic');
		it('Applied to a 4th column', function() {
			$('#example').dataTable({
				order: [[0, 'desc'], [1, 'desc'], [2, 'asc'], [3, 'desc']]
			});
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_2')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_3')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(3)').hasClass('sorting_3')).toBe(true);
		});
	});

	describe('Can be disabled', function() {
		dt.html('basic');
		it('Can be turned off', function() {
			$('#example').dataTable({
				orderClasses: false,
			});
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1')).toBe(false);
		});

		it('Add column 2- no effect', function() {
			var clickEvent = $.Event('click');
			clickEvent.shiftKey = true;
			$('#example thead th:eq(1)').trigger(clickEvent);
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1')).toBe(false);
			expect($('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_1')).toBe(false);
		});

		it('Add column 3- no effect', function() {
			var clickEvent = $.Event('click');
			clickEvent.shiftKey = true;
			$('#example thead th:eq(2)').trigger(clickEvent);
			expect($('#example tbody tr:eq(0) td:eq(0)').hasClass('sorting_1')).toBe(false);
			expect($('#example tbody tr:eq(0) td:eq(1)').hasClass('sorting_1')).toBe(false);
			expect($('#example tbody tr:eq(0) td:eq(2)').hasClass('sorting_1')).toBe(false);
		});
	});

	describe('Functional tests', function() {
		dt.html('two_tables');
		it('When multiple tables all OK', function() {
			$('#example_one').DataTable({
				orderClasses: false,
			});
			$('#example_two').DataTable({
				orderClasses: true,
			});

			expect($('#example_one tbody tr:eq(0) td:eq(0)').attr('class')).toBe(undefined);
			expect($('#example_two tbody tr:eq(0) td:eq(0)').attr('class')).toBe('sorting_1');			
		});
	});
});