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
|
describe('core - events - stateLoadParams', function() {
// TK COLIN this is pretty much the same as stateLoaded - so could do some refactoring here.
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
let count = 0;
let params;
let firstCell;
describe('Check the defaults', function() {
// Clear down save state before proceeding (otherwise old stuff may be lurking that will affect us)
dt.html('basic');
it('Clear state save', function() {
let table = $('#example').DataTable();
table.state.clear();
});
dt.html('basic');
it('Create a saved state', function() {
let table = $('#example').DataTable({
stateSave: true
});
table.state.save();
});
dt.html('basic');
it('Called during initialisation', function() {
table = $('#example')
.on('stateLoadParams.dt', function() {
params = arguments;
count++;
})
.DataTable({
stateSave: true
});
expect(count).toBe(1);
});
it('Called with expected parameters', function() {
expect(params.length).toBe(3);
expect(params[0] instanceof $.Event).toBe(true);
expect(params[1]).toBe(table.settings()[0]);
expect(typeof params[2]).toBe('object');
expect(params[2].length).toBe(10);
});
});
describe('Functional tests', function() {
dt.html('basic');
it('Not called if no stateSave', function() {
count = 0;
table = $('#example')
.on('stateLoadParams.dt', function() {
params = arguments;
count++;
})
.DataTable({
stateSave: false
});
expect(count).toBe(0);
});
dt.html('basic');
it('Called if stateSave', function() {
count = 0;
table = $('#example')
.on('stateLoadParams.dt', function() {
params = arguments;
count++;
})
.DataTable({
stateSave: true
});
expect(count).toBe(1);
});
it('Not called if state saved', function() {
table.state.save();
expect(count).toBe(1);
});
});
});
|