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
|
describe('columns - column().nodes()', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
function checkNodes(nodes, length) {
expect(nodes.count()).toBe(length);
for (let i = 0; i < length; i++) {
expect(nodes[i] instanceof HTMLElement).toBe(true);
}
}
describe('Check the defaults', function() {
dt.html('basic');
it('Exists and is a function', function() {
let table = $('#example').DataTable();
expect(typeof table.column().nodes).toBe('function');
});
dt.html('basic');
it('Returns an API instance', function() {
let table = $('#example').DataTable();
expect(table.column().nodes() instanceof $.fn.dataTable.Api).toBe(true);
});
});
describe('Check DOM behaviour', function() {
dt.html('basic');
it('Return data contains 1d array of correct length', function() {
let table = $('#example').DataTable();
checkNodes(table.column(1).nodes(), 57);
});
dt.html('basic');
it('Returned data is for correct column', function() {
let table = $('#example').DataTable();
expect(table.column(1).nodes()[0].textContent).toBe('Accountant');
});
});
describe('Check AJAX behaviour', function() {
dt.html('empty');
it('AJAX sourced table with deferRender- Is it a function', function(done) {
let table = $('#example').DataTable({
ajax: '/base/test/data/data.txt',
deferRender: true,
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'age' },
{ data: 'start_date' },
{ data: 'salary' }
],
initComplete: function(settings, json) {
expect(typeof table.column().nodes).toBe('function');
done();
}
});
});
dt.html('empty');
it('AJAX sourced table with deferRender - Returns an API instance', function(done) {
let table = $('#example').DataTable({
ajax: '/base/test/data/data.txt',
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'age' },
{ data: 'start_date' },
{ data: 'salary' }
],
initComplete: function(settings, json) {
expect(table.column().nodes() instanceof $.fn.dataTable.Api).toBe(true);
done();
}
});
});
dt.html('empty');
it('AJAX sourced table with deferRender - Return data contains array of correct length', function(done) {
let table = $('#example').DataTable({
ajax: '/base/test/data/data.txt',
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'age' },
{ data: 'start_date' },
{ data: 'salary' }
],
initComplete: function(settings, json) {
checkNodes(table.column(1).nodes(), 57);
done();
}
});
});
dt.html('empty');
it('AJAX sourced table with deferRender - Returned data is for correct column', function(done) {
let table = $('#example').DataTable({
ajax: '/base/test/data/data.txt',
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'age' },
{ data: 'start_date' },
{ data: 'salary' }
],
initComplete: function(settings, json) {
expect(table.column(1).nodes()[0].textContent).toBe('Accountant');
done();
}
});
});
});
});
|