1 |
|
2 | (function(win, TableFilter){
|
3 |
|
4 | var tf = new TableFilter('demo', {
|
5 | base_path: '../dist/tablefilter/',
|
6 | col_1: 'checklist',
|
7 | col_3: 'select',
|
8 | custom_options: {
|
9 | cols: [1, 3],
|
10 | texts: [
|
11 | ['Perth', 'Canberra'],
|
12 | ['0-0.5', '0.5-1', '1-2', '>2']
|
13 | ],
|
14 | values: [
|
15 | ['rgx:^Perth$', 'rgx:^Canberra$'],
|
16 | ['>0 && <=0.5', '>0.5 && <=1', '>1 && <=2', '>2']
|
17 | ],
|
18 | sorts: [false, false]
|
19 | }
|
20 | });
|
21 | tf.init();
|
22 |
|
23 | module('Sanity checks');
|
24 | test('Filter type', function() {
|
25 | deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
26 | deepEqual(
|
27 | tf.getFilterElement(3).nodeName, 'SELECT', 'Expected filter type');
|
28 | });
|
29 |
|
30 | module('Behaviour');
|
31 | test('Filter column with custom filter', function() {
|
32 | var flt = tf.getFilterElement(3);
|
33 | flt.selectedIndex = flt.options.length-1;
|
34 | tf.filter();
|
35 |
|
36 | deepEqual(
|
37 | tf.getFilteredData().length, 2, 'Expected nb of filtered rows');
|
38 |
|
39 | tf.clearFilters();
|
40 |
|
41 | deepEqual(
|
42 | tf.getFilteredData().length, 7, 'Expected nb of filtered rows');
|
43 | });
|
44 |
|
45 | test('set filter value with regex', function() {
|
46 |
|
47 | tf.setFilterValue(1, ['rgx:^Canberra$', 'rgx:^Perth$']);
|
48 | tf.filter();
|
49 |
|
50 |
|
51 | deepEqual(
|
52 | tf.getFilteredData(),
|
53 | [
|
54 | [
|
55 | 4,
|
56 | [
|
57 | 'Sydney',
|
58 | 'Canberra',
|
59 | '286',
|
60 | '.6',
|
61 | '4.3'
|
62 | ]
|
63 | ], [
|
64 | 6,
|
65 | [
|
66 | 'Adelaide',
|
67 | 'Perth',
|
68 | '2781',
|
69 | '3.1',
|
70 | '38'
|
71 | ]
|
72 | ]
|
73 | ],
|
74 | 'expected filtered data');
|
75 | });
|
76 |
|
77 | test('Paging: filter column with custom filter', function() {
|
78 | tf.destroy();
|
79 | tf = null;
|
80 | tf = new TableFilter('demo', {
|
81 | col_3: 'select',
|
82 | custom_options: {
|
83 | cols: [3],
|
84 | texts: [['0-0.5', '0.5-1', '1-2', '>2']],
|
85 | values: [['>0 && <=0.5', '>0.5 && <=1', '>1 && <=2', '>2']],
|
86 | sorts: [false]
|
87 | },
|
88 | paging: true,
|
89 | paging_length: 3
|
90 | });
|
91 | tf.init();
|
92 |
|
93 | var flt = tf.getFilterElement(3);
|
94 | flt.selectedIndex = flt.options.length-1;
|
95 | tf.filter();
|
96 |
|
97 | deepEqual(
|
98 | tf.getFilteredData().length, 2, 'Expected nb of filtered rows');
|
99 |
|
100 | tf.clearFilters();
|
101 |
|
102 | deepEqual(
|
103 | tf.getFilteredData().length, 7, 'Expected nb of filtered rows');
|
104 |
|
105 | tf.destroy();
|
106 | tf = null;
|
107 | });
|
108 |
|
109 | test('Grid layout: filter column with custom filter', function() {
|
110 | tf = new TableFilter('demo', {
|
111 | base_path: '../dist/tablefilter/',
|
112 | col_3: 'select',
|
113 | custom_options: {
|
114 | cols: [3],
|
115 | texts: [['0-0.5', '0.5-1', '1-2', '>2']],
|
116 | values: [['>0 && <=0.5', '>0.5 && <=1', '>1 && <=2', '>2']],
|
117 | sorts: [false]
|
118 | },
|
119 | grid_layout: true
|
120 | });
|
121 | tf.init();
|
122 |
|
123 | var flt = tf.getFilterElement(3);
|
124 | flt.selectedIndex = flt.options.length-1;
|
125 | tf.filter();
|
126 |
|
127 | deepEqual(
|
128 | tf.getFilteredData().length, 2, 'Expected nb of filtered rows');
|
129 |
|
130 | tf.clearFilters();
|
131 |
|
132 | deepEqual(
|
133 | tf.getFilteredData().length, 7, 'Expected nb of filtered rows');
|
134 |
|
135 | tf.destroy();
|
136 | tf = null;
|
137 | });
|
138 |
|
139 | })(window, TableFilter);
|