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
|
describe('core - events - column-visibility', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
let params;
describe('Check the defaults', function() {
dt.html('basic');
it('Called after the draw', function() {
var firstCell;
table = $('#example').DataTable();
table.on('column-visibility.dt', function() {
params = arguments;
firstCell = $('tbody tr:eq(0) td:eq(0)').text();
});
table.column(0).visible(false);
expect(firstCell).toBe('Accountant');
});
it('Called with expected parameters', function() {
expect(params.length).toBe(5);
expect(params[0] instanceof $.Event).toBe(true);
expect(params[1]).toBe(table.settings()[0]);
expect(typeof params[2]).toBe('number');
expect(typeof params[3]).toBe('boolean');
expect(typeof params[4]).toBe('undefined');
});
});
describe('Functional tests', function() {
let count = 0;
let length;
dt.html('basic');
it('Not called on initial draw', function() {
table = $('#example').on('column-visibility.dt', function() {
count++;
params = arguments;
}).DataTable();
expect(count).toBe(0);
});
it('Called when hiding a column', function() {
table.column(1).visible(false);
expect(count).toBe(1);
expect(params[2]).toBe(1);
expect(params[3]).toBe(false);
expect(params[4]).toBe(undefined);
});
it('Called when hiding same column', function() {
table.column(1).visible(false);
// this is disabled due to DD-796
// expect(count).toBe(1);
expect(count).toBe(2);
count--;
});
it('Called when unhiding a column', function() {
table.column(1).visible(true);
expect(count).toBe(2);
expect(params[2]).toBe(1);
expect(params[3]).toBe(true);
expect(params[4]).toBe(undefined);
});
it('Called when hiding multiple columns', function() {
table.columns([3, 4]).visible(false);
expect(count).toBe(4);
expect(params[2]).toBe(4);
expect(params[3]).toBe(false);
expect(params[4]).toBe(undefined);
});
it('Called when unhiding multiple columns', function() {
table.columns([4, 3]).visible(true);
expect(count).toBe(6);
expect(params[2]).toBe(3);
expect(params[3]).toBe(true);
expect(params[4]).toBe(undefined);
});
it('Called when hiding a column with recalc', function() {
table.column(1).visible(false, false);
expect(count).toBe(7);
expect(params[2]).toBe(1);
expect(params[3]).toBe(false);
expect(params[4]).toBe(false);
});
it('Called when unhiding a column with recalc', function() {
table.column(1).visible(true, false);
expect(count).toBe(8);
expect(params[2]).toBe(1);
expect(params[3]).toBe(true);
expect(params[4]).toBe(false);
});
});
});
|