2015-11-21 12:12:47 +01:00
|
|
|
var tf = new TableFilter('demo', {
|
|
|
|
base_path: '../dist/tablefilter/',
|
|
|
|
paging: true,
|
|
|
|
paging_length: 2,
|
|
|
|
results_per_page: ['Results per page ', [2,4,6]],
|
2015-12-20 06:58:39 +01:00
|
|
|
extensions: [{
|
|
|
|
name: 'sort',
|
|
|
|
types: ['string', 'string', 'number', 'number', 'number']
|
|
|
|
}]
|
2015-11-21 12:12:47 +01:00
|
|
|
});
|
|
|
|
tf.init();
|
|
|
|
|
|
|
|
var paging = tf.feature('paging');
|
|
|
|
|
|
|
|
module('Sanity checks');
|
|
|
|
test('Paging component', function() {
|
|
|
|
notEqual(paging, null, 'Paging instanciated');
|
|
|
|
deepEqual(paging.pagingLength, 2, 'Paging length');
|
|
|
|
deepEqual(paging.nbPages, 4, 'Number of pages');
|
|
|
|
});
|
|
|
|
test('Sort extension', function() {
|
|
|
|
var sort = tf.extension('sort');
|
|
|
|
notEqual(sort, null, 'Sort instanciated');
|
|
|
|
deepEqual(sort.stt instanceof SortableTable, true, 'Sort type');
|
|
|
|
deepEqual(sort.sorted, false, 'Table not sorted');
|
|
|
|
deepEqual(sort.initialized, true, 'Sort initialized');
|
|
|
|
});
|
|
|
|
|
2016-04-30 03:45:04 +02:00
|
|
|
module('Paging when a column is sorted');
|
2015-11-21 12:12:47 +01:00
|
|
|
test('It contains options', function() {
|
|
|
|
var sort = tf.extension('sort');
|
|
|
|
sort.sortByColumnIndex(0);
|
|
|
|
|
|
|
|
deepEqual(paging.pagingSlc.options.length, 4, 'Expected options number');
|
|
|
|
});
|
|
|
|
test('Can select a page', function() {
|
|
|
|
var sort = tf.extension('sort');
|
|
|
|
sort.sortByColumnIndex(1);
|
|
|
|
paging.setPage(3);
|
|
|
|
|
2015-11-29 11:27:43 +01:00
|
|
|
deepEqual(paging.pagingSlc.selectedIndex, 2, 'Expected selected option');
|
2015-11-21 12:12:47 +01:00
|
|
|
});
|
|
|
|
|
2015-12-20 06:58:39 +01:00
|
|
|
module('Changing pages when column is sorted (issue #70)');
|
2016-04-30 03:45:04 +02:00
|
|
|
test('Can change page', function() {
|
2015-12-20 06:58:39 +01:00
|
|
|
var sort = tf.extension('sort');
|
|
|
|
tf.setFilterValue(2, '>400');
|
|
|
|
sort.sortByColumnIndex(1);
|
|
|
|
sort.sortByColumnIndex(1);
|
|
|
|
paging.setPage(3);
|
|
|
|
|
|
|
|
deepEqual(paging.getPage(), 3, 'Expected page number');
|
|
|
|
});
|
|
|
|
|
2015-11-21 12:12:47 +01:00
|
|
|
module('Tear-down');
|
|
|
|
test('can destroy TableFilter DOM elements', function() {
|
|
|
|
tf.destroy();
|
2016-05-27 09:40:22 +02:00
|
|
|
deepEqual(tf.isInitialized(), false, 'Filters removed');
|
2015-11-21 12:12:47 +01:00
|
|
|
});
|