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

	describe('Check the defaults', function() {
		dt.html('basic');
		it('Default should be set to true', function() {
			$('#example').dataTable();
			expect($.fn.dataTable.defaults.bSort).toBe(true);
		});
		it('Default sorting is enabled', function() {
			expect($('#example thead th:eq(0)').hasClass('sorting_asc')).toBe(true);
		});
	});

	describe('Functional tests', function() {
		dt.html('basic');
		it('Column ordering can be disabled', function() {
			$('#example').dataTable({
				ordering: false
			});
			expect($('#example thead th:eq(0)').hasClass('sorting_disabled')).toBe(true);
		});
		it('Try activate sorting via DOM when disabled', function() {
			$('#example thead th:eq(0)').click();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Tiger Nixon');
		});
		it('Try activate sorting via DOM- when disabled (second click)', function() {
			$('#example thead th:eq(0)').click();
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Tiger Nixon');
		});

		dt.html('basic');
		it('Enabling ordering allows sorting', function() {
			$('#example').dataTable({
				ordering: true
			});
			expect($('#example thead th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
		});
		it("'sorting_desc' is added as a class when a column is clicked on", function() {
			$('#example thead th:eq(0)').click();
			expect($('#example thead th:eq(0)').hasClass('sorting_desc')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Zorita Serrano');
		});
		it("'sorting_asc' is added as a class when a column is clicked on", function() {
			$('#example thead th:eq(0)').click();
			expect($('#example thead th:eq(0)').hasClass('sorting_asc')).toBe(true);
			expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
		});
	});
});