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 - page()', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
describe('Check the defaults', function() {
dt.html('basic');
it('Exists and is a function', function() {
expect(typeof $('#example').DataTable().page).toBe('function');
});
it('Getter returns an integer', function() {
let table = $('#example').DataTable();
expect(Number.isInteger(table.page())).toBe(true);
});
it('Setter returns an API instance', function() {
let table = $('#example').DataTable();
expect(table.page(1) instanceof $.fn.dataTable.Api).toBe(true);
});
});
describe('Check the getter behaviour', function() {
dt.html('basic');
it('Starts on page 0', function() {
let table = $('#example').DataTable();
expect(table.page()).toBe(0);
});
dt.html('basic');
it('Report last page', function() {
let table = $('#example').DataTable();
table.page('last').draw(false);
expect(table.page()).toBe(5);
});
dt.html('basic');
it('Report correctly if starting off first page', function() {
let table = $('#example').DataTable({
displayStart: 45
});
expect(table.page()).toBe(4);
});
});
describe('Check the setter behaviour', function() {
dt.html('basic');
it('Move page numerically', function() {
let table = $('#example').DataTable();
table.page(2).draw(false);
expect(table.page()).toBe(2);
});
it('Move page with next', function() {
let table = $('#example').DataTable();
table.page('next').draw(false);
expect(table.page()).toBe(3);
});
it('Move page with previous', function() {
let table = $('#example').DataTable();
table.page('previous').draw(false);
expect(table.page()).toBe(2);
});
it('Move page with first', function() {
let table = $('#example').DataTable();
table.page(2).draw(false);
expect(table.page()).toBe(2);
});
it('Move page with last', function() {
let table = $('#example').DataTable();
table.page(2).draw(false);
expect(table.page()).toBe(2);
});
it('Bad numeric page reverts to first page ', function() {
let table = $('#example').DataTable();
table.page(10).draw(false);
expect(table.page()).toBe(0);
});
});
});
|