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
|
// todo tests
// - Confirm it exists and is a function
// - Confirm it returns an API instance (checking contents for the following tests)
// - One row in footer:
// - Select the first and last columns and get its footer cells
// - Select the second column only and get its footer cell
// - Two rows in footer:
// - Select the first and third columns and get their footer cell - only first cells for those columns are in the result
// - Select the last column and get its footer cell - only first cell for that column is returned
// - Test with no footer, make sure null is returned for all columns
// - Test with a scrolling table that has a footer
// - Hide columns - ensure that their footer nodes can still be accessed with this method
describe( "columns- columns().footer()", function() {
dt.libs( {
js: [ 'jquery', 'datatables' ],
css: [ 'datatables' ]
} );
describe("Check the defaults", function () {
dt.html( 'basic' );
it("Exists and is a function", function () {
var table = $('#example').DataTable();
expect(typeof table.columns().footer).toBe('function');
});
dt.html( 'basic' );
it("Returns an API instance", function () {
var table = $('#example').DataTable();
expect(table.columns().footer() instanceof $.fn.dataTable.Api).toBe(true);
});
dt.html( 'basic' );
it("One row in footer: Select first and last columns return footer cells", function () {
var table = $('#example').DataTable();
var returnData = table.columns([0,-1]).footer();
expect(
returnData[0].nodeName == "TH" &&
returnData[1].nodeName == "TH" &&
returnData[0].textContent == "Name" &&
returnData[1].textContent == "Salary").toBe(true);
});
dt.html( 'basic' );
it("One row in footer: Select second column return footer cell", function () {
var table = $('#example').DataTable();
var returnData = table.columns(1).footer();
expect(returnData[0].nodeName == "TH" && returnData[0].textContent == "Position").toBe(true);
});
dt.html( 'two_footers' );
it("Two rows in footer: Select last column return footer cell", function () {
var table = $('#example').DataTable();
var returnData = table.columns([0,2]).footer();
expect(
returnData[0].nodeName == "TH" &&
returnData[1].nodeName == "TH" &&
returnData[0].textContent == "Name" &&
returnData[1].textContent == "Office").toBe(true);
});
dt.html( 'two_footers' );
it("One row in footer: Select last column return footer cell", function () {
var table = $('#example').DataTable();
var returnData = table.columns(-1).footer();
expect(returnData[0].nodeName == "TH" && returnData[0].textContent == "Salary").toBe(true);
});
dt.html( 'no_footer' );
it("One row in footer: Select last column return footer cell", function () {
var table = $('#example').DataTable();
var returnData;
var result = true;
for( var x = 0; x<6; x++){
returnData = table.columns(x).footer();
if(returnData[0] !== null){
result = false;
return result;
}
}
expect(result).toBe(true);
});
dt.html('basic');
it("Scrolling table with footer", function () {
var table = $('#example').DataTable({
"scrollY": "200px",
"scrollCollapse": true,
"paging": false
});
var returnData = table.columns(0).footer();
expect(returnData[0].nodeName == "TH" && returnData[0].textContent == "Name").toBe(true);
});
dt.html( 'basic' );
it("Hidden column", function () {
var table = $('#example').DataTable({
"columnDefs": [
{
"targets": [ 0 ],
"visible": false,
"searchable": false
}
]
});
var returnData = table.columns(0).footer();
expect(returnData[0].nodeName == "TH" && returnData[0].textContent == "Name").toBe(true);
});
});
});
|