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 143 144 145 146 147 148 149 150 151 152 153 154 155
|
describe( "headerCallback 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.fnHeaderCallback).not.toBe(true);
//$.fn.DataTable.defaults
});
dt.html( 'basic' );
it("Five arguments passed", function () {
test = -1;
$('#example').dataTable( {
"headerCallback": function() {
test = arguments.length;
}
});
expect(test == 5).toBe(true);
});
dt.html( 'basic' );
it("headerCallback called once per draw", function () {
test = 0;
$('#example').dataTable( {
"headerCallback": function( thead, data, start, end, display ) {
test++;
}
});
expect(test == 1).toBe(true);
});
it("headerCallback called on on paging (ie another draw)", function () {
$('#example_next').click();
expect(test == 2).toBe(true);
});
dt.html( 'basic' );
it("headerCallback allows us to alter row information", function () {
$('#example').dataTable( {
"headerCallback": function( thead, data, start, end, display ) {
thead.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
}
});
expect($('#example thead 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( {
"headerCallback": function( thead, data, start, end, display ) {
if ( data.length != 57){
test = false;
}
}
});
expect(test === true).toBe(true);
});
dt.html( 'basic' );
it("Data array has length matching original data", function () {
test = true;
$('#example').dataTable( {
"headerCallback": function( thead, 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( {
"headerCallback": function( thead, 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( {
"headerCallback": function( thead, 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 = true;
$('#example').dataTable( {
"headerCallback": function( thead, data, start, end, display ) {
if ( end !== 10 ){
test = false;
}
}
});
expect(test === true).toBe(true);
});
dt.html( 'basic' );
it("end correct on second page", function () {
test = false;
$('#example').dataTable( {
"headerCallback": function( thead, data, start, end, display ) {
if ( end !== 20 ){
test = true;
}
}
});
expect(test === true).toBe(true);
});
dt.html( 'basic' );
it("Display length is full data when not filtered", function () {
test = false;
$('#example').dataTable( {
"headerCallback": function( thead, 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( {
"headerCallback": function( thead, data, start, end, display ) {
if ( display.length == 12 ){
test = true;
}
}
});
$('#example').DataTable().search('London').draw();
expect(test === true).toBe(true);
});
});
});
|