1 | (function(win, TableFilter){
|
2 |
|
3 | var tf = new TableFilter('demo', {
|
4 | base_path: '../dist/tablefilter/',
|
5 | col_types: [
|
6 | null, null, null,
|
7 | { type: 'formatted-number', decimal: ',', thousands: ','},
|
8 | 'formatted-number', null,
|
9 | { type: 'date', locale: 'fr', },
|
10 | { type: 'date', locale: 'en', format: '{dd}-{MM}-{yyyy|yy}' },
|
11 | { type: 'date', locale: 'en', format: ['{dd}-{months}-{yyyy|yy}'] },
|
12 | 'IpAddress',
|
13 | {
|
14 | type: 'date', locale: 'en',
|
15 | format: ['{yyyy|yy}-{MM}-{dd} {HH}:{mm}:{ss}']
|
16 | }
|
17 | ]
|
18 | });
|
19 | tf.init();
|
20 | window.tf = tf;
|
21 |
|
22 | module('Sanity checks');
|
23 | test('Data types', function() {
|
24 | deepEqual(tf instanceof TableFilter, true, 'TableFilter instanciated');
|
25 | deepEqual(
|
26 | tf.hasType(3, ['formatted-number']) &&
|
27 | tf.hasType(4, ['formatted-number']),
|
28 | true, 'Has number column types'
|
29 | );
|
30 | deepEqual(
|
31 | tf.hasType(6, ['date']) &&
|
32 | tf.hasType(7, ['date']) &&
|
33 | tf.hasType(8, ['date']),
|
34 | true, 'Has date column types'
|
35 | );
|
36 | });
|
37 |
|
38 | module('Data types filtering');
|
39 | test('Can filter a column with a string', function() {
|
40 |
|
41 | tf.setFilterValue(0, 'carl');
|
42 | tf.filter();
|
43 |
|
44 |
|
45 | deepEqual(tf.getValidRows(), [14, 18], 'Expected rows');
|
46 |
|
47 | });
|
48 |
|
49 | test('Can filter a EU formatted number', function() {
|
50 |
|
51 | tf.clearFilters();
|
52 |
|
53 |
|
54 | tf.setFilterValue(3, '1.836,09');
|
55 | tf.filter();
|
56 |
|
57 |
|
58 | deepEqual(tf.getValidRows(), [6], 'Expected rows');
|
59 | });
|
60 |
|
61 | test('Can filter a EU formatted number column with a number', function() {
|
62 |
|
63 | tf.clearFilters();
|
64 |
|
65 |
|
66 | tf.setFilterValue(3, 3876);
|
67 | tf.filter();
|
68 |
|
69 |
|
70 | deepEqual(tf.getValidRows(), [14], 'Expected rows');
|
71 | });
|
72 |
|
73 | test('Can filter a EU formatted number column with a number without ' +
|
74 | 'thousands separator', function() {
|
75 |
|
76 | tf.clearFilters();
|
77 |
|
78 |
|
79 | tf.setFilterValue(3, '1393,52');
|
80 | tf.filter();
|
81 |
|
82 |
|
83 | deepEqual(tf.getValidRows(), [13], 'Expected rows');
|
84 | });
|
85 |
|
86 | test('Can filter a EU formatted number column with a number without ' +
|
87 | 'decimals', function() {
|
88 |
|
89 | tf.clearFilters();
|
90 |
|
91 |
|
92 | tf.setFilterValue(3, '2.805');
|
93 | tf.filter();
|
94 |
|
95 |
|
96 | deepEqual(tf.getValidRows(), [7], 'Expected rows');
|
97 | });
|
98 |
|
99 | test('Can filter a formatted number', function() {
|
100 |
|
101 | tf.clearFilters();
|
102 |
|
103 |
|
104 | tf.setFilterValue(4, '1,836.09');
|
105 | tf.filter();
|
106 |
|
107 |
|
108 | deepEqual(tf.getValidRows(), [6], 'Expected rows');
|
109 | });
|
110 |
|
111 | test('Can filter a number', function() {
|
112 |
|
113 | tf.clearFilters();
|
114 |
|
115 |
|
116 | tf.setFilterValue(4, 1836.09);
|
117 | tf.filter();
|
118 |
|
119 |
|
120 | deepEqual(tf.getValidRows(), [6], 'Expected rows');
|
121 | });
|
122 |
|
123 | test('Can filter a formatted number column with a number', function() {
|
124 |
|
125 | tf.clearFilters();
|
126 |
|
127 |
|
128 | tf.setFilterValue(4, 3876);
|
129 | tf.filter();
|
130 |
|
131 |
|
132 | deepEqual(tf.getValidRows(), [14], 'Expected rows');
|
133 | });
|
134 |
|
135 | test('Can filter a formatted number column with a number without ' +
|
136 | 'thousands separator', function() {
|
137 |
|
138 | tf.clearFilters();
|
139 |
|
140 |
|
141 | tf.setFilterValue(4, '1393.52');
|
142 | tf.filter();
|
143 |
|
144 |
|
145 | deepEqual(tf.getValidRows(), [13], 'Expected rows');
|
146 | });
|
147 |
|
148 | test('Can filter a formatted number column with a number without ' +
|
149 | 'decimals', function() {
|
150 |
|
151 | tf.clearFilters();
|
152 |
|
153 |
|
154 | tf.setFilterValue(4, '2,805');
|
155 | tf.filter();
|
156 |
|
157 |
|
158 | deepEqual(tf.getValidRows(), [7], 'Expected rows');
|
159 | });
|
160 |
|
161 | test('Can filter a EU formatted date column', function() {
|
162 |
|
163 | tf.clearFilters();
|
164 |
|
165 |
|
166 | tf.setFilterValue(6, '14/7/1994');
|
167 | tf.filter();
|
168 |
|
169 |
|
170 | deepEqual(tf.getValidRows(), [16], 'Expected rows');
|
171 | });
|
172 |
|
173 | test('Can filter a EU formatted date column with different date separator',
|
174 | function() {
|
175 |
|
176 | tf.clearFilters();
|
177 |
|
178 |
|
179 | tf.setFilterValue(6, '20-10-97');
|
180 | tf.filter();
|
181 |
|
182 |
|
183 | deepEqual(tf.getValidRows(), [17], 'Expected rows');
|
184 | });
|
185 |
|
186 | test('Can filter a formatted date column', function() {
|
187 |
|
188 | tf.clearFilters();
|
189 |
|
190 |
|
191 | tf.setFilterValue(7, '7/14/1994');
|
192 | tf.filter();
|
193 |
|
194 |
|
195 | deepEqual(tf.getValidRows(), [16], 'Expected rows');
|
196 | });
|
197 |
|
198 | test('Can filter a formatted date column with different date separator',
|
199 | function() {
|
200 |
|
201 | tf.clearFilters();
|
202 |
|
203 |
|
204 | tf.setFilterValue(7, '10-20-97');
|
205 | tf.filter();
|
206 |
|
207 |
|
208 | deepEqual(tf.getValidRows(), [17], 'Expected rows');
|
209 | });
|
210 |
|
211 | test('Can filter a dd-MMM-yyy formatted date column', function() {
|
212 |
|
213 | tf.clearFilters();
|
214 |
|
215 |
|
216 | tf.setFilterValue(8, '3-Jul-2002');
|
217 | tf.filter();
|
218 |
|
219 |
|
220 | deepEqual(tf.getValidRows(), [8], 'Expected rows');
|
221 | });
|
222 |
|
223 | test('Can filter a dd-MMM-yyy formatted date column with different date ' +
|
224 | 'separator', function() {
|
225 |
|
226 | tf.clearFilters();
|
227 |
|
228 |
|
229 | tf.setFilterValue(8, '25.Mar.2000');
|
230 | tf.filter();
|
231 |
|
232 |
|
233 | deepEqual(tf.getValidRows(), [4], 'Expected rows');
|
234 | });
|
235 |
|
236 | test('Can filter an IP address column', function() {
|
237 |
|
238 | tf.clearFilters();
|
239 |
|
240 |
|
241 | tf.setFilterValue(9, '219.115.156.145');
|
242 | tf.filter();
|
243 |
|
244 |
|
245 | deepEqual(tf.getValidRows(), [8], 'Expected rows');
|
246 | });
|
247 |
|
248 | test('Can filter an IP address column with a truncated IP address',
|
249 | function() {
|
250 |
|
251 | tf.clearFilters();
|
252 |
|
253 |
|
254 | tf.setFilterValue(9, '219.115.15');
|
255 | tf.filter();
|
256 |
|
257 |
|
258 | deepEqual(tf.getValidRows(), [4, 8, 14], 'Expected rows');
|
259 | });
|
260 |
|
261 | test('Can filter datetime format', function() {
|
262 |
|
263 | tf.clearFilters();
|
264 |
|
265 |
|
266 | tf.setFilterValue(10, '2006-06-03 11:59:48');
|
267 | tf.filter();
|
268 |
|
269 |
|
270 | deepEqual(tf.getValidRows(), [8], 'Expected rows');
|
271 | });
|
272 |
|
273 | test('Can filter datetime format with operator', function() {
|
274 |
|
275 | tf.clearFilters();
|
276 |
|
277 |
|
278 | tf.setFilterValue(10, '>2006-06-03 11:59:48');
|
279 | tf.filter();
|
280 |
|
281 |
|
282 | deepEqual(tf.getValidRows().length, 7, 'Expected rows');
|
283 | });
|
284 |
|
285 | module('Locale helpers');
|
286 | test('Can get decimal separator for given column from config', function() {
|
287 |
|
288 | var result = tf.getDecimal(3);
|
289 |
|
290 |
|
291 | deepEqual(result, ',', 'Decimal separator for given column');
|
292 | });
|
293 |
|
294 | test('Can get decimal separator for given column from global setting',
|
295 | function() {
|
296 |
|
297 | var result = tf.getDecimal(1);
|
298 |
|
299 |
|
300 | deepEqual(result, '.', 'Decimal separator for given column');
|
301 | });
|
302 |
|
303 | module('Tear-down');
|
304 | test('can destroy TableFilter DOM elements', function() {
|
305 | tf.destroy();
|
306 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
307 | });
|
308 |
|
309 | })(window, TableFilter);
|