File: stateDuration.js

package info (click to toggle)
datatables.js 1.10.19%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 6,348 kB
  • sloc: xml: 10,397; php: 4,448; sh: 521; makefile: 21
file content (43 lines) | stat: -rw-r--r-- 1,285 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
describe('stateDuration Option', function() {
	dt.libs({
		js: ['jquery', 'datatables'],
		css: ['datatables']
	});

	describe('Default tests', function() {
		dt.html('basic');

		it('Test using session storage', function() {
			$('#example').dataTable({
				stateSave: true,
				stateDuration: -1
			});
			$('#example')
				.DataTable()
				.state.clear();
			expect(sessionStorage['DataTables_example_' + location.pathname]).toBeDefined();
		});

		dt.html('basic');

		it('Test using localStorage', function() {
			$('#example').dataTable({
				stateSave: true,
				stateDuration: 1
			});

			$('#example')
				.DataTable()
				.state.clear();
				
			expect(localStorage['DataTables_example_' + location.pathname]).toBeDefined();

			// The following test should fail - but it is passing due to
			// https://sprymedia.manuscript.com/f/cases/394/API-call-state-clear-isn-t-clearing-the-state
			// remove the test when that bug is fixed - it will cause the test to fail.
			// The second test is just a failsafe to ensure it is behaving, so could optionally be removed
			expect(sessionStorage['DataTables_example_' + location.pathname]).toBeDefined();
			expect($.isEmptyObject($.parseJSON(sessionStorage['DataTables_example_' + location.pathname]))).toBe(true);
		});
	});
});