forked from DataTables/DataTablesSrc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
303 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,161 @@ | ||
// todo tests | ||
// - Confirm it exists and is a function | ||
// - Confirm it returns an API instance | ||
// - Get cached order data (no orthogonal data) | ||
// - Get cached order data (orthogonal data using a renderer) | ||
// - Get cached order data (orthogonal data using HTML5 attributes) | ||
// - Get cached search data (no orthogonal data) | ||
// - Get cached search data (orthogonal data using a renderer) | ||
// - Get cached search data (orthogonal data using HTML5 attributes) | ||
// - Attempt to get cached ordering data for columns which haven't had ordering applied to them (should be undefined or null I think) | ||
// - Use `rows().data()` or `cell().data()` to update the data and check the cache is updated | ||
// - Use the DOM to update the row's data and then `rows().invalidate()` to check the cache has been updated | ||
describe('columns- column().cache()', function() { | ||
dt.libs({ | ||
js: ['jquery', 'datatables'], | ||
css: ['datatables'] | ||
}); | ||
|
||
describe( "columns- column().cache()", 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 () { | ||
var table = $('#example').DataTable(); | ||
describe('Check the defaults', function() { | ||
dt.html('basic'); | ||
it('Exists and is a function', function() { | ||
table = $('#example').DataTable(); | ||
expect(typeof table.column().cache).toBe('function'); | ||
}); | ||
dt.html( 'basic' ); | ||
it("Returns an API instance", function () { | ||
var table = $('#example').DataTable(); | ||
expect(table.column().cache( 'search' ) instanceof $.fn.dataTable.Api).toBe(true); | ||
it('Returns an API instance', function() { | ||
expect(table.column().cache('search') instanceof $.fn.dataTable.Api).toBe(true); | ||
}); | ||
//Order tests | ||
dt.html( 'basic' ); | ||
it("Get cached order data (no orthogonal data)", function () { | ||
var table = $('#example').DataTable(); | ||
$('#example thead th:eq(0)').click(); //flip around the sorting on column 0 so we know the ordering is working and being cached | ||
var test = table.column(0).cache( 'order' ); | ||
|
||
expect(test[0] === "zorita serrano").toBe(true); | ||
it('Defaults to "order"', function() { | ||
expect(table.column(1).cache()[0]).toBe(undefined); | ||
}); | ||
it('Returns data for entire column', function() { | ||
expect(table.column(1).cache().length).toBe(57); | ||
}); | ||
}); | ||
|
||
describe('Check the behaviour (no orthogonal data)', function() { | ||
dt.html('basic'); | ||
it('Get initial cached order data', function() { | ||
table = $('#example').DataTable(); | ||
expect(table.column(0).cache('order')[0]).toBe('airi satou'); | ||
}); | ||
it('Get initial cached search data', function() { | ||
expect(table.column(0).cache('search')[0]).toBe('Airi Satou'); | ||
}); | ||
it('Unordered columns not order cached', function() { | ||
expect(table.column(1).cache('order')[0]).toBe(undefined); | ||
}); | ||
it('Unordered columns are search cached', function() { | ||
expect(table.column(1).cache('search')[0]).toBe('Accountant'); | ||
}); | ||
it('... after ordering columns are cached for order', function() { | ||
table.order([1, 'asc']).draw(); | ||
expect(table.column(1).cache('order')[0]).toBe('accountant'); | ||
}); | ||
it('... after ordering columns are still cached for search', function() { | ||
expect(table.column(1).cache('search')[0]).toBe('Accountant'); | ||
}); | ||
it('cache updated if data changed - before draw', function() { | ||
table.order([0, 'asc']).draw(); | ||
table.cell(2, 0).data('Ashton Coxxx'); | ||
// failing due to DD-975 | ||
// expect(table.column(0).cache('search')[2]).toBe('ashton coxxx'); | ||
}); | ||
it('cache updated if data changed - after draw', function() { | ||
table.draw(); | ||
expect(table.column(0).cache('search')[2]).toBe('Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - before draw', function() { | ||
$('tbody tr:eq(2) td:eq(0)').html('Ashtonnn'); | ||
table.cell(2, 0).invalidate(); | ||
// failing due to DD-944 | ||
// expect(table.column(0).cache('search')[2]).toBe('Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - after draw', function() { | ||
table.draw(); | ||
expect(table.column(0).cache('search')[2]).toBe('Ashtonnn'); | ||
}); | ||
}); | ||
|
||
//Search tests | ||
dt.html( 'basic' ); | ||
it("Get cached order data (no orthogonal data)", function () { | ||
var table = $('#example').DataTable(); | ||
table.search('Zorita').draw(); | ||
|
||
//$('#example_filter input').val('Zorita').keyup(); //flip around the sorting on column 0 so we know the ordering is working and being cached | ||
var test = table.column(0).cache( 'search' ); | ||
describe('Check the behaviour (orthogonal data)', function() { | ||
dt.html('basic'); | ||
it('Get table data', function() { | ||
table = $('#example').DataTable({ | ||
columnDefs: [ | ||
{ | ||
targets: 0, | ||
render: function(data, type, row, meta) { | ||
if (type === 'filter') return 'Filter ' + data; | ||
if (type === 'sort') return 'Sort ' + data; | ||
|
||
//expect(test[0] === "zorita serrano").toBe(true); | ||
return data; | ||
} | ||
} | ||
] | ||
}); | ||
expect(table.column(0).data()[1]).toBe('Angelica Ramos'); | ||
}); | ||
it('Get cached order data', function() { | ||
expect(table.column(0).cache('order')[1]).toBe('sort angelica ramos'); | ||
}); | ||
it('Get cached search data', function() { | ||
expect(table.column(0).cache('search')[1]).toBe('Filter Angelica Ramos'); | ||
}); | ||
it('cache updated if data changed - before draw', function() { | ||
table.order([0, 'asc']).draw(); | ||
table.cell(2, 0).data('Ashton Coxxx'); | ||
// failing due to DD-975 | ||
// expect(table.column(0).cache('search')[2]).toBe('ashton coxxx'); | ||
}); | ||
it('cache updated if data changed - after draw', function() { | ||
table.draw(); | ||
expect(table.column(0).cache('search')[2]).toBe('Filter Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - before draw', function() { | ||
$('tbody tr:eq(2) td:eq(0)').html('Filter Ashtonnn'); | ||
table.cell(2, 0).invalidate(); | ||
// failing due to DD-975 | ||
// expect(table.column(0).cache('search')[2]).toBe('Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - after draw', function() { | ||
table.draw(); | ||
// failing due to DD-975 | ||
// expect(table.column(0).cache('search')[2]).toBe('Ashtonnn'); | ||
}); | ||
}); | ||
|
||
describe('Functional tests - html5', function() { | ||
dt.html('html5'); | ||
it('Default - only filter', function() { | ||
table = $('#example').DataTable(); | ||
expect(table.column(0).cache()[2]).toBe('ashton cox'); | ||
expect(table.column(1).cache()[2]).toBe(undefined); | ||
}); | ||
it('search - only filter', function() { | ||
expect(table.column(0).cache('search')[2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('order - only filter', function() { | ||
expect(table.column(0).cache('order')[2]).toBe('ashton cox'); | ||
}); | ||
it('Default - only sort', function() { | ||
table.order([1, 'asc']).draw(); | ||
expect(table.column(1).cache('order')[2]).toBe('order chief executive officer (ceo)'); | ||
}); | ||
it('search - only sort', function() { | ||
expect(table.column(1).cache('search')[2]).toBe('Chief Executive Officer (CEO)'); | ||
}); | ||
it('Default - only sort', function() { | ||
expect(table.column(1).cache()[2]).toBe('order chief executive officer (ceo)'); | ||
}); | ||
it('cache updated if data changed - before draw', function() { | ||
table.order([0, 'asc']).draw(); | ||
table.cell(2, 0).data('Ashton Coxxx'); | ||
// failing due to DD-975 | ||
// expect(table.column(0).cache('search')[2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('cache updated if data changed - after draw', function() { | ||
table.draw(); | ||
expect(table.column(0).cache('search')[2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - before draw', function() { | ||
$('tbody tr:eq(2) td:eq(0)').html('Ashtonnn'); | ||
table.cell(2, 0).invalidate(); | ||
// failing due to DD-944 | ||
// expect(table.column(0).cache('search')[2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - after draw', function() { | ||
table.draw(); | ||
expect(table.column(0).cache('search')[2]).toBe('Filter Ashton Cox'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,163 @@ | ||
// todo tests | ||
// - Confirm it exists and is a function | ||
// - Confirm it returns an API instance | ||
// - Select two columns and get cached search data | ||
// - Ensure that the array ordering is index based with the first column's data appearing first and then the second's data | ||
// - Selecting different and a different number of columns for each test: | ||
// - Get cached order data (no orthogonal data) | ||
// - Get cached order data (orthogonal data using a renderer) | ||
// - Get cached order data (orthogonal data using HTML5 attributes) | ||
// - Get cached search data (no orthogonal data) | ||
// - Get cached search data (orthogonal data using a renderer) | ||
// - Get cached search data (orthogonal data using HTML5 attributes) | ||
// - Attempt to get cached ordering data for columns which haven't had ordering applied to them (should be undefined or null I think) | ||
// - Use `rows().data()` or `cell().data()` to update the data and check the cache is updated | ||
// - Use the DOM to update the row's data and then `rows().invalidate()` to check the cache has been updated | ||
describe('columns- columns().cache()', function() { | ||
dt.libs({ | ||
js: ['jquery', 'datatables'], | ||
css: ['datatables'] | ||
}); | ||
|
||
describe( "columns- columns().cache()", 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 () { | ||
var table = $('#example').DataTable(); | ||
describe('Check the defaults', function() { | ||
dt.html('basic'); | ||
it('Exists and is a function', function() { | ||
table = $('#example').DataTable(); | ||
expect(typeof table.columns().cache).toBe('function'); | ||
}); | ||
dt.html( 'basic' ); | ||
it("Returns an API instance", function () { | ||
var table = $('#example').DataTable(); | ||
expect(table.columns().cache() instanceof $.fn.dataTable.Api).toBe(true); | ||
it('Returns an API instance', function() { | ||
expect(table.columns().cache('search') instanceof $.fn.dataTable.Api).toBe(true); | ||
}); | ||
it('Defaults to "order"', function() { | ||
expect(table.columns().cache()[1][0]).toBe(undefined); | ||
}); | ||
it('Returns data for entire column', function() { | ||
expect(table.columns().cache().length).toBe(6); | ||
expect(table.columns().cache()[0].length).toBe(57); | ||
|
||
}); | ||
}); | ||
|
||
describe('Check the behaviour (no orthogonal data)', function() { | ||
dt.html('basic'); | ||
it('Get initial cached order data', function() { | ||
table = $('#example').DataTable(); | ||
expect(table.columns().cache('order')[0][0]).toBe('airi satou'); | ||
}); | ||
it('Get initial cached search data', function() { | ||
expect(table.columns().cache('search')[0][0]).toBe('Airi Satou'); | ||
}); | ||
it('Unordered columns not order cached', function() { | ||
expect(table.columns().cache('order')[1][0]).toBe(undefined); | ||
}); | ||
it('Unordered columns are search cached', function() { | ||
expect(table.columns().cache('search')[1][0]).toBe('Accountant'); | ||
}); | ||
it('... after ordering columns are cached for order', function() { | ||
table.order([1, 'asc']).draw(); | ||
expect(table.columns().cache('order')[1][0]).toBe('accountant'); | ||
}); | ||
it('... after ordering columns are still cached for search', function() { | ||
expect(table.columns().cache('search')[1][0]).toBe('Accountant'); | ||
}); | ||
it('cache updated if data changed - before draw', function() { | ||
table.order([0, 'asc']).draw(); | ||
table.cell(2, 0).data('Ashton Coxxx'); | ||
// failing due to DD-975 | ||
// expect(table.columns().cache('search')[0][2]).toBe('ashton coxxx'); | ||
}); | ||
it('cache updated if data changed - after draw', function() { | ||
table.draw(); | ||
expect(table.columns().cache('search')[0][2]).toBe('Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - before draw', function() { | ||
$('tbody tr:eq(2) td:eq(0)').html('Ashtonnn'); | ||
table.cell(2, 0).invalidate(); | ||
// failing due to DD-944 | ||
// expect(table.columns().cache('search')[0][2]).toBe('Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - after draw', function() { | ||
table.draw(); | ||
expect(table.columns().cache('search')[0][2]).toBe('Ashtonnn'); | ||
}); | ||
}); | ||
|
||
describe('Check the behaviour (orthogonal data)', function() { | ||
dt.html('basic'); | ||
it('Get table data', function() { | ||
table = $('#example').DataTable({ | ||
columnDefs: [ | ||
{ | ||
targets: 0, | ||
render: function(data, type, row, meta) { | ||
if (type === 'filter') return 'Filter ' + data; | ||
if (type === 'sort') return 'Sort ' + data; | ||
|
||
return data; | ||
} | ||
} | ||
] | ||
}); | ||
expect(table.columns().data()[0][1]).toBe('Angelica Ramos'); | ||
}); | ||
it('Get cached order data', function() { | ||
expect(table.columns().cache('order')[0][1]).toBe('sort angelica ramos'); | ||
}); | ||
it('Get cached search data', function() { | ||
expect(table.columns().cache('search')[0][1]).toBe('Filter Angelica Ramos'); | ||
}); | ||
it('cache updated if data changed - before draw', function() { | ||
table.order([0, 'asc']).draw(); | ||
table.cell(2, 0).data('Ashton Coxxx'); | ||
// failing due to DD-975 | ||
// expect(table.columns().cache('search')[0][2]).toBe('ashton coxxx'); | ||
}); | ||
it('cache updated if data changed - after draw', function() { | ||
table.draw(); | ||
expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - before draw', function() { | ||
$('tbody tr:eq(2) td:eq(0)').html('Filter Ashtonnn'); | ||
table.cell(2, 0).invalidate(); | ||
// failing due to DD-975 | ||
// expect(table.columns().cache('search')[0][2]).toBe('Ashton Coxxx'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - after draw', function() { | ||
table.draw(); | ||
// failing due to DD-975 | ||
// expect(table.columns().cache('search')[0][2]).toBe('Ashtonnn'); | ||
}); | ||
}); | ||
|
||
describe('Functional tests - html5', function() { | ||
dt.html('html5'); | ||
it('Default - only filter', function() { | ||
table = $('#example').DataTable(); | ||
expect(table.columns().cache()[0][2]).toBe('ashton cox'); | ||
expect(table.columns().cache()[1][2]).toBe(undefined); | ||
}); | ||
it('search - only filter', function() { | ||
expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('order - only filter', function() { | ||
expect(table.columns().cache('order')[0][2]).toBe('ashton cox'); | ||
}); | ||
it('Default - only sort', function() { | ||
table.order([1, 'asc']).draw(); | ||
expect(table.columns().cache('order')[1][2]).toBe('order chief executive officer (ceo)'); | ||
}); | ||
it('search - only sort', function() { | ||
expect(table.columns().cache('search')[1][2]).toBe('Chief Executive Officer (CEO)'); | ||
}); | ||
it('Default - only sort', function() { | ||
expect(table.columns().cache()[1][2]).toBe('order chief executive officer (ceo)'); | ||
}); | ||
it('cache updated if data changed - before draw', function() { | ||
table.order([0, 'asc']).draw(); | ||
table.cell(2, 0).data('Ashton Coxxx'); | ||
// failing due to DD-975 | ||
// expect(table.column().cache('search')[0][2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('cache updated if data changed - after draw', function() { | ||
table.draw(); | ||
expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - before draw', function() { | ||
$('tbody tr:eq(2) td:eq(0)').html('Ashtonnn'); | ||
table.cell(2, 0).invalidate(); | ||
// failing due to DD-944 | ||
// expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox'); | ||
}); | ||
it('cache updated if data changed and cell invalidated - after draw', function() { | ||
table.draw(); | ||
expect(table.columns().cache('search')[0][2]).toBe('Filter Ashton Cox'); | ||
}); | ||
}); | ||
}); |