1 | (function(win, TableFilter) {
|
2 |
|
3 | var tf = new TableFilter('demo', {
|
4 | base_path: '../dist/tablefilter/',
|
5 | linked_filters: true,
|
6 | col_0: 'checklist',
|
7 | col_1: 'multiple',
|
8 | load_filters_on_demand: true
|
9 | });
|
10 |
|
11 | tf.init();
|
12 |
|
13 | var checkList = tf.feature('checkList');
|
14 | var cont0 = checkList.containers[0];
|
15 | var cont1 = tf.getFilterElement(1);
|
16 |
|
17 | module('Sanity checks');
|
18 | test('Linked filters feature', function() {
|
19 | deepEqual(tf instanceof TableFilter, true, 'TableFilter instantiated');
|
20 | deepEqual(tf.linkedFilters, true, 'Linked filters enabled');
|
21 | deepEqual(tf.loadFltOnDemand, true, 'Load filters on demand setting');
|
22 | });
|
23 |
|
24 | test('Can generate filter options', function() {
|
25 |
|
26 | var ct = 0;
|
27 | tf.emitter.on(['after-populating-filter'], checkGeneratedFilters);
|
28 |
|
29 | function checkGeneratedFilters(tf, colIndex, flt) {
|
30 | ct++;
|
31 |
|
32 | if (colIndex === 0) {
|
33 |
|
34 | deepEqual(flt.getElementsByTagName('li').length, 3,
|
35 | 'Filter 0 options length');
|
36 | }
|
37 | if (colIndex === 1) {
|
38 |
|
39 | deepEqual(flt.options.length, 7, 'Filter 1 options length');
|
40 | }
|
41 | if (ct === 2) {
|
42 | tf.emitter.off(['after-populating-filter'],
|
43 | checkGeneratedFilters);
|
44 | canFilterLinkedFilters();
|
45 | }
|
46 | }
|
47 |
|
48 |
|
49 | var evObj = document.createEvent('HTMLEvents');
|
50 | evObj.initEvent('click', true, true);
|
51 | cont0.dispatchEvent(evObj);
|
52 | cont1.focus();
|
53 | });
|
54 |
|
55 | function canFilterLinkedFilters() {
|
56 | test('Can filter linked filters', function() {
|
57 |
|
58 | tf.activateFilter(0);
|
59 | tf.setFilterValue(0, 'Adelaide');
|
60 | tf.filter();
|
61 |
|
62 |
|
63 | deepEqual(cont0.getElementsByTagName('li').length, 2,
|
64 | 'Filter 0 options length');
|
65 | deepEqual(cont1.options.length, 4, 'Filter 1 options length');
|
66 | });
|
67 |
|
68 | test('Can filter linked filters 2', function() {
|
69 |
|
70 | tf.activateFilter(1);
|
71 | tf.setFilterValue(1, 'Brisbane');
|
72 | tf.filter();
|
73 |
|
74 |
|
75 | deepEqual(cont0.getElementsByTagName('li').length, 2,
|
76 | 'Filter 0 options length');
|
77 | deepEqual(cont1.options.length, 2, 'Filter 1 options length');
|
78 | });
|
79 |
|
80 | test('Can clear filters', function() {
|
81 |
|
82 | tf.clearFilters();
|
83 |
|
84 |
|
85 | deepEqual(cont0.getElementsByTagName('li').length, 3,
|
86 | 'Filter 0 options length');
|
87 | deepEqual(cont1.options.length, 7, 'Filter 1 options length');
|
88 | });
|
89 |
|
90 | test('Destroy TableFilter', function() {
|
91 |
|
92 | tf.destroy();
|
93 |
|
94 |
|
95 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
96 | });
|
97 | }
|
98 |
|
99 | })(window, TableFilter);
|