1 | var tf = new TableFilter('demo', {
|
2 | base_path: '../dist/tablefilter/',
|
3 | paging: {
|
4 | length: 2
|
5 | },
|
6 | results_per_page: ['Results per page ', [2,4,6]],
|
7 | extensions: [{
|
8 | name: 'sort',
|
9 | types: ['string', 'string', 'number', 'number', 'number']
|
10 | }]
|
11 | });
|
12 | tf.init();
|
13 |
|
14 | var paging = tf.feature('paging');
|
15 |
|
16 | module('Sanity checks');
|
17 | test('Paging component', function() {
|
18 | notEqual(paging, null, 'Paging instanciated');
|
19 | deepEqual(paging.pageLength, 2, 'Paging length');
|
20 | deepEqual(paging.nbPages, 4, 'Number of pages');
|
21 | });
|
22 | test('Sort extension', function() {
|
23 | var sort = tf.extension('sort');
|
24 | notEqual(sort, null, 'Sort instanciated');
|
25 | deepEqual(sort.stt instanceof SortableTable, true, 'Sort type');
|
26 | deepEqual(sort.sorted, false, 'Table not sorted');
|
27 | deepEqual(sort.initialized, true, 'Sort initialized');
|
28 | });
|
29 |
|
30 | module('Paging when a column is sorted');
|
31 | test('It contains options', function() {
|
32 | var sort = tf.extension('sort');
|
33 | sort.sortByColumnIndex(0);
|
34 |
|
35 | deepEqual(paging.pageSlc.options.length, 4, 'Expected options number');
|
36 | });
|
37 | test('Can select a page', function() {
|
38 | var sort = tf.extension('sort');
|
39 | sort.sortByColumnIndex(1);
|
40 | paging.setPage(3);
|
41 |
|
42 | deepEqual(paging.pageSlc.selectedIndex, 2, 'Expected selected option');
|
43 | });
|
44 |
|
45 | module('Changing pages when column is sorted (issue #70)');
|
46 | test('Can change page', function() {
|
47 | var sort = tf.extension('sort');
|
48 | tf.setFilterValue(2, '>400');
|
49 | sort.sortByColumnIndex(1);
|
50 | sort.sortByColumnIndex(1);
|
51 | paging.setPage(3);
|
52 |
|
53 | deepEqual(paging.getPage(), 3, 'Expected page number');
|
54 | });
|
55 |
|
56 | module('Tear-down');
|
57 | test('can destroy TableFilter DOM elements', function() {
|
58 | tf.destroy();
|
59 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
60 | });
|