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
|
describe('cells - cell().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() {
table = $('#example').DataTable();
expect(typeof table.cell().cache).toBe('function');
});
it('Returns a string', function() {
expect(typeof table.cell().cache('search')).toBe('string');
});
it('Defaults to "order"', function() {
expect(table.cell(2, 0).cache()).toBe('ashton cox');
});
it('undefined if not ordered yet', function() {
expect(table.cell(2, 1).cache()).toBe(undefined);
});
});
describe('Functional tests - standard', function() {
dt.html('basic');
it('Default', function() {
table = $('#example').DataTable();
expect(table.cell(2, 0).cache()).toBe('ashton cox');
});
it('search', function() {
expect(table.cell(2, 0).cache('search')).toBe('Ashton Cox');
});
it('order', function() {
expect(table.cell(2, 0).cache('order')).toBe('ashton cox');
});
it('cache updated if data changed - before draw', function() {
table.cell(2, 0).data('Ashton Coxxx');
// failing due to DD-944
// expect(table.cell(2, 0).cache('search')).toBe('ashton cox');
});
it('cache updated if data changed - after draw', function() {
table.draw();
expect(table.cell(2, 0).cache()).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.cell(2, 0).cache()).toBe('ashtonnn');
});
it('cache updated if data changed and cell invalidated - after draw', function() {
table.draw();
expect(table.cell(2, 0).cache()).toBe('ashtonnn');
});
});
describe('Functional tests - render', function() {
dt.html('basic');
it('Default', 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.cell(2, 0).cache()).toBe('sort ashton cox');
});
it('search', function() {
expect(table.cell(2, 0).cache('search')).toBe('Filter Ashton Cox');
});
it('order', function() {
expect(table.cell(2, 0).cache()).toBe('sort ashton cox');
});
it('cache updated if data changed - before draw', function() {
table.cell(2, 0).data('Ashton Coxxx');
// failing due to DD-944
// expect(table.cell(2, 0).cache('search')).toBe('sort ashton cox');
});
it('cache updated if data changed - after draw', function() {
table.draw();
expect(table.cell(2, 0).cache()).toBe('sort 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.cell(2, 0).cache()).toBe('sort ashtonnn');
});
it('cache updated if data changed and cell invalidated - after draw', function() {
table.draw();
expect(table.cell(2, 0).cache()).toBe('sort ashtonnn');
});
});
describe('Functional tests - html5', function() {
dt.html('html5');
it('Default - only filter', function() {
table = $('#example').DataTable();
expect(table.cell(2, 0).cache()).toBe('ashton cox');
});
it('search - only filter', function() {
expect(table.cell(2, 0).cache('search')).toBe('Filter Ashton Cox');
});
it('order - only filter', function() {
expect(table.cell(2, 0).cache('order')).toBe('ashton cox');
});
it('Default - only sort', function() {
table.order([1, 'asc']).draw();
expect(table.cell(2, 1).cache()).toBe('order junior technical author');
});
it('search - only sort', function() {
expect(table.cell(2, 1).cache('search')).toBe('Junior Technical Author');
});
it('Default - only sort', function() {
expect(table.cell(2, 1).cache()).toBe('order junior technical author');
});
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-944
// expect(table.cell(2, 0).cache('search')).toBe('Filter Ashton Cox');
});
it('cache updated if data changed - after draw', function() {
table.draw();
expect(table.cell(2, 0).cache('search')).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.cell(2, 0).cache('search')).toBe('Filter Ashton Cox');
});
it('cache updated if data changed and cell invalidated - after draw', function() {
table.draw();
expect(table.cell(2, 0).cache('search')).toBe('Filter Ashton Cox');
});
});
});
|