1 | var tf = new TableFilter('demo', {
|
2 | base_path: '../dist/tablefilter/',
|
3 | col_types: [
|
4 | null,
|
5 | { type: 'date', format: ['{dd}.{MM}.{yyyy|yy}'] },
|
6 | { type: 'date', format: ['{dd}.{months}.{yyyy}'] },
|
7 | null,
|
8 | null,
|
9 | 'formatted-number'
|
10 | ]
|
11 | });
|
12 | tf.init();
|
13 |
|
14 | module('Sanity checks');
|
15 | test('TableFilter object', function() {
|
16 | deepEqual(tf instanceof TableFilter, true, 'TableFilter instantiated');
|
17 | deepEqual(tf.id, 'demo', 'id check');
|
18 | deepEqual(tf.filtersRowIndex, 0, 'Filters row index');
|
19 | });
|
20 |
|
21 | module('Issue 74');
|
22 | test('can filter values in this format: 21.1.18 as string', function(){
|
23 | tf.setFilterValue(0, '2');
|
24 | tf.filter();
|
25 | deepEqual(tf.getValidRows().length, 3, 'Expected number of matches');
|
26 | });
|
27 | test('can filter values in this format: 21.1.18 as date', function(){
|
28 | tf.clearFilters();
|
29 | tf.setFilterValue(1, '21.1.2005');
|
30 | tf.filter();
|
31 | deepEqual(tf.getValidRows().length, 1, 'Expected number of matches');
|
32 | });
|
33 | test('can filter values in this format: 21.1.18 as date with operator',
|
34 | function(){
|
35 | tf.clearFilters();
|
36 | tf.setFilterValue(1, '>21.1.04');
|
37 | tf.filter();
|
38 | deepEqual(tf.getValidRows().length, 1, 'Expected number of matches');
|
39 | }
|
40 | );
|
41 |
|
42 | module('Issue 72');
|
43 | test('can filter values in this format: 21-Jul-2010 as date', function(){
|
44 | tf.clearFilters();
|
45 | tf.setFilterValue(2, '14-Mar-2009');
|
46 | tf.filter();
|
47 | deepEqual(tf.getValidRows().length, 1, 'Expected number of matches');
|
48 | });
|
49 | test('can filter values in this format: 21-Jul-2010 as date with operator',
|
50 | function(){
|
51 | tf.clearFilters();
|
52 | tf.setFilterValue(2, '<21-Jul-2010');
|
53 | tf.filter();
|
54 | deepEqual(tf.getValidRows().length, 2, 'Expected number of matches');
|
55 | }
|
56 | );
|
57 |
|
58 | module('Issue 217');
|
59 | test('can filter columns with blank space separated values (1)', function(){
|
60 | tf.clearFilters();
|
61 | tf.setFilterValue(3, 'c');
|
62 | tf.filter();
|
63 | deepEqual(tf.getValidRows().length, 1, 'Expected number of matches');
|
64 | });
|
65 | test('can filter columns with blank space separated values (2)', function(){
|
66 | tf.clearFilters();
|
67 | tf.setFilterValue(3, 'xyz');
|
68 | tf.filter();
|
69 | deepEqual(tf.getValidRows().length, 3, 'Expected number of matches');
|
70 | });
|
71 | test('can filter columns with alpha numeric values (1)', function(){
|
72 | tf.clearFilters();
|
73 | tf.setFilterValue(4, '1');
|
74 | tf.filter();
|
75 | deepEqual(tf.getValidRows().length, 1, 'Expected number of matches');
|
76 | });
|
77 | test('can filter columns with alpha numeric values (2)', function(){
|
78 | tf.clearFilters();
|
79 | tf.setFilterValue(4, 'numeric');
|
80 | tf.filter();
|
81 | deepEqual(tf.getValidRows().length, 3, 'Expected number of matches');
|
82 | });
|
83 | test('can filter numeric value (6)', function(){
|
84 |
|
85 | tf.clearFilters();
|
86 |
|
87 |
|
88 | tf.setFilterValue(5, 2767);
|
89 | tf.filter();
|
90 |
|
91 |
|
92 | deepEqual(tf.getFilteredDataCol(5), ['2767'], 'Expected match');
|
93 | });
|
94 | test('Should return no results for an unmatched term (6)', function(){
|
95 |
|
96 | tf.clearFilters();
|
97 |
|
98 |
|
99 | tf.setFilterValue(5, 'hello world');
|
100 | tf.filter();
|
101 |
|
102 |
|
103 | deepEqual(tf.getValidRows().length, 0, 'No matches');
|
104 | });
|
105 |
|
106 |
|
107 | module('Filtering data types');
|
108 | module('Date types');
|
109 | test('can filter date with `<` operator', function(){
|
110 |
|
111 | tf.clearFilters();
|
112 |
|
113 |
|
114 | tf.setFilterValue(2, '< 14-Mar-2009');
|
115 | tf.filter();
|
116 |
|
117 |
|
118 | deepEqual(
|
119 | tf.getFilteredDataCol(2),
|
120 | ['23-Oct-2007'],
|
121 | 'Expected match'
|
122 | );
|
123 | });
|
124 |
|
125 | test('can filter date with `<=` operator', function(){
|
126 |
|
127 | tf.clearFilters();
|
128 |
|
129 |
|
130 | tf.setFilterValue(2, '<= 14-Mar-2009');
|
131 | tf.filter();
|
132 |
|
133 |
|
134 | deepEqual(
|
135 | tf.getFilteredDataCol(2),
|
136 | ['23-Oct-2007', '14-Mar-2009'],
|
137 | 'Expected match'
|
138 | );
|
139 | });
|
140 |
|
141 | test('can filter date with `>` operator', function(){
|
142 |
|
143 | tf.clearFilters();
|
144 |
|
145 |
|
146 | tf.setFilterValue(2, '> 14/03/2009');
|
147 | tf.filter();
|
148 |
|
149 |
|
150 | deepEqual(
|
151 | tf.getFilteredDataCol(2),
|
152 | ['3-Jan-2014'],
|
153 | 'Expected match'
|
154 | );
|
155 | });
|
156 |
|
157 | test('can filter date with `>` operator', function(){
|
158 |
|
159 | tf.clearFilters();
|
160 |
|
161 |
|
162 | tf.setFilterValue(2, '>= 14/03/2009');
|
163 | tf.filter();
|
164 |
|
165 |
|
166 | deepEqual(
|
167 | tf.getFilteredDataCol(2),
|
168 | ['3-Jan-2014', '14-Mar-2009'],
|
169 | 'Expected match'
|
170 | );
|
171 | });
|
172 |
|
173 | test('can filter date with `!` operator', function(){
|
174 |
|
175 | tf.clearFilters();
|
176 |
|
177 |
|
178 | tf.setFilterValue(2, '! 14-Mar-2009');
|
179 | tf.filter();
|
180 |
|
181 |
|
182 | deepEqual(
|
183 | tf.getFilteredDataCol(2),
|
184 | ['3-Jan-2014', '23-Oct-2007'],
|
185 | 'Expected match'
|
186 | );
|
187 | });
|
188 |
|
189 | test('can filter date with `=` operator', function(){
|
190 |
|
191 | tf.clearFilters();
|
192 |
|
193 |
|
194 | tf.setFilterValue(2, '= 14-Mar-2009');
|
195 | tf.filter();
|
196 |
|
197 |
|
198 | deepEqual(
|
199 | tf.getFilteredDataCol(2),
|
200 | ['14-Mar-2009'],
|
201 | 'Expected match'
|
202 | );
|
203 | });
|
204 |
|
205 | test('can filter date with `=` operator and different date format', function(){
|
206 |
|
207 | tf.clearFilters();
|
208 |
|
209 |
|
210 | tf.setFilterValue(2, '= 14.03.2009');
|
211 | tf.filter();
|
212 |
|
213 |
|
214 | deepEqual(
|
215 | tf.getFilteredDataCol(2),
|
216 | ['14-Mar-2009'],
|
217 | 'Expected match'
|
218 | );
|
219 | });
|
220 |
|
221 | test('can filter date with different date format', function(){
|
222 |
|
223 | tf.clearFilters();
|
224 |
|
225 |
|
226 | tf.setFilterValue(2, '2007-10-23');
|
227 | tf.filter();
|
228 |
|
229 |
|
230 | deepEqual(
|
231 | tf.getFilteredDataCol(2),
|
232 | ['23-Oct-2007'],
|
233 | 'Expected match'
|
234 | );
|
235 | });
|
236 |
|
237 | test('can filter empty value with [empty] operator', function(){
|
238 |
|
239 | var cellValue = tf.getCellValue(tf.dom().rows[2].cells[2]);
|
240 | tf.clearFilters();
|
241 | tf.dom().rows[2].cells[2].innerHTML = '';
|
242 |
|
243 |
|
244 | tf.setFilterValue(2, '[empty]');
|
245 | tf.filter();
|
246 |
|
247 |
|
248 | deepEqual(
|
249 | tf.getFilteredDataCol(2),
|
250 | [''],
|
251 | 'Expected match'
|
252 | );
|
253 |
|
254 | tf.dom().rows[2].cells[2].innerHTML = cellValue;
|
255 | });
|
256 |
|
257 | test('can filter empty value with [nonempty] operator', function(){
|
258 |
|
259 | tf.clearFilters();
|
260 |
|
261 |
|
262 | tf.setFilterValue(2, '[nonempty]');
|
263 | tf.filter();
|
264 |
|
265 |
|
266 | deepEqual(
|
267 | tf.getFilteredDataCol(2),
|
268 | ['3-Jan-2014', '23-Oct-2007', '14-Mar-2009'],
|
269 | 'Expected match'
|
270 | );
|
271 | });
|
272 |
|
273 | test('can filter date with date range with operators', function(){
|
274 |
|
275 | tf.clearFilters();
|
276 |
|
277 |
|
278 | tf.setFilterValue(2, '<3-jan-2014 && >=23-Oct-2007');
|
279 | tf.filter();
|
280 |
|
281 |
|
282 | deepEqual(
|
283 | tf.getFilteredDataCol(2),
|
284 | ['23-Oct-2007', '14-Mar-2009'],
|
285 | 'Expected match'
|
286 | );
|
287 | });
|
288 |
|
289 | module('Tear-down');
|
290 | test('can destroy TableFilter DOM elements', function() {
|
291 | tf.destroy();
|
292 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
293 | });
|