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
|
describe('core- ajax.url()', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
let table;
describe('Check the defaults', function() {
dt.html('empty');
it('Exists and is a function', function(done) {
table = $('#example').DataTable({
columns: dt.getTestColumns(),
ajax: '/base/test/data/data.txt',
initComplete: function(settings, json) {
expect(typeof table.ajax.reload).toBe('function');
done();
}
});
});
it('Getter returns string', function() {
expect(typeof table.ajax.url()).toBe('string');
});
it('Setter returns an API instance', function() {
expect(table.ajax.url('/base/test/data/data_small.txt') instanceof $.fn.dataTable.Api).toBe(true);
});
dt.html('basic');
it('Getter returns null for DOM sourced table', function() {
table = $('#example').DataTable();
expect(table.ajax.url()).toBe(null);
});
it('Getter returns an API instance for DOM sourced table', function() {
expect(table.ajax.url('/base/test/data/data_small.txt') instanceof $.fn.dataTable.Api).toBe(true);
});
});
describe('Functional tests', function() {
dt.html('empty');
it('Setup', function(done) {
table = $('#example').DataTable({
columns: dt.getTestColumns(),
ajax: '/base/test/data/data.txt',
initComplete: function(settings, json) {
done();
}
});
});
it('Getter returns original address', function() {
expect(table.ajax.url()).toBe('/base/test/data/data.txt');
});
it('Does not update the table', function() {
table.ajax.url('/base/test/data/data_small.txt');
expect($('tbody tr:eq(1) td:eq(0)').text()).toBe('Angelica Ramos');
});
it('Getter returns new address', function() {
expect(table.ajax.url()).toBe('/base/test/data/data_small.txt');
});
it('New data loads after reload', async function() {
table.ajax.reload();
await dt.sleep(500);
expect($('tbody tr:eq(1) td:eq(0)').text()).toBe('Winter Jenkins');
});
it('Can give the same URL again', async function() {
table.ajax.url('/base/test/data/data_small.txt').load();
await dt.sleep(500);
expect($('tbody tr:eq(1) td:eq(0)').text()).toBe('Winter Jenkins');
});
it('Getter returns new address', function() {
expect(table.ajax.url()).toBe('/base/test/data/data_small.txt');
});
it('Can give another URL', async function() {
table.ajax.url('/base/test/data/data.txt').load();
await dt.sleep(500);
expect($('tbody tr:eq(1) td:eq(0)').text()).toBe('Angelica Ramos');
});
it('Getter returns new address', function() {
expect(table.ajax.url()).toBe('/base/test/data/data.txt');
});
});
});
|