1 |
|
2 | var tf = new TableFilter('demo', {
|
3 | base_path: '../dist/tablefilter/',
|
4 | on_filters_loaded: filtersLoadedTests
|
5 | });
|
6 | tf.init();
|
7 |
|
8 |
|
9 | function filtersLoadedTests(){
|
10 | tf.setFilterValue(0, 'Adelaide');
|
11 | tf.setFilterValue(1, 'Perth');
|
12 | tf.filter();
|
13 |
|
14 |
|
15 | module('TableFilter with filters loaded callback');
|
16 | test('Can filter table on callback', function() {
|
17 | deepEqual(tf.initialized, true, 'TableFilter is initialized');
|
18 | deepEqual(tf.getValidRowsNb(), 1, 'Nb of filtered rows');
|
19 | });
|
20 |
|
21 | module('Tear-down');
|
22 | test('Can destroy', function() {
|
23 | tf.destroy();
|
24 | deepEqual(tf.isInitialized(), false, 'Destroyed');
|
25 |
|
26 |
|
27 | afterFilterTests();
|
28 | });
|
29 | }
|
30 |
|
31 | function afterFilterTests(){
|
32 | tf = new TableFilter('demo', {
|
33 | base_path: '../dist/tablefilter/',
|
34 | col_1: 'checklist',
|
35 | on_after_filter: afterFilter
|
36 | });
|
37 | var ct = 0;
|
38 | tf.init();
|
39 |
|
40 |
|
41 | var evObj = document.createEvent('HTMLEvents');
|
42 | evObj.initEvent('click', true, true);
|
43 | var flt1 = tf.getFilterElement(1);
|
44 |
|
45 |
|
46 | flt1.getElementsByTagName('li')[4].firstChild.dispatchEvent(evObj);
|
47 |
|
48 |
|
49 | function afterFilter(){
|
50 | ct++;
|
51 | module('TableFilter with on_after_filter callback');
|
52 | test('after filter callback fired once', function() {
|
53 |
|
54 | deepEqual(ct, 1, 'Nb of times is fired');
|
55 | deepEqual(tf.getFilterValue(1), ['Canberra'], 'Selected option');
|
56 | });
|
57 | }
|
58 | };
|