UNPKG

2.72 kBJavaScriptView Raw
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 paging: 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.paging, true, 'Paging setting is on');
22 });
23
24 module('Behaviour');
25 test('Can link filters 0-1', function() {
26 // setup
27 tf.clearFilters();
28 tf.activateFilter(0);
29
30 // act
31 tf.setFilterValue(0, 'Sydney');
32 tf.filter();
33
34 // assert
35 deepEqual(cont0.getElementsByTagName('li').length, 2,
36 'Filter 0 options length');
37 deepEqual(cont1.options.length, 5, 'Filter 1 options length');
38 });
39
40 test('Can re-populate filters with clearFilters', function() {
41 // act
42 tf.clearFilters();
43
44 // assert
45 deepEqual(cont0.getElementsByTagName('li').length, 3,
46 'Filter 0 options length');
47 deepEqual(cont1.options.length, 7, 'Filter 1 options length');
48 });
49
50 test('Can link filters 1-0', function() {
51 // setup
52 tf.clearFilters();
53 tf.activateFilter(1);
54
55 // act
56 tf.setFilterValue(1, 'Brisbane');
57 tf.filter();
58
59 // assert
60 deepEqual(cont0.getElementsByTagName('li').length, 3,
61 'Filter 0 options length');
62 deepEqual(cont1.options.length, 2, 'Filter 1 options length');
63 });
64
65 test('Can re-populate filter 0 with clear option', function() {
66 // setup
67 tf.activateFilter(0);
68
69 // act
70 tf.setFilterValue(0, '');
71 tf.filter();
72
73 // assert
74 deepEqual(cont0.getElementsByTagName('li').length, 3,
75 'Filter 0 options length');
76 });
77
78 test('Can re-populate filter 1 with clear option', function() {
79 // setup
80 tf.activateFilter(1);
81
82 // act
83 tf.setFilterValue(1, '');
84 tf.filter();
85
86 // assert
87 deepEqual(cont1.options.length, 7, 'Filter 1 options length');
88 });
89
90 module('Tear down');
91 test('Destroy TableFilter', function() {
92 // act
93 tf.destroy();
94
95 // assert
96 deepEqual(tf.isInitialized(), false, 'Filters removed');
97 });
98
99})(window, TableFilter);