Skip to content

Commit

Permalink
DEV DD32 - final sweep to remove IDs from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
colin0117 committed Jan 21, 2019
1 parent b79286b commit e2c8ecd
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 189 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TK COLIN not convinced by the usefulness of these tests...
describe('Basic Datatables Test', function() {
dt.libs({
js: ['jquery', 'datatables'],
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/options/Features/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('info option- Feature', function() {
$('#example_two').DataTable({
info: false
});
expect($('#example_one_info').length).toBe(1);
expect($('#example_two_info').length).toBe(0);
expect($('#example_one_wrapper div.dataTables_info').length).toBe(1);
expect($('#example_two_wrapper div.dataTables_info').length).toBe(0);
});

dt.html('basic');
Expand Down
10 changes: 5 additions & 5 deletions test/options/Features/processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ describe('Processing option', function() {
dt.html('basic');
it('Processing can be enabled', function() {
$('#example').on('processing.dt', function(e) {
expect(document.getElementById('example_processing')).not.toBeNull();
expect($('div.dataTables_processing').length).toBe(1);
});
$('#example').dataTable({
processing: true
});
$('#example').off('processing.dt', function(e) {});
});
it('Processing div is in the DOM', function() {
expect(document.getElementById('example_processing')).toBeTruthy();
expect($('div.dataTables_processing').length).toBe(1);
});
});

describe('disable makes no difference', function() {
dt.html('basic');
it('Processing disabled override', function() {
$('#example').dataTable({
processing: false
});
$('#example').on('processing.dt', function(e) {
expect(document.getElementById('example_processing')).toBeNull();
expect($('div.dataTables_processing').length).toBe(0);
});

$('#example').off('processing.dt', function(e) {});
});
it('Processing div is not in the DOM', function() {
expect(document.getElementById('example_processing') === null).toBeTruthy();
expect($('div.dataTables_processing').length).toBe(0);
});
});
});
29 changes: 20 additions & 9 deletions test/options/Features/searching.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ describe('searching option', function() {
describe('Check the defaults', function() {
dt.html('basic');
it('Default is enabled', function() {
// it's an alias for this fellow
expect($.fn.dataTable.defaults.bFilter).toBe(true);
});

Expand Down Expand Up @@ -44,8 +43,8 @@ describe('searching option', function() {
searching: false
});

expect($('#example_one_filter').length).toBe(1);
expect($('#example_two_filter').length).toBe(0);
expect($('#example_one_wrapper div.dataTables_filter').length).toBe(1);
expect($('#example_two_wrapper div.dataTables_filter').length).toBe(0);
});
});

Expand All @@ -57,30 +56,38 @@ describe('searching option', function() {
$('div.dataTables_filter input')
.val(33)
.keyup();
expect($('div.dataTables_info').html() == 'Showing 1 to 2 of 2 entries (filtered from 57 total entries)').toBeTruthy();
expect(
$('div.dataTables_info').html() == 'Showing 1 to 2 of 2 entries (filtered from 57 total entries)'
).toBeTruthy();
});

it('searching enabled by default- API', function() {
$('#example')
.DataTable()
.search(33)
.draw();
expect($('div.dataTables_info').html() == 'Showing 1 to 2 of 2 entries (filtered from 57 total entries)').toBeTruthy();
expect(
$('div.dataTables_info').html() == 'Showing 1 to 2 of 2 entries (filtered from 57 total entries)'
).toBeTruthy();
});

it('Can search multiple space seperated words- DOM', function() {
$('div.dataTables_filter input')
.val('New 3')
.keyup();
expect($('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)').toBeTruthy();
expect(
$('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)'
).toBeTruthy();
});

it('Can search multiple space seperated words- API', function() {
$('#example')
.DataTable()
.search('New 3')
.draw();
expect($('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)').toBeTruthy();
expect(
$('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)'
).toBeTruthy();
});
});

Expand Down Expand Up @@ -118,15 +125,19 @@ describe('searching option', function() {
$('div.dataTables_filter input')
.val('New 3')
.keyup();
expect($('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)').toBeTruthy();
expect(
$('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)'
).toBeTruthy();
});

it('Searching enabled override- API', function() {
$('#example')
.DataTable()
.search('New 3')
.draw();
expect($('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)').toBeTruthy();
expect(
$('div.dataTables_info').html() == 'Showing 1 to 5 of 5 entries (filtered from 57 total entries)'
).toBeTruthy();
});
});
});
34 changes: 17 additions & 17 deletions test/options/Features/stateSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('stateSave option', function() {

table = $('#example').DataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Bradley Greer');
expect($('#example_info').text()).toBe('Showing 1 to 9 of 9 entries (filtered from 57 total entries)');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 9 of 9 entries (filtered from 57 total entries)');
expect($('div.dataTables_filter input').val()).toBe('2012');
table.state.clear();
});
Expand All @@ -46,7 +46,7 @@ describe('stateSave option', function() {

$('#example').dataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Bradley Greer');
expect($('#example_info').text()).toBe('Showing 1 to 9 of 9 entries (filtered from 57 total entries)');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 9 of 9 entries (filtered from 57 total entries)');
expect(table.search()).toBe('2012');
table.state.clear();
});
Expand All @@ -69,7 +69,7 @@ describe('stateSave option', function() {
it('Does sorting remain applied after page refresh', function() {
/*
* Note the following behaviour is unintuitive. It's different to the search results before the refresh
* because the first search is a stable search - it uses the first column as a secondary ordering.
* because the first search is a stable search - it uses the first column as a secondary ordering.
* The second search doesn't do this, so the secondary ordering is purely the load order. A bug-ette
* in the reload, but very minor, and unlikely to ever be resolved.
*/
Expand Down Expand Up @@ -124,13 +124,13 @@ describe('stateSave option', function() {
it('Check table is back to default state', function() {
$('#example').dataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Airi Satou');
expect($('#example_info').text()).toBe('Showing 1 to 10 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 10 of 57 entries');
});

it('Paging - Second page', function() {
$('#example_next').click();
$('.paginate_button.next').click();
expect($('#example tbody td:eq(0)').text()).toBe('Charde Marshall');
expect($('#example_info').text()).toBe('Showing 11 to 20 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 11 to 20 of 57 entries');
});

it('Paging - Second page - After refresh', function() {
Expand All @@ -139,13 +139,13 @@ describe('stateSave option', function() {
.destroy();
$('#example').dataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Charde Marshall');
expect($('#example_info').text()).toBe('Showing 11 to 20 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 11 to 20 of 57 entries');
});

it('Paging - Third page', function() {
$('#example_next').click();
$('.paginate_button.next').click();
expect($('#example tbody td:eq(0)').text()).toBe('Gloria Little');
expect($('#example_info').text()).toBe('Showing 21 to 30 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 21 to 30 of 57 entries');
});

it('Paging - Third page- After refresh', function() {
Expand All @@ -154,27 +154,27 @@ describe('stateSave option', function() {
.destroy();
$('#example').dataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Gloria Little');
expect($('#example_info').text()).toBe('Showing 21 to 30 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 21 to 30 of 57 entries');
});

it('Paging back to second page and refreshing', function() {
$('#example_previous').click();
$('.paginate_button.previous').click();
$('#example')
.DataTable()
.destroy();
$('#example').dataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Charde Marshall');
expect($('#example_info').text()).toBe('Showing 11 to 20 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 11 to 20 of 57 entries');
});

it('Paging back to first page and refreshing', function() {
$('#example_previous').click();
$('.paginate_button.previous').click();
$('#example')
.DataTable()
.destroy();
let table = $('#example').DataTable({ stateSave: true });
expect($('#example tbody td:eq(0)').text()).toBe('Airi Satou');
expect($('#example_info').text()).toBe('Showing 1 to 10 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 10 of 57 entries');
table.state.clear();
});
});
Expand All @@ -187,11 +187,11 @@ describe('stateSave option', function() {
.val('25')
.change();

expect($('#example_info').text()).toBe('Showing 1 to 25 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 25 of 57 entries');
table.state.clear();
table.destroy();
table = $('#example').DataTable({ stateSave: true });
expect($('#example_info').text()).toBe('Showing 1 to 10 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 10 of 57 entries');
});

dt.html('basic');
Expand All @@ -202,7 +202,7 @@ describe('stateSave option', function() {
.change();
table.destroy();
table = $('#example').DataTable({ stateSave: true });
expect($('#example_info').text()).toBe('Showing 1 to 25 of 57 entries');
expect($('div.dataTables_info').text()).toBe('Showing 1 to 25 of 57 entries');
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/options/Options/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ describe('destroy option', function() {
$('#example_one').DataTable();
$('#example_two').DataTable();

expect($('#example_one_filter').length).toBe(1);
expect($('#example_two_filter').length).toBe(1);
expect($('#example_one_wrapper div.dataTables_filter').length).toBe(1);
expect($('#example_two_wrapper div.dataTables_filter').length).toBe(1);

$('#example_one').DataTable({
filter: false,
destroy: true
});

expect($('#example_one_filter').length).toBe(0);
expect($('#example_two_filter').length).toBe(1);
expect($('#example_one_wrapper div.dataTables_filter').length).toBe(0);
expect($('#example_two_wrapper div.dataTables_filter').length).toBe(1);
});
});
});
1 change: 1 addition & 0 deletions test/options/Options/pagingType.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('pageType Option', function() {
function checkPaging(count, typeInternal, type, pages, pageCount, prevNext, firstLast) {
expect($('.dataTables_paginate a').length).toBe(count);
expect($('#example').DataTable.settings[0].sPaginationType).toBe(typeInternal);
expect($('div.' + type).length).toBe(1);

if (pages) {
// this is the sum of the numbers ('a') and the ellipses ('span')
Expand Down
2 changes: 1 addition & 1 deletion test/options/callbacks/drawCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('drawCallback option', function() {
});

it('drawCallback called once when paging', function() {
$('#example_next').click();
$('.paginate_button.next').click();
expect(test).toBe(2);
});

Expand Down
2 changes: 1 addition & 1 deletion test/options/callbacks/initComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('initComplete Option', function() {
expect(count).toBe(1);
});
it('initComplete never called there after', function() {
$('#example_next').click();
$('.paginate_button.next').click();
table.page(1).draw();
expect(count).toBe(1);
});
Expand Down
6 changes: 3 additions & 3 deletions test/options/callbacks/preDrawCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ describe('preDrawCallback option', function() {
expect(drawCount).toBe(1);
});
it('preDrawCallback called once after each draw', function() {
$('#example_next').click();
$('#example_next').click();
$('#example_next').click();
$('.paginate_button.next').click();
$('.paginate_button.next').click();
$('.paginate_button.next').click();

expect(count).toBe(4);
expect(drawCount).toBe(4);
Expand Down
Loading

0 comments on commit e2c8ecd

Please sign in to comment.