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
|
describe('rows - row.add()', 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() {
expect(typeof $('#example').DataTable().row.add).toBe('function');
});
it('Returns API instance', function() {
table = $('#example').DataTable();
expect(
table.row.add(['Fred Johnson', 'Accountant', 'Edinburgh', 24, '2009/11/28', '$65,000']) instanceof
$.fn.dataTable.Api
).toBe(true);
});
});
function isFredThere() {
table = $('#example').DataTable();
table.search('Fred Johnson').draw();
if (
$('div.dataTables_info').text() != 'Showing 1 to 1 of 1 entries (filtered from 58 total entries)' ||
$('#example tbody tr:eq(0) td:eq(0)').text() != 'Fred Johnson'
) {
return false;
}
return true;
}
describe('Functional tests', function() {
dt.html('basic');
it('No change until the draw', function() {
let row = ['Fred Johnson', 'Accountant', 'Edinburgh', 24, '2009/11/28', '$65,000'];
table = $('#example').DataTable();
table.row.add(row);
expect(table.rows().count()).toBe(58);
expect($('div.dataTables_info').text()).toBe('Showing 1 to 10 of 57 entries');
});
dt.html('basic');
it('Add row as an Array', function() {
let row = ['Fred Johnson', 'Accountant', 'Edinburgh', 24, '2009/11/28', '$65,000'];
table = $('#example').DataTable();
table.row.add(row);
expect(isFredThere()).toBe(true);
});
dt.html('basic');
it('Add row as an Object', function() {
let table = $('#example').DataTable({
columns: dt.getTestColumns()
});
table.row
.add({
name: 'Fred Johnson',
position: 'Accountant',
office: 'Edinburgh',
age: '24',
start_date: '2011/04/25',
salary: '$3,120'
})
.draw();
expect(isFredThere()).toBe(true);
});
dt.html('basic');
it('Add row as a Node', function() {
table = $('#example').DataTable();
let clone = table
.row(1)
.node()
.cloneNode(true);
clone.cells[0].innerText = 'Fred Johnson';
table.row.add(clone);
expect(isFredThere()).toBe(true);
});
});
describe('Adding new row to HTML5 attr sourced orthogonal table', function() {
dt.html('html5');
it('Add row as a Node', function() {
table = $('#example').DataTable();
table
.row.add({
0: {
display: 'Jadzia',
'@data-filter': 'Dax'
},
1: {
display: 'Know it all',
'@data-sort': '1'
},
2: 'DS9',
3: '213',
4: '2012/03/29',
5: '0'
})
.search('Dax')
.draw();
expect($('#example tbody td:eq(0)').text()).toBe('Jadzia');
} );
});
});
|