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
|
describe('cells - cells().indexes()', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
describe('Check the defaults', function() {
dt.html('basic');
it('Exists and is a function', function() {
table = $('#example').DataTable();
expect(typeof table.cells().indexes).toBe('function');
});
it('Returns an API instance', function() {
expect(table.cells().indexes() instanceof $.fn.dataTable.Api).toBe(true);
});
it('Returns an object containing three integers', function() {
let cellIdx = table.cells(0, 0).indexes()[0];
expect(Object.keys(cellIdx).length).toBe(3);
expect(Number.isInteger(cellIdx.row)).toBe(true);
expect(Number.isInteger(cellIdx.column)).toBe(true);
expect(Number.isInteger(cellIdx.columnVisible)).toBe(true);
});
});
describe('Check behaviour', function() {
dt.html('basic');
it('Correct cell indexes when no columns hidden', function() {
table = $('#example').DataTable();
$(table.row(2).node()).addClass('selected');
let cellIdx = table.cells('.selected', '*').indexes();
expect(cellIdx.length).toBe(6);
for (let i = 0; i < table.columns().count(); i++) {
expect(cellIdx[i].row).toBe(2);
expect(cellIdx[i].column).toBe(i);
expect(cellIdx[i].columnVisible).toBe(i);
}
});
it('Correct indexes if one column is hidden', function() {
$(table.row(2).node()).addClass('selected');
table.column(1).visible(false);
let cellIdx = table.cells('.selected', '*').indexes();
let columnVisible = null;
expect(cellIdx.length).toBe(6);
for (let i = 0; i < table.columns().count(); i++) {
expect(cellIdx[i].row).toBe(2);
expect(cellIdx[i].column).toBe(i);
columnVisible = i == 1 ? null : i < 1 ? i : i - 1;
expect(cellIdx[i].columnVisible).toBe(columnVisible);
}
});
});
});
|