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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
describe('footerCallback option', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
describe('Check the defaults', function() {
dt.html('basic');
it('Default should not be true', function() {
$('#example').dataTable();
expect($.fn.dataTable.defaults.fnFooterCallback).not.toBe(true);
});
dt.html('basic');
it('Five arguments pass', function() {
test = -1;
$('#example').dataTable({
footerCallback: function() {
test = arguments.length;
}
});
expect(test == 5).toBe(true);
});
dt.html('basic');
it('footerCallback called once per draw', function() {
test = 0;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
test++;
}
});
expect(test == 1).toBe(true);
});
it('rooterCallback called on paging (ie another draw)', function() {
$('#example_next').click();
expect(test == 2).toBe(true);
});
dt.html('basic');
it('footerCallback allows ut to alter row information', function() {
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
tfoot.getElementsByTagName('th')[0].innerHTML =
'Displaying ' + (end - start) + ' records';
}
});
expect(
$('#example tfoot th:eq(0)').html() == 'Displaying 10 records'
).toBe(true);
});
dt.html('basic');
it('Data array has length matching original data', function() {
test = true;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
if (data.length != 57) {
test = false;
}
}
});
expect(test === true).toBe(true);
});
dt.html('basic');
it("Data array's column lengths match original data", function() {
test = true;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
for (var i = 0, length = data.length; i < length; i++) {
if (data[i].length != 6) {
test = false;
}
}
}
});
expect(test === true).toBe(true);
});
dt.html('basic');
it('start correct on first page', function() {
test = true;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
if (start !== 0) {
test = false;
}
}
});
expect(test === true).toBe(true);
});
dt.html('basic');
it('start correct on second page', function() {
test = false;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
if (start == 10) {
test = true;
}
}
});
$('#example_next').click();
expect(test === true).toBe(true);
});
dt.html('basic');
it('End correct on first page', function() {
test = false;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
if (end != 10) {
test = true;
}
}
});
$('#example_next').click();
expect(test === true).toBe(true);
});
dt.html('basic');
it('Display Length is full data when not filtered', function() {
test = false;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
if (display.length == 57) {
test = true;
}
}
});
expect(test === true).toBe(true);
});
dt.html('basic');
it('Display length is 12 when filtering on London ', function() {
test = false;
$('#example').dataTable({
footerCallback: function(tfoot, data, start, end, display) {
if (display.length == 12) {
test = true;
}
}
});
$('#example')
.DataTable()
.search('London')
.draw();
expect(test === true).toBe(true);
});
});
});
|