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
|
describe('core - events - requestChild', function () {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
let params;
let children = [];
let columns = [{data: 'name'}, {data: 'position'}, {data: 'office'}, {data: 'age'}, {data: 'start_date'}, {data: 'salary'}];
describe('Functional tests', function () {
// Clear down save state before proceeding (otherwise old stuff may be lurking that will affect us)
dt.html('basic');
it('Clear state save', function () {
let table = $('#example').DataTable();
table.state.clear();
});
dt.html('empty');
it('Not called on table initialisation if no stateSave', function (done) {
table = $('#example')
.on('requestChild.dt', function () {
params = arguments;
})
.DataTable({
ajax: '/base/test/data/id.txt',
columns: columns,
rowId: 'ID',
initComplete: function () {
expect(params).toBe(undefined);
done();
}
});
});
dt.html('empty');
it('Not called on table initialisation if no opened rows', function (done) {
table = $('#example')
.on('requestChild.dt', function () {
params = arguments;
})
.DataTable({
ajax: '/base/test/data/id.txt',
columns: columns,
stateSave: true,
rowId: 'ID',
initComplete: function () {
expect(params).toBe(undefined);
done();
}
});
});
it('Open a child row', function () {
table.row(2).child('TEST').show();
});
dt.html('empty');
it('Called on table initialisation if opened rows', function (done) {
table = $('#example')
.on('requestChild.dt', function () {
params = arguments;
})
.DataTable({
ajax: '/base/test/data/id.txt',
columns: columns,
stateSave: true,
rowId: 'ID',
initComplete: function () {
expect(params).not.toBe(undefined);
done();
}
});
});
it('Check parameter types', function () {
expect(params.length).toBe(2);
expect(params[0] instanceof $.Event).toBe(true);
expect(params[1] instanceof $.fn.dataTable.Api).toBe(true);
});
it('Check parameters', function () {
expect(params[0].type).toBe('requestChild');
expect(params[1].index()).toBe(2);
});
it('Open child rows', function () {
table.row(2).child('TEST').show();
table.row(3).child('TEST').show();
});
dt.html('empty');
it('Called for each opened row', function (done) {
table = $('#example')
.on('requestChild.dt', function () {
children.push(arguments[1].index());
})
.DataTable({
ajax: '/base/test/data/id.txt',
columns: columns,
stateSave: true,
rowId: 'ID',
initComplete: function () {
done();
}
});
});
it('Check parameters', function () {
expect(children.length).toBe(2);
expect(children).toEqual([2, 3]);
});
});
});
|