]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | describe("Ext.util.Filter", function() {\r |
2 | var filter;\r | |
3 | \r | |
4 | describe("construction", function() {\r | |
5 | var createFilter = function(config) {\r | |
6 | return function() {\r | |
7 | new Ext.util.Filter(config);\r | |
8 | };\r | |
9 | };\r | |
10 | \r | |
11 | it("should accept a property and value", function() {\r | |
12 | expect(createFilter({property: 'test', value: 'a'})).not.toThrow();\r | |
13 | });\r | |
14 | \r | |
15 | it("should accept a false", function() {\r | |
16 | expect(createFilter({property: 'test', value: false})).not.toThrow();\r | |
17 | });\r | |
18 | \r | |
19 | it("should accept a 0", function() {\r | |
20 | expect(createFilter({property: 'test', value: 0})).not.toThrow();\r | |
21 | });\r | |
22 | \r | |
23 | it("should accept a ''", function() {\r | |
24 | expect(createFilter({property: 'test', value: ''})).not.toThrow();\r | |
25 | });\r | |
26 | \r | |
27 | it("should accept a filter function", function() {\r | |
28 | expect(createFilter({filterFn: Ext.emptyFn})).not.toThrow();\r | |
29 | });\r | |
30 | \r | |
31 | it("should require at least a filter function or a property/value combination", function() {\r | |
32 | expect(createFilter()).toThrow();\r | |
33 | });\r | |
34 | });\r | |
35 | \r | |
36 | describe("disableOnEmpty", function() {\r | |
37 | var filter;\r | |
38 | \r | |
39 | function makeFilter(v) {\r | |
40 | filter = new Ext.util.Filter({\r | |
41 | disableOnEmpty: true,\r | |
42 | property: 'foo',\r | |
43 | value: v\r | |
44 | });\r | |
45 | }\r | |
46 | \r | |
47 | it("should disable when the value is ''", function() {\r | |
48 | makeFilter('');\r | |
49 | expect(filter.getDisabled()).toBe(true);\r | |
50 | });\r | |
51 | \r | |
52 | it("should disable when the value is null", function() {\r | |
53 | makeFilter(null);\r | |
54 | expect(filter.getDisabled()).toBe(true);\r | |
55 | });\r | |
56 | });\r | |
57 | \r | |
58 | describe("creating filter functions", function() {\r | |
59 | var edRecord = {name: 'Ed'},\r | |
60 | tedRecord = {name: 'Ted'},\r | |
61 | abeRecord = {name: 'Abe'},\r | |
62 | edwardRecord = {name: 'Edward'};\r | |
63 | \r | |
64 | it("should honor a simple property matcher", function() {\r | |
65 | filter = new Ext.util.Filter({\r | |
66 | property: 'name',\r | |
67 | value : 'Ed'\r | |
68 | });\r | |
69 | \r | |
70 | var fn = filter.getFilterFn(); \r | |
71 | \r | |
72 | expect(fn(edRecord)).toBe(true);\r | |
73 | expect(fn(edwardRecord)).toBe(true);\r | |
74 | expect(fn(tedRecord)).toBe(false);\r | |
75 | expect(fn(abeRecord)).toBe(false);\r | |
76 | });\r | |
77 | \r | |
78 | it("should honor anyMatch", function() {\r | |
79 | filter = new Ext.util.Filter({\r | |
80 | anyMatch: true,\r | |
81 | property: 'name',\r | |
82 | value : 'Ed'\r | |
83 | });\r | |
84 | \r | |
85 | var fn = filter.getFilterFn(); \r | |
86 | \r | |
87 | expect(fn(edRecord)).toBe(true);\r | |
88 | expect(fn(edwardRecord)).toBe(true);\r | |
89 | expect(fn(tedRecord)).toBe(true);\r | |
90 | expect(fn(abeRecord)).toBe(false);\r | |
91 | });\r | |
92 | \r | |
93 | it("should honor exactMatch", function() {\r | |
94 | filter = new Ext.util.Filter({\r | |
95 | exactMatch: true,\r | |
96 | property : 'name',\r | |
97 | value : 'Ed'\r | |
98 | });\r | |
99 | \r | |
100 | var fn = filter.getFilterFn(); \r | |
101 | \r | |
102 | expect(fn(edRecord)).toBe(true);\r | |
103 | expect(fn(edwardRecord)).toBe(false);\r | |
104 | expect(fn(tedRecord)).toBe(false);\r | |
105 | expect(fn(abeRecord)).toBe(false);\r | |
106 | });\r | |
107 | \r | |
108 | it("should honor case sensitivity", function() {\r | |
109 | filter = new Ext.util.Filter({\r | |
110 | caseSensitive: true,\r | |
111 | property : 'name',\r | |
112 | value : 'Ed'\r | |
113 | });\r | |
114 | \r | |
115 | var fn = filter.getFilterFn(); \r | |
116 | \r | |
117 | expect(fn(edRecord)).toBe(true);\r | |
118 | expect(fn(edwardRecord)).toBe(true);\r | |
119 | expect(fn(tedRecord)).toBe(false);\r | |
120 | });\r | |
121 | \r | |
122 | it("should honor case sensitivity and anyMatch", function() {\r | |
123 | filter = new Ext.util.Filter({\r | |
124 | caseSensitive: true,\r | |
125 | anyMatch : true,\r | |
126 | property : 'name',\r | |
127 | value : 'ed'\r | |
128 | });\r | |
129 | \r | |
130 | var fn = filter.getFilterFn(); \r | |
131 | \r | |
132 | expect(fn(tedRecord)).toBe(true);\r | |
133 | expect(fn(edRecord)).toBe(false);\r | |
134 | expect(fn(edwardRecord)).toBe(false);\r | |
135 | });\r | |
136 | \r | |
137 | it("should honor the root property", function() {\r | |
138 | var users = [{\r | |
139 | data: {name: 'Ed'}\r | |
140 | }, {\r | |
141 | data: {name: 'Ted'}\r | |
142 | }, {\r | |
143 | data: {name: 'Edward'}\r | |
144 | }, {\r | |
145 | data: {name: 'Abe'}\r | |
146 | }];\r | |
147 | \r | |
148 | var filter = new Ext.util.Filter({\r | |
149 | root : 'data',\r | |
150 | property: 'name',\r | |
151 | value : 'Ed'\r | |
152 | });\r | |
153 | \r | |
154 | var fn = filter.getFilterFn(); \r | |
155 | \r | |
156 | expect(fn(users[0])).toBe(true);\r | |
157 | expect(fn(users[2])).toBe(true);\r | |
158 | expect(fn(users[1])).toBe(false);\r | |
159 | expect(fn(users[3])).toBe(false);\r | |
160 | });\r | |
161 | });\r | |
162 | \r | |
163 | describe("operators", function() {\r | |
164 | var filter;\r | |
165 | \r | |
166 | function makeFilter(cfg) {\r | |
167 | filter = new Ext.util.Filter(Ext.apply({\r | |
168 | property: 'value'\r | |
169 | }, cfg));\r | |
170 | }\r | |
171 | \r | |
172 | function match(operator, v, candidate, cfg) {\r | |
173 | makeFilter(Ext.apply({\r | |
174 | operator: operator,\r | |
175 | value: candidate\r | |
176 | }, cfg));\r | |
177 | return filter.filter({value: v});\r | |
178 | }\r | |
179 | \r | |
180 | afterEach(function() {\r | |
181 | filter = null;\r | |
182 | });\r | |
183 | \r | |
184 | describe("<", function() {\r | |
185 | describe("numbers", function() {\r | |
186 | it("should match when the candidate is smaller than the value", function() {\r | |
187 | expect(match('<', 7, 10)).toBe(true);\r | |
188 | });\r | |
189 | \r | |
190 | it("should not match when the candidate is equal to the value", function() {\r | |
191 | expect(match('<', 10, 10)).toBe(false);\r | |
192 | });\r | |
193 | \r | |
194 | it("should not match when the candidate is larger than the value", function() {\r | |
195 | expect(match('<', 100, 10)).toBe(false);\r | |
196 | });\r | |
197 | });\r | |
198 | \r | |
199 | describe("strings", function() {\r | |
200 | it("should match when the candidate is smaller than the value", function() {\r | |
201 | expect(match('<', 'a', 'f')).toBe(true);\r | |
202 | });\r | |
203 | \r | |
204 | it("should not match when the candidate is equal to the value", function() {\r | |
205 | expect(match('<', 'j', 'j')).toBe(false);\r | |
206 | });\r | |
207 | \r | |
208 | it("should not match when the candidate is larger than the value", function() {\r | |
209 | expect(match('<', 'z', 'q')).toBe(false);\r | |
210 | });\r | |
211 | });\r | |
212 | \r | |
213 | describe("dates", function() {\r | |
214 | it("should match when the candidate is smaller than the value", function() {\r | |
215 | var d1 = new Date(2008, 0, 1),\r | |
216 | d2 = new Date(2010, 0, 1);\r | |
217 | \r | |
218 | expect(match('<', d1, d2)).toBe(true);\r | |
219 | });\r | |
220 | \r | |
221 | it("should not match when the candidate is equal to the value", function() {\r | |
222 | var d1 = new Date(2010, 0, 1),\r | |
223 | d2 = new Date(2010, 0, 1);\r | |
224 | \r | |
225 | expect(match('<', d1, d2)).toBe(false);\r | |
226 | });\r | |
227 | \r | |
228 | it("should not match when the candidate is larger than the value", function() {\r | |
229 | var d1 = new Date(2012, 0, 1),\r | |
230 | d2 = new Date(2010, 0, 1);\r | |
231 | \r | |
232 | expect(match('<', d1, d2)).toBe(false);\r | |
233 | });\r | |
234 | \r | |
235 | it("should match on the full date", function() {\r | |
236 | var d1 = new Date(2010, 0, 1, 12),\r | |
237 | d2 = new Date(2010, 0, 1, 10);\r | |
238 | \r | |
239 | expect(match('<', d1, d2)).toBe(false);\r | |
240 | });\r | |
241 | });\r | |
242 | \r | |
243 | describe("with convert", function() {\r | |
244 | it("should call the convert fn", function() {\r | |
245 | var d1 = new Date(2010, 0, 1, 10),\r | |
246 | d2 = new Date(2010, 0, 1, 12),\r | |
247 | convert = function(v) {\r | |
248 | return Ext.Date.clearTime(v, true).getTime();\r | |
249 | };\r | |
250 | \r | |
251 | expect(match('<', d1, d2, {convert: convert})).toBe(false);\r | |
252 | });\r | |
253 | });\r | |
254 | \r | |
255 | describe("value coercion", function() {\r | |
256 | it("should coerce the candidate value based on the value", function() {\r | |
257 | expect(match('<', '7', 10)).toBe(true);\r | |
258 | });\r | |
259 | });\r | |
260 | });\r | |
261 | \r | |
262 | describe("lt", function() {\r | |
263 | describe("numbers", function() {\r | |
264 | it("should match when the candidate is smaller than the value", function() {\r | |
265 | expect(match('lt', 7, 10)).toBe(true);\r | |
266 | });\r | |
267 | \r | |
268 | it("should not match when the candidate is equal to the value", function() {\r | |
269 | expect(match('lt', 10, 10)).toBe(false);\r | |
270 | });\r | |
271 | \r | |
272 | it("should not match when the candidate is larger than the value", function() {\r | |
273 | expect(match('lt', 100, 10)).toBe(false);\r | |
274 | });\r | |
275 | });\r | |
276 | \r | |
277 | describe("strings", function() {\r | |
278 | it("should match when the candidate is smaller than the value", function() {\r | |
279 | expect(match('lt', 'a', 'f')).toBe(true);\r | |
280 | });\r | |
281 | \r | |
282 | it("should not match when the candidate is equal to the value", function() {\r | |
283 | expect(match('lt', 'j', 'j')).toBe(false);\r | |
284 | });\r | |
285 | \r | |
286 | it("should not match when the candidate is larger than the value", function() {\r | |
287 | expect(match('lt', 'z', 'q')).toBe(false);\r | |
288 | });\r | |
289 | });\r | |
290 | \r | |
291 | describe("dates", function() {\r | |
292 | it("should match when the candidate is smaller than the value", function() {\r | |
293 | var d1 = new Date(2008, 0, 1),\r | |
294 | d2 = new Date(2010, 0, 1);\r | |
295 | \r | |
296 | expect(match('lt', d1, d2)).toBe(true);\r | |
297 | });\r | |
298 | \r | |
299 | it("should not match when the candidate is equal to the value", function() {\r | |
300 | var d1 = new Date(2010, 0, 1),\r | |
301 | d2 = new Date(2010, 0, 1);\r | |
302 | \r | |
303 | expect(match('lt', d1, d2)).toBe(false);\r | |
304 | });\r | |
305 | \r | |
306 | it("should not match when the candidate is larger than the value", function() {\r | |
307 | var d1 = new Date(2012, 0, 1),\r | |
308 | d2 = new Date(2010, 0, 1);\r | |
309 | \r | |
310 | expect(match('lt', d1, d2)).toBe(false);\r | |
311 | });\r | |
312 | \r | |
313 | it("should match on the full date", function() {\r | |
314 | var d1 = new Date(2010, 0, 1, 12),\r | |
315 | d2 = new Date(2010, 0, 1, 10);\r | |
316 | \r | |
317 | expect(match('lt', d1, d2)).toBe(false);\r | |
318 | });\r | |
319 | });\r | |
320 | \r | |
321 | describe("with convert", function() {\r | |
322 | it("should call the convert fn", function() {\r | |
323 | var d1 = new Date(2010, 0, 1, 10),\r | |
324 | d2 = new Date(2010, 0, 1, 12),\r | |
325 | convert = function(v) {\r | |
326 | return Ext.Date.clearTime(v, true).getTime();\r | |
327 | };\r | |
328 | \r | |
329 | expect(match('lt', d1, d2, {convert: convert})).toBe(false);\r | |
330 | });\r | |
331 | });\r | |
332 | \r | |
333 | describe("value coercion", function() {\r | |
334 | it("should coerce the candidate value based on the value", function() {\r | |
335 | expect(match('lt', '7', 10)).toBe(true);\r | |
336 | });\r | |
337 | });\r | |
338 | });\r | |
339 | \r | |
340 | describe("<=", function() {\r | |
341 | describe("numbers", function() {\r | |
342 | it("should match when the candidate is smaller than the value", function() {\r | |
343 | expect(match('<=', 7, 10)).toBe(true);\r | |
344 | });\r | |
345 | \r | |
346 | it("should match when the candidate is equal to the value", function() {\r | |
347 | expect(match('<=', 10, 10)).toBe(true);\r | |
348 | });\r | |
349 | \r | |
350 | it("should not match when the candidate is larger than the value", function() {\r | |
351 | expect(match('<=', 100, 10)).toBe(false);\r | |
352 | });\r | |
353 | });\r | |
354 | \r | |
355 | describe("strings", function() {\r | |
356 | it("should match when the candidate is smaller than the value", function() {\r | |
357 | expect(match('<=', 'a', 'f')).toBe(true);\r | |
358 | });\r | |
359 | \r | |
360 | it("should match when the candidate is equal to the value", function() {\r | |
361 | expect(match('<=', 'j', 'j')).toBe(true);\r | |
362 | });\r | |
363 | \r | |
364 | it("should not match when the candidate is larger than the value", function() {\r | |
365 | expect(match('<=', 'z', 'q')).toBe(false);\r | |
366 | });\r | |
367 | });\r | |
368 | \r | |
369 | describe("dates", function() {\r | |
370 | it("should match when the candidate is smaller than the value", function() {\r | |
371 | var d1 = new Date(2008, 0, 1),\r | |
372 | d2 = new Date(2010, 0, 1);\r | |
373 | \r | |
374 | expect(match('<=', d1, d2)).toBe(true);\r | |
375 | });\r | |
376 | \r | |
377 | it("should match when the candidate is equal to the value", function() {\r | |
378 | var d1 = new Date(2010, 0, 1),\r | |
379 | d2 = new Date(2010, 0, 1);\r | |
380 | \r | |
381 | expect(match('<=', d1, d2)).toBe(true);\r | |
382 | });\r | |
383 | \r | |
384 | it("should not match when the candidate is larger than the value", function() {\r | |
385 | var d1 = new Date(2012, 0, 1),\r | |
386 | d2 = new Date(2010, 0, 1);\r | |
387 | \r | |
388 | expect(match('<=', d1, d2)).toBe(false);\r | |
389 | });\r | |
390 | \r | |
391 | it("should match on the full date", function() {\r | |
392 | var d1 = new Date(2010, 0, 1, 12),\r | |
393 | d2 = new Date(2010, 0, 1, 10);\r | |
394 | \r | |
395 | expect(match('<=', d1, d2)).toBe(false);\r | |
396 | });\r | |
397 | });\r | |
398 | \r | |
399 | describe("with convert", function() {\r | |
400 | it("should call the convert fn", function() {\r | |
401 | var d1 = new Date(2010, 0, 1, 10),\r | |
402 | d2 = new Date(2010, 0, 1, 12),\r | |
403 | convert = function(v) {\r | |
404 | return Ext.Date.clearTime(v, true).getTime();\r | |
405 | };\r | |
406 | \r | |
407 | expect(match('<=', d1, d2, {convert: convert})).toBe(true);\r | |
408 | });\r | |
409 | });\r | |
410 | \r | |
411 | describe("value coercion", function() {\r | |
412 | it("should coerce the candidate value based on the value", function() {\r | |
413 | expect(match('<=', '7', 10)).toBe(true);\r | |
414 | });\r | |
415 | });\r | |
416 | });\r | |
417 | \r | |
418 | describe("le", function() {\r | |
419 | describe("numbers", function() {\r | |
420 | it("should match when the candidate is smaller than the value", function() {\r | |
421 | expect(match('le', 7, 10)).toBe(true);\r | |
422 | });\r | |
423 | \r | |
424 | it("should match when the candidate is equal to the value", function() {\r | |
425 | expect(match('le', 10, 10)).toBe(true);\r | |
426 | });\r | |
427 | \r | |
428 | it("should not match when the candidate is larger than the value", function() {\r | |
429 | expect(match('le', 100, 10)).toBe(false);\r | |
430 | });\r | |
431 | });\r | |
432 | \r | |
433 | describe("strings", function() {\r | |
434 | it("should match when the candidate is smaller than the value", function() {\r | |
435 | expect(match('le', 'a', 'f')).toBe(true);\r | |
436 | });\r | |
437 | \r | |
438 | it("should match when the candidate is equal to the value", function() {\r | |
439 | expect(match('le', 'j', 'j')).toBe(true);\r | |
440 | });\r | |
441 | \r | |
442 | it("should not match when the candidate is larger than the value", function() {\r | |
443 | expect(match('le', 'z', 'q')).toBe(false);\r | |
444 | });\r | |
445 | });\r | |
446 | \r | |
447 | describe("dates", function() {\r | |
448 | it("should match when the candidate is smaller than the value", function() {\r | |
449 | var d1 = new Date(2008, 0, 1),\r | |
450 | d2 = new Date(2010, 0, 1);\r | |
451 | \r | |
452 | expect(match('le', d1, d2)).toBe(true);\r | |
453 | });\r | |
454 | \r | |
455 | it("should match when the candidate is equal to the value", function() {\r | |
456 | var d1 = new Date(2010, 0, 1),\r | |
457 | d2 = new Date(2010, 0, 1);\r | |
458 | \r | |
459 | expect(match('le', d1, d2)).toBe(true);\r | |
460 | });\r | |
461 | \r | |
462 | it("should not match when the candidate is larger than the value", function() {\r | |
463 | var d1 = new Date(2012, 0, 1),\r | |
464 | d2 = new Date(2010, 0, 1);\r | |
465 | \r | |
466 | expect(match('le', d1, d2)).toBe(false);\r | |
467 | });\r | |
468 | \r | |
469 | it("should match on the full date", function() {\r | |
470 | var d1 = new Date(2010, 0, 1, 12),\r | |
471 | d2 = new Date(2010, 0, 1, 10);\r | |
472 | \r | |
473 | expect(match('le', d1, d2)).toBe(false);\r | |
474 | });\r | |
475 | });\r | |
476 | \r | |
477 | describe("with convert", function() {\r | |
478 | it("should call the convert fn", function() {\r | |
479 | var d1 = new Date(2010, 0, 1, 10),\r | |
480 | d2 = new Date(2010, 0, 1, 12),\r | |
481 | convert = function(v) {\r | |
482 | return Ext.Date.clearTime(v, true).getTime();\r | |
483 | };\r | |
484 | \r | |
485 | expect(match('le', d1, d2, {convert: convert})).toBe(true);\r | |
486 | });\r | |
487 | });\r | |
488 | \r | |
489 | describe("value coercion", function() {\r | |
490 | it("should coerce the candidate value based on the value", function() {\r | |
491 | expect(match('le', '7', 10)).toBe(true);\r | |
492 | });\r | |
493 | });\r | |
494 | });\r | |
495 | \r | |
496 | describe("=", function() {\r | |
497 | describe("numbers", function() {\r | |
498 | it("should not match when the candidate is smaller than the value", function() {\r | |
499 | expect(match('=', 7, 10)).toBe(false);\r | |
500 | });\r | |
501 | \r | |
502 | it("should match when the candidate is equal to the value", function() {\r | |
503 | expect(match('=', 10, 10)).toBe(true);\r | |
504 | });\r | |
505 | \r | |
506 | it("should not match when the candidate is larger than the value", function() {\r | |
507 | expect(match('=', 100, 10)).toBe(false);\r | |
508 | });\r | |
509 | });\r | |
510 | \r | |
511 | describe("strings", function() {\r | |
512 | it("should not match when the candidate is smaller than the value", function() {\r | |
513 | expect(match('=', 'a', 'f')).toBe(false);\r | |
514 | });\r | |
515 | \r | |
516 | it("should match when the candidate is equal to the value", function() {\r | |
517 | expect(match('=', 'j', 'j')).toBe(true);\r | |
518 | });\r | |
519 | \r | |
520 | it("should not match when the candidate is larger than the value", function() {\r | |
521 | expect(match('=', 'z', 'q')).toBe(false);\r | |
522 | });\r | |
523 | });\r | |
524 | \r | |
525 | describe("dates", function() {\r | |
526 | it("should not match when the candidate is smaller than the value", function() {\r | |
527 | var d1 = new Date(2008, 0, 1),\r | |
528 | d2 = new Date(2010, 0, 1);\r | |
529 | \r | |
530 | expect(match('=', d1, d2)).toBe(false);\r | |
531 | });\r | |
532 | \r | |
533 | it("should match when the candidate is equal to the value", function() {\r | |
534 | var d1 = new Date(2010, 0, 1),\r | |
535 | d2 = new Date(2010, 0, 1);\r | |
536 | \r | |
537 | expect(match('=', d1, d2)).toBe(true);\r | |
538 | });\r | |
539 | \r | |
540 | it("should not match when the candidate is larger than the value", function() {\r | |
541 | var d1 = new Date(2012, 0, 1),\r | |
542 | d2 = new Date(2010, 0, 1);\r | |
543 | \r | |
544 | expect(match('=', d1, d2)).toBe(false);\r | |
545 | });\r | |
546 | \r | |
547 | it("should match on the full date", function() {\r | |
548 | var d1 = new Date(2010, 0, 1, 10),\r | |
549 | d2 = new Date(2010, 0, 1, 12);\r | |
550 | \r | |
551 | expect(match('=', d1, d2)).toBe(false);\r | |
552 | });\r | |
553 | });\r | |
554 | \r | |
555 | describe("with convert", function() {\r | |
556 | it("should call the convert fn", function() {\r | |
557 | var d1 = new Date(2010, 0, 1, 12),\r | |
558 | d2 = new Date(2010, 0, 1, 10),\r | |
559 | convert = function(v) {\r | |
560 | return Ext.Date.clearTime(v, true).getTime();\r | |
561 | };\r | |
562 | \r | |
563 | expect(match('=', d1, d2, {convert: convert})).toBe(true);\r | |
564 | });\r | |
565 | });\r | |
566 | \r | |
567 | describe("value coercion", function() {\r | |
568 | it("should coerce the candidate value based on the value", function() {\r | |
569 | expect(match('=', '10', 10)).toBe(true);\r | |
570 | });\r | |
571 | });\r | |
572 | });\r | |
573 | \r | |
574 | describe("eq", function() {\r | |
575 | describe("numbers", function() {\r | |
576 | it("should not match when the candidate is smaller than the value", function() {\r | |
577 | expect(match('eq', 7, 10)).toBe(false);\r | |
578 | });\r | |
579 | \r | |
580 | it("should match when the candidate is equal to the value", function() {\r | |
581 | expect(match('eq', 10, 10)).toBe(true);\r | |
582 | });\r | |
583 | \r | |
584 | it("should not match when the candidate is larger than the value", function() {\r | |
585 | expect(match('eq', 100, 10)).toBe(false);\r | |
586 | });\r | |
587 | });\r | |
588 | \r | |
589 | describe("strings", function() {\r | |
590 | it("should not match when the candidate is smaller than the value", function() {\r | |
591 | expect(match('eq', 'a', 'f')).toBe(false);\r | |
592 | });\r | |
593 | \r | |
594 | it("should match when the candidate is equal to the value", function() {\r | |
595 | expect(match('eq', 'j', 'j')).toBe(true);\r | |
596 | });\r | |
597 | \r | |
598 | it("should not match when the candidate is larger than the value", function() {\r | |
599 | expect(match('eq', 'z', 'q')).toBe(false);\r | |
600 | });\r | |
601 | });\r | |
602 | \r | |
603 | describe("dates", function() {\r | |
604 | it("should not match when the candidate is smaller than the value", function() {\r | |
605 | var d1 = new Date(2008, 0, 1),\r | |
606 | d2 = new Date(2010, 0, 1);\r | |
607 | \r | |
608 | expect(match('eq', d1, d2)).toBe(false);\r | |
609 | });\r | |
610 | \r | |
611 | it("should match when the candidate is equal to the value", function() {\r | |
612 | var d1 = new Date(2010, 0, 1),\r | |
613 | d2 = new Date(2010, 0, 1);\r | |
614 | \r | |
615 | expect(match('eq', d1, d2)).toBe(true);\r | |
616 | });\r | |
617 | \r | |
618 | it("should not match when the candidate is larger than the value", function() {\r | |
619 | var d1 = new Date(2012, 0, 1),\r | |
620 | d2 = new Date(2010, 0, 1);\r | |
621 | \r | |
622 | expect(match('eq', d1, d2)).toBe(false);\r | |
623 | });\r | |
624 | \r | |
625 | it("should match on the full date", function() {\r | |
626 | var d1 = new Date(2010, 0, 1, 10),\r | |
627 | d2 = new Date(2010, 0, 1, 12);\r | |
628 | \r | |
629 | expect(match('eq', d1, d2)).toBe(false);\r | |
630 | });\r | |
631 | });\r | |
632 | \r | |
633 | describe("with convert", function() {\r | |
634 | it("should call the convert fn", function() {\r | |
635 | var d1 = new Date(2010, 0, 1, 12),\r | |
636 | d2 = new Date(2010, 0, 1, 10),\r | |
637 | convert = function(v) {\r | |
638 | return Ext.Date.clearTime(v, true).getTime();\r | |
639 | };\r | |
640 | \r | |
641 | expect(match('eq', d1, d2, {convert: convert})).toBe(true);\r | |
642 | });\r | |
643 | });\r | |
644 | \r | |
645 | describe("value coercion", function() {\r | |
646 | it("should coerce the candidate value based on the value", function() {\r | |
647 | expect(match('eq', '10', 10)).toBe(true);\r | |
648 | });\r | |
649 | });\r | |
650 | });\r | |
651 | \r | |
652 | describe("===", function() {\r | |
653 | describe("numbers", function() {\r | |
654 | it("should not match when the candidate is smaller than the value", function() {\r | |
655 | expect(match('===', 7, 10)).toBe(false);\r | |
656 | });\r | |
657 | \r | |
658 | it("should match when the candidate is equal to the value", function() {\r | |
659 | expect(match('===', 10, 10)).toBe(true);\r | |
660 | });\r | |
661 | \r | |
662 | it("should not match when the candidate is larger than the value", function() {\r | |
663 | expect(match('===', 100, 10)).toBe(false);\r | |
664 | });\r | |
665 | });\r | |
666 | \r | |
667 | describe("strings", function() {\r | |
668 | it("should not match when the candidate is smaller than the value", function() {\r | |
669 | expect(match('===', 'a', 'f')).toBe(false);\r | |
670 | });\r | |
671 | \r | |
672 | it("should match when the candidate is equal to the value", function() {\r | |
673 | expect(match('===', 'j', 'j')).toBe(true);\r | |
674 | });\r | |
675 | \r | |
676 | it("should not match when the candidate is larger than the value", function() {\r | |
677 | expect(match('===', 'z', 'q')).toBe(false);\r | |
678 | });\r | |
679 | });\r | |
680 | \r | |
681 | describe("dates", function() {\r | |
682 | it("should not match when the candidate is smaller than the value", function() {\r | |
683 | var d1 = new Date(2008, 0, 1),\r | |
684 | d2 = new Date(2010, 0, 1);\r | |
685 | \r | |
686 | expect(match('===', d1, d2)).toBe(false);\r | |
687 | });\r | |
688 | \r | |
689 | it("should match when the candidate is equal to the value", function() {\r | |
690 | var d1 = new Date(2010, 0, 1),\r | |
691 | d2 = new Date(2010, 0, 1);\r | |
692 | \r | |
693 | expect(match('===', d1, d2)).toBe(true);\r | |
694 | });\r | |
695 | \r | |
696 | it("should not match when the candidate is larger than the value", function() {\r | |
697 | var d1 = new Date(2012, 0, 1),\r | |
698 | d2 = new Date(2010, 0, 1);\r | |
699 | \r | |
700 | expect(match('===', d1, d2)).toBe(false);\r | |
701 | });\r | |
702 | \r | |
703 | it("should match on the full date", function() {\r | |
704 | var d1 = new Date(2010, 0, 1, 10),\r | |
705 | d2 = new Date(2010, 0, 1, 12);\r | |
706 | \r | |
707 | expect(match('===', d1, d2)).toBe(false);\r | |
708 | });\r | |
709 | });\r | |
710 | \r | |
711 | describe("with convert", function() {\r | |
712 | it("should call the convert fn", function() {\r | |
713 | var d1 = new Date(2010, 0, 1, 12),\r | |
714 | d2 = new Date(2010, 0, 1, 10),\r | |
715 | convert = function(v) {\r | |
716 | return Ext.Date.clearTime(v, true).getTime();\r | |
717 | };\r | |
718 | \r | |
719 | expect(match('===', d1, d2, {convert: convert})).toBe(true);\r | |
720 | });\r | |
721 | });\r | |
722 | \r | |
723 | describe("value coercion", function() {\r | |
724 | it("should not coerce the candidate value based on the value", function() {\r | |
725 | expect(match('===', '10', 10)).toBe(false);\r | |
726 | });\r | |
727 | });\r | |
728 | });\r | |
729 | \r | |
730 | describe(">", function() {\r | |
731 | describe("numbers", function() {\r | |
732 | it("should not match when the candidate is smaller than the value", function() {\r | |
733 | expect(match('>', 7, 10)).toBe(false);\r | |
734 | });\r | |
735 | \r | |
736 | it("should not match when the candidate is equal to the value", function() {\r | |
737 | expect(match('>', 10, 10)).toBe(false);\r | |
738 | });\r | |
739 | \r | |
740 | it("should match when the candidate is larger than the value", function() {\r | |
741 | expect(match('>', 100, 10)).toBe(true);\r | |
742 | });\r | |
743 | });\r | |
744 | \r | |
745 | describe("strings", function() {\r | |
746 | it("should not match when the candidate is smaller than the value", function() {\r | |
747 | expect(match('>', 'a', 'f')).toBe(false);\r | |
748 | });\r | |
749 | \r | |
750 | it("should not match when the candidate is equal to the value", function() {\r | |
751 | expect(match('>', 'j', 'j')).toBe(false);\r | |
752 | });\r | |
753 | \r | |
754 | it("should match when the candidate is larger than the value", function() {\r | |
755 | expect(match('>', 'z', 'q')).toBe(true);\r | |
756 | });\r | |
757 | });\r | |
758 | \r | |
759 | describe("dates", function() {\r | |
760 | it("should not match when the candidate is smaller than the value", function() {\r | |
761 | var d1 = new Date(2008, 0, 1),\r | |
762 | d2 = new Date(2010, 0, 1);\r | |
763 | \r | |
764 | expect(match('>', d1, d2)).toBe(false);\r | |
765 | });\r | |
766 | \r | |
767 | it("should not match when the candidate is equal to the value", function() {\r | |
768 | var d1 = new Date(2010, 0, 1),\r | |
769 | d2 = new Date(2010, 0, 1);\r | |
770 | \r | |
771 | expect(match('>', d1, d2)).toBe(false);\r | |
772 | });\r | |
773 | \r | |
774 | it("should match when the candidate is larger than the value", function() {\r | |
775 | var d1 = new Date(2012, 0, 1),\r | |
776 | d2 = new Date(2010, 0, 1);\r | |
777 | \r | |
778 | expect(match('>', d1, d2)).toBe(true);\r | |
779 | });\r | |
780 | \r | |
781 | it("should match on the full date", function() {\r | |
782 | var d1 = new Date(2010, 0, 1, 10),\r | |
783 | d2 = new Date(2010, 0, 1, 12);\r | |
784 | \r | |
785 | expect(match('>', d1, d2)).toBe(false);\r | |
786 | });\r | |
787 | });\r | |
788 | \r | |
789 | describe("with convert", function() {\r | |
790 | it("should call the convert fn", function() {\r | |
791 | var d1 = new Date(2010, 0, 1, 12),\r | |
792 | d2 = new Date(2010, 0, 1, 10),\r | |
793 | convert = function(v) {\r | |
794 | return Ext.Date.clearTime(v, true).getTime();\r | |
795 | };\r | |
796 | \r | |
797 | expect(match('>', d1, d2, {convert: convert})).toBe(false);\r | |
798 | });\r | |
799 | });\r | |
800 | \r | |
801 | describe("value coercion", function() {\r | |
802 | it("should coerce the candidate value based on the value", function() {\r | |
803 | expect(match('>', '10', 7)).toBe(true);\r | |
804 | });\r | |
805 | });\r | |
806 | });\r | |
807 | \r | |
808 | describe("gt", function() {\r | |
809 | describe("numbers", function() {\r | |
810 | it("should not match when the candidate is smaller than the value", function() {\r | |
811 | expect(match('gt', 7, 10)).toBe(false);\r | |
812 | });\r | |
813 | \r | |
814 | it("should not match when the candidate is equal to the value", function() {\r | |
815 | expect(match('gt', 10, 10)).toBe(false);\r | |
816 | });\r | |
817 | \r | |
818 | it("should match when the candidate is larger than the value", function() {\r | |
819 | expect(match('gt', 100, 10)).toBe(true);\r | |
820 | });\r | |
821 | });\r | |
822 | \r | |
823 | describe("strings", function() {\r | |
824 | it("should not match when the candidate is smaller than the value", function() {\r | |
825 | expect(match('gt', 'a', 'f')).toBe(false);\r | |
826 | });\r | |
827 | \r | |
828 | it("should not match when the candidate is equal to the value", function() {\r | |
829 | expect(match('gt', 'j', 'j')).toBe(false);\r | |
830 | });\r | |
831 | \r | |
832 | it("should match when the candidate is larger than the value", function() {\r | |
833 | expect(match('gt', 'z', 'q')).toBe(true);\r | |
834 | });\r | |
835 | });\r | |
836 | \r | |
837 | describe("dates", function() {\r | |
838 | it("should not match when the candidate is smaller than the value", function() {\r | |
839 | var d1 = new Date(2008, 0, 1),\r | |
840 | d2 = new Date(2010, 0, 1);\r | |
841 | \r | |
842 | expect(match('gt', d1, d2)).toBe(false);\r | |
843 | });\r | |
844 | \r | |
845 | it("should not match when the candidate is equal to the value", function() {\r | |
846 | var d1 = new Date(2010, 0, 1),\r | |
847 | d2 = new Date(2010, 0, 1);\r | |
848 | \r | |
849 | expect(match('gt', d1, d2)).toBe(false);\r | |
850 | });\r | |
851 | \r | |
852 | it("should match when the candidate is larger than the value", function() {\r | |
853 | var d1 = new Date(2012, 0, 1),\r | |
854 | d2 = new Date(2010, 0, 1);\r | |
855 | \r | |
856 | expect(match('gt', d1, d2)).toBe(true);\r | |
857 | });\r | |
858 | \r | |
859 | it("should match on the full date", function() {\r | |
860 | var d1 = new Date(2010, 0, 1, 10),\r | |
861 | d2 = new Date(2010, 0, 1, 12);\r | |
862 | \r | |
863 | expect(match('gt', d1, d2)).toBe(false);\r | |
864 | });\r | |
865 | });\r | |
866 | \r | |
867 | describe("with convert", function() {\r | |
868 | it("should call the convert fn", function() {\r | |
869 | var d1 = new Date(2010, 0, 1, 12),\r | |
870 | d2 = new Date(2010, 0, 1, 10),\r | |
871 | convert = function(v) {\r | |
872 | return Ext.Date.clearTime(v, true).getTime();\r | |
873 | };\r | |
874 | \r | |
875 | expect(match('gt', d1, d2, {convert: convert})).toBe(false);\r | |
876 | });\r | |
877 | });\r | |
878 | \r | |
879 | describe("value coercion", function() {\r | |
880 | it("should coerce the candidate value based on the value", function() {\r | |
881 | expect(match('gt', '10', 7)).toBe(true);\r | |
882 | });\r | |
883 | });\r | |
884 | });\r | |
885 | \r | |
886 | describe(">=", function() {\r | |
887 | describe("numbers", function() {\r | |
888 | it("should not match when the candidate is smaller than the value", function() {\r | |
889 | expect(match('>=', 7, 10)).toBe(false);\r | |
890 | });\r | |
891 | \r | |
892 | it("should match when the candidate is equal to the value", function() {\r | |
893 | expect(match('>=', 10, 10)).toBe(true);\r | |
894 | });\r | |
895 | \r | |
896 | it("should match when the candidate is larger than the value", function() {\r | |
897 | expect(match('>=', 100, 10)).toBe(true);\r | |
898 | });\r | |
899 | });\r | |
900 | \r | |
901 | describe("strings", function() {\r | |
902 | it("should not match when the candidate is smaller than the value", function() {\r | |
903 | expect(match('>=', 'a', 'f')).toBe(false);\r | |
904 | });\r | |
905 | \r | |
906 | it("should match when the candidate is equal to the value", function() {\r | |
907 | expect(match('>=', 'j', 'j')).toBe(true);\r | |
908 | });\r | |
909 | \r | |
910 | it("should match when the candidate is larger than the value", function() {\r | |
911 | expect(match('>=', 'z', 'q')).toBe(true);\r | |
912 | });\r | |
913 | });\r | |
914 | \r | |
915 | describe("dates", function() {\r | |
916 | it("should not match when the candidate is smaller than the value", function() {\r | |
917 | var d1 = new Date(2008, 0, 1),\r | |
918 | d2 = new Date(2010, 0, 1);\r | |
919 | \r | |
920 | expect(match('>=', d1, d2)).toBe(false);\r | |
921 | });\r | |
922 | \r | |
923 | it("should match when the candidate is equal to the value", function() {\r | |
924 | var d1 = new Date(2010, 0, 1),\r | |
925 | d2 = new Date(2010, 0, 1);\r | |
926 | \r | |
927 | expect(match('>=', d1, d2)).toBe(true);\r | |
928 | });\r | |
929 | \r | |
930 | it("should match when the candidate is larger than the value", function() {\r | |
931 | var d1 = new Date(2012, 0, 1),\r | |
932 | d2 = new Date(2010, 0, 1);\r | |
933 | \r | |
934 | expect(match('>=', d1, d2)).toBe(true);\r | |
935 | });\r | |
936 | \r | |
937 | it("should match on the full date", function() {\r | |
938 | var d1 = new Date(2010, 0, 1, 10),\r | |
939 | d2 = new Date(2010, 0, 1, 12);\r | |
940 | \r | |
941 | expect(match('>=', d1, d2)).toBe(false);\r | |
942 | });\r | |
943 | });\r | |
944 | \r | |
945 | describe("with convert", function() {\r | |
946 | it("should call the convert fn", function() {\r | |
947 | var d1 = new Date(2010, 0, 1, 12),\r | |
948 | d2 = new Date(2010, 0, 1, 10),\r | |
949 | convert = function(v) {\r | |
950 | return Ext.Date.clearTime(v, true).getTime();\r | |
951 | };\r | |
952 | \r | |
953 | expect(match('>=', d1, d2, {convert: convert})).toBe(true);\r | |
954 | });\r | |
955 | });\r | |
956 | \r | |
957 | describe("value coercion", function() {\r | |
958 | it("should coerce the candidate value based on the value", function() {\r | |
959 | expect(match('>=', '10', 7)).toBe(true);\r | |
960 | });\r | |
961 | });\r | |
962 | });\r | |
963 | \r | |
964 | describe("ge", function() {\r | |
965 | describe("numbers", function() {\r | |
966 | it("should not match when the candidate is smaller than the value", function() {\r | |
967 | expect(match('ge', 7, 10)).toBe(false);\r | |
968 | });\r | |
969 | \r | |
970 | it("should match when the candidate is equal to the value", function() {\r | |
971 | expect(match('ge', 10, 10)).toBe(true);\r | |
972 | });\r | |
973 | \r | |
974 | it("should match when the candidate is larger than the value", function() {\r | |
975 | expect(match('ge', 100, 10)).toBe(true);\r | |
976 | });\r | |
977 | });\r | |
978 | \r | |
979 | describe("strings", function() {\r | |
980 | it("should not match when the candidate is smaller than the value", function() {\r | |
981 | expect(match('ge', 'a', 'f')).toBe(false);\r | |
982 | });\r | |
983 | \r | |
984 | it("should match when the candidate is equal to the value", function() {\r | |
985 | expect(match('ge', 'j', 'j')).toBe(true);\r | |
986 | });\r | |
987 | \r | |
988 | it("should match when the candidate is larger than the value", function() {\r | |
989 | expect(match('ge', 'z', 'q')).toBe(true);\r | |
990 | });\r | |
991 | });\r | |
992 | \r | |
993 | describe("dates", function() {\r | |
994 | it("should not match when the candidate is smaller than the value", function() {\r | |
995 | var d1 = new Date(2008, 0, 1),\r | |
996 | d2 = new Date(2010, 0, 1);\r | |
997 | \r | |
998 | expect(match('ge', d1, d2)).toBe(false);\r | |
999 | });\r | |
1000 | \r | |
1001 | it("should match when the candidate is equal to the value", function() {\r | |
1002 | var d1 = new Date(2010, 0, 1),\r | |
1003 | d2 = new Date(2010, 0, 1);\r | |
1004 | \r | |
1005 | expect(match('ge', d1, d2)).toBe(true);\r | |
1006 | });\r | |
1007 | \r | |
1008 | it("should match when the candidate is larger than the value", function() {\r | |
1009 | var d1 = new Date(2012, 0, 1),\r | |
1010 | d2 = new Date(2010, 0, 1);\r | |
1011 | \r | |
1012 | expect(match('ge', d1, d2)).toBe(true);\r | |
1013 | });\r | |
1014 | \r | |
1015 | it("should match on the full date", function() {\r | |
1016 | var d1 = new Date(2010, 0, 1, 10),\r | |
1017 | d2 = new Date(2010, 0, 1, 12);\r | |
1018 | \r | |
1019 | expect(match('ge', d1, d2)).toBe(false);\r | |
1020 | });\r | |
1021 | });\r | |
1022 | \r | |
1023 | describe("with convert", function() {\r | |
1024 | it("should call the convert fn", function() {\r | |
1025 | var d1 = new Date(2010, 0, 1, 12),\r | |
1026 | d2 = new Date(2010, 0, 1, 10),\r | |
1027 | convert = function(v) {\r | |
1028 | return Ext.Date.clearTime(v, true).getTime();\r | |
1029 | };\r | |
1030 | \r | |
1031 | expect(match('ge', d1, d2, {convert: convert})).toBe(true);\r | |
1032 | });\r | |
1033 | });\r | |
1034 | \r | |
1035 | describe("value coercion", function() {\r | |
1036 | it("should coerce the candidate value based on the value", function() {\r | |
1037 | expect(match('ge', '10', 7)).toBe(true);\r | |
1038 | });\r | |
1039 | });\r | |
1040 | });\r | |
1041 | \r | |
1042 | describe("!=", function() {\r | |
1043 | describe("numbers", function() {\r | |
1044 | it("should match when the candidate is smaller than the value", function() {\r | |
1045 | expect(match('!=', 7, 10)).toBe(true);\r | |
1046 | });\r | |
1047 | \r | |
1048 | it("should not match when the candidate is equal to the value", function() {\r | |
1049 | expect(match('!=', 10, 10)).toBe(false);\r | |
1050 | });\r | |
1051 | \r | |
1052 | it("should match when the candidate is larger than the value", function() {\r | |
1053 | expect(match('!=', 100, 10)).toBe(true);\r | |
1054 | });\r | |
1055 | });\r | |
1056 | \r | |
1057 | describe("strings", function() {\r | |
1058 | it("should match when the candidate is smaller than the value", function() {\r | |
1059 | expect(match('!=', 'a', 'f')).toBe(true);\r | |
1060 | });\r | |
1061 | \r | |
1062 | it("should not match when the candidate is equal to the value", function() {\r | |
1063 | expect(match('!=', 'j', 'j')).toBe(false);\r | |
1064 | });\r | |
1065 | \r | |
1066 | it("should match when the candidate is larger than the value", function() {\r | |
1067 | expect(match('!=', 'z', 'q')).toBe(true);\r | |
1068 | });\r | |
1069 | });\r | |
1070 | \r | |
1071 | describe("dates", function() {\r | |
1072 | it("should match when the candidate is smaller than the value", function() {\r | |
1073 | var d1 = new Date(2008, 0, 1),\r | |
1074 | d2 = new Date(2010, 0, 1);\r | |
1075 | \r | |
1076 | expect(match('!=', d1, d2)).toBe(true);\r | |
1077 | });\r | |
1078 | \r | |
1079 | it("should not match when the candidate is equal to the value", function() {\r | |
1080 | var d1 = new Date(2010, 0, 1),\r | |
1081 | d2 = new Date(2010, 0, 1);\r | |
1082 | \r | |
1083 | expect(match('!=', d1, d2)).toBe(false);\r | |
1084 | });\r | |
1085 | \r | |
1086 | it("should match when the candidate is larger than the value", function() {\r | |
1087 | var d1 = new Date(2012, 0, 1),\r | |
1088 | d2 = new Date(2010, 0, 1);\r | |
1089 | \r | |
1090 | expect(match('!=', d1, d2)).toBe(true);\r | |
1091 | });\r | |
1092 | \r | |
1093 | it("should match on the full date", function() {\r | |
1094 | var d1 = new Date(2010, 0, 1, 10),\r | |
1095 | d2 = new Date(2010, 0, 1, 12);\r | |
1096 | \r | |
1097 | expect(match('!=', d1, d2)).toBe(true);\r | |
1098 | });\r | |
1099 | });\r | |
1100 | \r | |
1101 | describe("with convert", function() {\r | |
1102 | it("should call the convert fn", function() {\r | |
1103 | var d1 = new Date(2010, 0, 1, 12),\r | |
1104 | d2 = new Date(2010, 0, 1, 10),\r | |
1105 | convert = function(v) {\r | |
1106 | return Ext.Date.clearTime(v, true).getTime();\r | |
1107 | };\r | |
1108 | \r | |
1109 | expect(match('!=', d1, d2, {convert: convert})).toBe(false);\r | |
1110 | });\r | |
1111 | });\r | |
1112 | \r | |
1113 | describe("value coercion", function() {\r | |
1114 | it("should coerce the candidate value based on the value", function() {\r | |
1115 | expect(match('!=', '10', 10)).toBe(false);\r | |
1116 | });\r | |
1117 | });\r | |
1118 | });\r | |
1119 | \r | |
1120 | describe("ne", function() {\r | |
1121 | describe("numbers", function() {\r | |
1122 | it("should match when the candidate is smaller than the value", function() {\r | |
1123 | expect(match('ne', 7, 10)).toBe(true);\r | |
1124 | });\r | |
1125 | \r | |
1126 | it("should not match when the candidate is equal to the value", function() {\r | |
1127 | expect(match('ne', 10, 10)).toBe(false);\r | |
1128 | });\r | |
1129 | \r | |
1130 | it("should match when the candidate is larger than the value", function() {\r | |
1131 | expect(match('ne', 100, 10)).toBe(true);\r | |
1132 | });\r | |
1133 | });\r | |
1134 | \r | |
1135 | describe("strings", function() {\r | |
1136 | it("should match when the candidate is smaller than the value", function() {\r | |
1137 | expect(match('ne', 'a', 'f')).toBe(true);\r | |
1138 | });\r | |
1139 | \r | |
1140 | it("should not match when the candidate is equal to the value", function() {\r | |
1141 | expect(match('ne', 'j', 'j')).toBe(false);\r | |
1142 | });\r | |
1143 | \r | |
1144 | it("should match when the candidate is larger than the value", function() {\r | |
1145 | expect(match('ne', 'z', 'q')).toBe(true);\r | |
1146 | });\r | |
1147 | });\r | |
1148 | \r | |
1149 | describe("dates", function() {\r | |
1150 | it("should match when the candidate is smaller than the value", function() {\r | |
1151 | var d1 = new Date(2008, 0, 1),\r | |
1152 | d2 = new Date(2010, 0, 1);\r | |
1153 | \r | |
1154 | expect(match('ne', d1, d2)).toBe(true);\r | |
1155 | });\r | |
1156 | \r | |
1157 | it("should not match when the candidate is equal to the value", function() {\r | |
1158 | var d1 = new Date(2010, 0, 1),\r | |
1159 | d2 = new Date(2010, 0, 1);\r | |
1160 | \r | |
1161 | expect(match('ne', d1, d2)).toBe(false);\r | |
1162 | });\r | |
1163 | \r | |
1164 | it("should match when the candidate is larger than the value", function() {\r | |
1165 | var d1 = new Date(2012, 0, 1),\r | |
1166 | d2 = new Date(2010, 0, 1);\r | |
1167 | \r | |
1168 | expect(match('ne', d1, d2)).toBe(true);\r | |
1169 | });\r | |
1170 | \r | |
1171 | it("should match on the full date", function() {\r | |
1172 | var d1 = new Date(2010, 0, 1, 10),\r | |
1173 | d2 = new Date(2010, 0, 1, 12);\r | |
1174 | \r | |
1175 | expect(match('ne', d1, d2)).toBe(true);\r | |
1176 | });\r | |
1177 | });\r | |
1178 | \r | |
1179 | describe("with convert", function() {\r | |
1180 | it("should call the convert fn", function() {\r | |
1181 | var d1 = new Date(2010, 0, 1, 12),\r | |
1182 | d2 = new Date(2010, 0, 1, 10),\r | |
1183 | convert = function(v) {\r | |
1184 | return Ext.Date.clearTime(v, true).getTime();\r | |
1185 | };\r | |
1186 | \r | |
1187 | expect(match('ne', d1, d2, {convert: convert})).toBe(false);\r | |
1188 | });\r | |
1189 | });\r | |
1190 | \r | |
1191 | describe("value coercion", function() {\r | |
1192 | it("should coerce the candidate value based on the value", function() {\r | |
1193 | expect(match('ne', '10', 10)).toBe(false);\r | |
1194 | });\r | |
1195 | });\r | |
1196 | });\r | |
1197 | \r | |
1198 | describe("!==", function() {\r | |
1199 | describe("numbers", function() {\r | |
1200 | it("should match when the candidate is smaller than the value", function() {\r | |
1201 | expect(match('!==', 7, 10)).toBe(true);\r | |
1202 | });\r | |
1203 | \r | |
1204 | it("should not match when the candidate is equal to the value", function() {\r | |
1205 | expect(match('!==', 10, 10)).toBe(false);\r | |
1206 | });\r | |
1207 | \r | |
1208 | it("should match when the candidate is larger than the value", function() {\r | |
1209 | expect(match('!==', 100, 10)).toBe(true);\r | |
1210 | });\r | |
1211 | });\r | |
1212 | \r | |
1213 | describe("strings", function() {\r | |
1214 | it("should match when the candidate is smaller than the value", function() {\r | |
1215 | expect(match('!==', 'a', 'f')).toBe(true);\r | |
1216 | });\r | |
1217 | \r | |
1218 | it("should not match when the candidate is equal to the value", function() {\r | |
1219 | expect(match('!==', 'j', 'j')).toBe(false);\r | |
1220 | });\r | |
1221 | \r | |
1222 | it("should match when the candidate is larger than the value", function() {\r | |
1223 | expect(match('!==', 'z', 'q')).toBe(true);\r | |
1224 | });\r | |
1225 | });\r | |
1226 | \r | |
1227 | describe("dates", function() {\r | |
1228 | it("should match when the candidate is smaller than the value", function() {\r | |
1229 | var d1 = new Date(2008, 0, 1),\r | |
1230 | d2 = new Date(2010, 0, 1);\r | |
1231 | \r | |
1232 | expect(match('!==', d1, d2)).toBe(true);\r | |
1233 | });\r | |
1234 | \r | |
1235 | it("should not match when the candidate is equal to the value", function() {\r | |
1236 | var d1 = new Date(2010, 0, 1),\r | |
1237 | d2 = new Date(2010, 0, 1);\r | |
1238 | \r | |
1239 | expect(match('!==', d1, d2)).toBe(false);\r | |
1240 | });\r | |
1241 | \r | |
1242 | it("should match when the candidate is larger than the value", function() {\r | |
1243 | var d1 = new Date(2012, 0, 1),\r | |
1244 | d2 = new Date(2010, 0, 1);\r | |
1245 | \r | |
1246 | expect(match('!==', d1, d2)).toBe(true);\r | |
1247 | });\r | |
1248 | \r | |
1249 | it("should match on the full date", function() {\r | |
1250 | var d1 = new Date(2010, 0, 1, 10),\r | |
1251 | d2 = new Date(2010, 0, 1, 12);\r | |
1252 | \r | |
1253 | expect(match('!==', d1, d2)).toBe(true);\r | |
1254 | });\r | |
1255 | });\r | |
1256 | \r | |
1257 | describe("with convert", function() {\r | |
1258 | it("should call the convert fn", function() {\r | |
1259 | var d1 = new Date(2010, 0, 1, 12),\r | |
1260 | d2 = new Date(2010, 0, 1, 10),\r | |
1261 | convert = function(v) {\r | |
1262 | return Ext.Date.clearTime(v, true).getTime();\r | |
1263 | };\r | |
1264 | \r | |
1265 | expect(match('!==', d1, d2, {convert: convert})).toBe(false);\r | |
1266 | });\r | |
1267 | });\r | |
1268 | \r | |
1269 | describe("value coercion", function() {\r | |
1270 | it("should not coerce the candidate value based on the value", function() {\r | |
1271 | expect(match('!==', '10', 10)).toBe(true);\r | |
1272 | });\r | |
1273 | });\r | |
1274 | });\r | |
1275 | \r | |
1276 | describe("in", function() {\r | |
1277 | it("should match when the candidate exists in the value", function() {\r | |
1278 | expect(match('in', 2, [1, 2, 3, 4])).toBe(true);\r | |
1279 | });\r | |
1280 | \r | |
1281 | it("should not match when the candidate does not exist in the value", function() {\r | |
1282 | expect(match('in', 5, [1, 2, 3, 4])).toBe(false);\r | |
1283 | });\r | |
1284 | \r | |
1285 | it("should call the convert fn", function() {\r | |
1286 | var convert = function(v) {\r | |
1287 | return v + 1;\r | |
1288 | }\r | |
1289 | expect(match('in', 0, [1, 2, 3, 4], {convert: convert})).toBe(true);\r | |
1290 | });\r | |
1291 | });\r | |
1292 | \r | |
1293 | describe("notin", function() {\r | |
1294 | it("should not match when the candidate exists in the value", function() {\r | |
1295 | expect(match('notin', 2, [1, 2, 3, 4])).toBe(false);\r | |
1296 | });\r | |
1297 | \r | |
1298 | it("should match when the candidate does not exist in the value", function() {\r | |
1299 | expect(match('notin', 5, [1, 2, 3, 4])).toBe(true);\r | |
1300 | });\r | |
1301 | \r | |
1302 | it("should call the convert fn", function() {\r | |
1303 | var convert = function(v) {\r | |
1304 | return v + 1;\r | |
1305 | }\r | |
1306 | expect(match('notin', 0, [1, 2, 3, 4], {convert: convert})).toBe(false);\r | |
1307 | });\r | |
1308 | });\r | |
1309 | \r | |
1310 | describe("like", function() {\r | |
1311 | it("should match when the candidate matches the value", function() {\r | |
1312 | expect(match('like', 'foo', 'foo')).toBe(true);\r | |
1313 | });\r | |
1314 | \r | |
1315 | it("should match when the candidate is at the start of the value ", function() {\r | |
1316 | expect(match('like', 'food', 'foo')).toBe(true);\r | |
1317 | });\r | |
1318 | \r | |
1319 | it("should match when the candidate is at the end of the value ", function() {\r | |
1320 | expect(match('like', 'food', 'ood')).toBe(true);\r | |
1321 | });\r | |
1322 | \r | |
1323 | it("should match when the candidate is in the middle of the value ", function() {\r | |
1324 | expect(match('like', 'foobar', 'oob')).toBe(true);\r | |
1325 | });\r | |
1326 | \r | |
1327 | it("should not match when the candidate does not exist in the value", function() {\r | |
1328 | expect(match('like', 'foo', 'bar')).toBe(false);\r | |
1329 | });\r | |
1330 | });\r | |
1331 | });\r | |
1332 | });\r |