1
+ function formatDate ( d ) {
2
+ if ( d . constructor == Number ) {
3
+ d = new Date ( d ) ;
4
+ }
5
+
6
+ return ( d . getYear ( ) + 1900 ) + '-' + ( d . getMonth ( ) + 1 ) + '-' + d . getDate ( ) ;
7
+ }
8
+
1
9
describe ( 'Validator' , function ( ) {
2
10
3
11
var testForm , testFormHtml ,
@@ -42,7 +50,7 @@ describe('Validator', function() {
42
50
43
51
} ) ;
44
52
45
- describe ( 'for the ACCEPTED rule' , function ( ) {
53
+ describe ( 'for the accepted rule' , function ( ) {
46
54
47
55
it ( 'should pass a checked checkbox' , function ( ) {
48
56
@@ -308,4 +316,107 @@ describe('Validator', function() {
308
316
309
317
} ) ;
310
318
319
+ describe ( 'for the after rule' , function ( ) {
320
+
321
+ it ( 'should pass for tomorrow\'s date' , function ( ) {
322
+
323
+ var elem = null ,
324
+ elemValid = null ,
325
+ formValid = null ,
326
+ now = new Date ;
327
+
328
+ textInput . data ( 'validations' , 'after:' + formatDate ( now ) ) ;
329
+ textInput . val ( formatDate ( now . setDate ( now . getDate ( ) + 1 ) ) ) ;
330
+
331
+ testForm . validator ( $ . extend ( {
332
+ callback : function ( e , v ) {
333
+ elem = e ;
334
+ elemValid = v ;
335
+ } ,
336
+ done : function ( v ) {
337
+ formValid = v ;
338
+ }
339
+ } , defaultOptions ) ) . submit ( ) ;
340
+
341
+ waitsFor ( function ( ) {
342
+ return elem !== null &&
343
+ formValid !== null ;
344
+ } ) ;
345
+
346
+ runs ( function ( ) {
347
+ expect ( $ ( elem ) . attr ( 'name' ) ) . toEqual ( textInput . attr ( 'name' ) ) ;
348
+ expect ( elemValid ) . toEqual ( true ) ;
349
+ expect ( formValid ) . toEqual ( true ) ;
350
+ } ) ;
351
+
352
+ } ) ;
353
+
354
+ it ( 'should fail for today\'s date' , function ( ) {
355
+
356
+ var elem = null ,
357
+ elemValid = null ,
358
+ formValid = null ,
359
+ now = new Date ;
360
+
361
+ textInput . data ( 'validations' , 'after:' + formatDate ( now ) ) ;
362
+ textInput . val ( formatDate ( now ) ) ;
363
+
364
+ testForm . validator ( $ . extend ( {
365
+ callback : function ( e , v ) {
366
+ elem = e ;
367
+ elemValid = v ;
368
+ } ,
369
+ done : function ( v ) {
370
+ formValid = v ;
371
+ }
372
+ } , defaultOptions ) ) . submit ( ) ;
373
+
374
+ waitsFor ( function ( ) {
375
+ return elem !== null &&
376
+ formValid !== null ;
377
+ } ) ;
378
+
379
+ runs ( function ( ) {
380
+ expect ( $ ( elem ) . attr ( 'name' ) ) . toEqual ( textInput . attr ( 'name' ) ) ;
381
+ expect ( elemValid ) . toEqual ( false ) ;
382
+ expect ( formValid ) . toEqual ( false ) ;
383
+ } ) ;
384
+
385
+ } ) ;
386
+
387
+ it ( 'should fail for yesterday\'s date' , function ( ) {
388
+
389
+ var elem = null ,
390
+ elemValid = null ,
391
+ formValid = null ,
392
+ now = new Date ;
393
+
394
+ textInput . data ( 'validations' , 'after:' + formatDate ( now ) ) ;
395
+ textInput . val ( formatDate ( now . setDate ( now . getDate ( ) - 1 ) ) ) ;
396
+
397
+ testForm . validator ( $ . extend ( {
398
+ callback : function ( e , v ) {
399
+ elem = e ;
400
+ elemValid = v ;
401
+ } ,
402
+ done : function ( v ) {
403
+ formValid = v ;
404
+ }
405
+ } , defaultOptions ) ) . submit ( ) ;
406
+
407
+ waitsFor ( function ( ) {
408
+ return elem !== null &&
409
+ formValid !== null ;
410
+ } ) ;
411
+
412
+ runs ( function ( ) {
413
+ expect ( $ ( elem ) . attr ( 'name' ) ) . toEqual ( textInput . attr ( 'name' ) ) ;
414
+ expect ( elemValid ) . toEqual ( false ) ;
415
+ expect ( formValid ) . toEqual ( false ) ;
416
+ } ) ;
417
+
418
+ } ) ;
419
+
420
+ } ) ;
421
+
311
422
} ) ;
0 commit comments