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 115 116 117 118 119 120 121 122
|
// todo tests - write the tests...
describe('rows - rows()', 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().rows).toBe('function');
});
it('Returns an API instance', function() {
let table = $('#example').DataTable();
expect(table.rows() instanceof $.fn.dataTable.Api).toBe(true);
});
});
describe('Check the behaviour (just rowSelector)', function() {
dt.html('basic');
var table;
it('select all rows - no selector', function() {
table = $('#example').DataTable();
expect(table.rows().count()).toBe(57);
});
it('select all rows - undefined selector', function() {
expect(table.rows(undefined).count()).toBe(57);
});
it('select all rows - null selector', function() {
expect(table.rows(null).count()).toBe(57);
});
it('select one row - 0 selector', function() {
expect(table.rows(0).count()).toBe(1);
});
it('Select nodes by `tr` selector', function() {
expect(table.rows('tr').count()).toBe(57);
});
it('Select nodes by `tr` selector', function() {
expect(table.rows('tr:eq(1)').count()).toBe(1);
});
it('Selector will gather rows uniquely', function() {
expect(table.rows(['tr', 'tr']).count()).toBe(57);
});
});
describe('Check the behaviour (with modifier)', function() {
dt.html('basic');
var table;
it('page - current', function() {
table = $('#example').DataTable();
table.page(1).draw(false);
rows = table.rows('tr', { page: 'current' });
expect(rows.count()).toBe(10);
expect(rows.data()[0][0]).toBe('Charde Marshall');
expect(rows.data()[9][0]).toBe('Gavin Joyce');
});
it('page - all', function() {
rows = table.rows('tr', { page: 'all' });
expect(rows.count()).toBe(57);
expect(rows.data()[0][0]).toBe('Airi Satou');
expect(rows.data()[9][0]).toBe('Cedric Kelly');
});
it('order - current', function() {
table.order([3, 'asc']).draw();
rows = table.rows('tr', { order: 'current' });
expect(rows.count()).toBe(57);
expect(rows.data()[0][0]).toBe('Tatyana Fitzpatrick');
});
it('order - applied', function() {
table.order([3, 'asc']).draw();
rows = table.rows('tr', { order: 'applied' });
expect(rows.count()).toBe(57);
expect(rows.data()[0][0]).toBe('Tatyana Fitzpatrick');
});
it('order - index', function() {
table.order([3, 'asc']).draw();
rows = table.rows('tr', { order: 'index' });
expect(rows.count()).toBe(57);
expect(rows.data()[0][0]).toBe('Tiger Nixon');
});
it('order - original', function() {
table.order([3, 'asc']).draw();
rows = table.rows('tr', { order: 'original' });
expect(rows.count()).toBe(57);
expect(rows.data()[0][0]).toBe('Tiger Nixon');
});
it('search - applied', function() {
table.search('33').draw();
rows = table.rows('tr', { search: 'applied' });
expect(rows.count()).toBe(2);
expect(rows.data()[0][0]).toBe('Cedric Kelly');
});
it('search - none', function() {
rows = table.rows('tr', { search: 'none' });
expect(rows.count()).toBe(57);
expect(rows.data()[0][0]).toBe('Tatyana Fitzpatrick');
});
it('search - none', function() {
rows = table.rows('tr', { search: 'removed' });
expect(rows.count()).toBe(55);
expect(rows.data()[0][0]).toBe('Tatyana Fitzpatrick');
});
});
});
|