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
|
describe('stateDuration Option', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
describe('Functional tests', function() {
dt.html('basic');
it('Infinite duration', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: 0
});
table.search('cox').draw();
});
dt.html('basic');
it('... keeps value immediately', function() {
table = $('#example').DataTable({
stateSave: true
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Ashton Cox');
});
dt.html('basic');
it('... and after 2 seconds', async function(done) {
await dt.sleep(2000);
table = $('#example').DataTable({
stateSave: true
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Ashton Cox');
done();
});
dt.html('basic');
it('1 second duration', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: 1
});
table.search('cox').draw();
});
dt.html('basic');
it('... keeps value immediately', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: 1
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Ashton Cox');
});
dt.html('basic');
it('... but not after 2 seconds', async function(done) {
await dt.sleep(2000);
table = $('#example').DataTable({
stateSave: true,
stateDuration: 1
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
done();
});
dt.html('basic');
it('1 second duration', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: 1
});
table.search('cox').draw();
table.state.clear();
});
dt.html('basic');
it('... still loses value if state cleared', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: 1
});
expect($('tbody tr:eq(0) td:eq(0)').text()).toBe('Airi Satou');
});
});
describe('old tests (really tests for state().clear()', function() {
dt.html('basic');
it('Test using session storage', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: -1
});
table.state.clear();
expect(sessionStorage['DataTables_example_' + location.pathname]).toBeDefined();
});
dt.html('basic');
it('Test using localStorage', function() {
table = $('#example').DataTable({
stateSave: true,
stateDuration: 1
});
table.state.clear();
expect(localStorage['DataTables_example_' + location.pathname]).toBeDefined();
// The following test should fail - but it is passing due to
// https://sprymedia.atlassian.net/browse/DD-205
// 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);
});
});
});
|