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
|
// todo tests
// - Confirm it exists and is a function
// - Confirm it returns an API instance
// - Select a column - ensure that the API instance contains the nodes for that column and returned API instance is the right length (obviously don't check every single node!)
// - Test using Ajax sourced table with deferRender
describe( "columns- column().nodes()", 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.column().nodes).toBe('function');
});
dt.html( 'basic' );
it("Returns an API instance", function () {
var table = $('#example').DataTable();
expect(table.column().nodes() instanceof $.fn.dataTable.Api).toBe(true);
});
dt.html( 'basic' );
it("Return data contains 1d array of correct length(57)", function () {
var table = $('#example').DataTable();
var test = table.column(1).nodes();
expect(test.length === 57).toBe(true);
});
dt.html( 'basic' );
it("Returned data is for correct column", function () {
var table = $('#example').DataTable();
var test = table.column(1).nodes();
expect(test[0].nodeName == "TD" && test[0].textContent == "Accountant").toBe(true);
});
//AJAX
dt.html( 'empty' );
it("AJAX sourced table with deferRender- Is it a function", function (done) {
var table = $('#example').DataTable({
"ajax": '/base/test/data/data.txt',
"deferRender": true,
columns: [
{ data: "name" },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ 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) {
var table = $('#example').DataTable({
"ajax": '/base/test/data/data.txt',
columns: [
{ data: "name" },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ 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 1d array of correct length(57)", function (done) {
var table = $('#example').DataTable({
"ajax": '/base/test/data/data.txt',
columns: [
{ data: "name" },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data: "salary" }
],
initComplete: function ( settings, json ) {
var test = table.column(1).nodes();
expect(test.length === 57).toBe(true);
done();
}
});
});
dt.html( 'empty' );
it("AJAX sourced table with deferRender- Returned data is for correct column", function (done) {
var table = $('#example').DataTable({
"ajax": '/base/test/data/data.txt',
columns: [
{ data: "name" },
{ data: "position" },
{ data: "office" },
{ data: "extn" },
{ data: "start_date" },
{ data: "salary" }
],
initComplete: function ( settings, json ) {
var test = table.column(1).nodes();
expect(test[0].nodeName == "TD" && test[0].textContent == "Accountant").toBe(true);
done();
}
});
});
});
});
|