@@ -383,6 +383,64 @@ describe('toastr', function() {
383
383
animationFlush ( ) ;
384
384
expect ( toastr . active ( ) ) . toBe ( 0 ) ;
385
385
} ) ;
386
+
387
+ it ( 'allows to restart the timer, keeping the toast visible longer' , function ( ) {
388
+ toastrConfig . timeOut = 5000 ;
389
+ var toast = openToast ( 'success' , 'foo' ) ;
390
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
391
+ intervalFlush ( 2000 ) ;
392
+ toastr . refreshTimer ( toast ) ;
393
+ intervalFlush ( 3000 ) ;
394
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
395
+ intervalFlush ( 2000 ) ;
396
+ expect ( $document ) . toHaveToastOpen ( 0 ) ;
397
+ } ) ;
398
+
399
+ it ( 'allows to restart the timer with a new duration' , function ( ) {
400
+ toastrConfig . timeOut = 5000 ;
401
+ var toast = openToast ( 'success' , 'foo' ) ;
402
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
403
+ intervalFlush ( 2000 ) ;
404
+ toastr . refreshTimer ( toast , 10000 ) ;
405
+ intervalFlush ( 5000 ) ;
406
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
407
+ intervalFlush ( 5000 ) ;
408
+ expect ( $document ) . toHaveToastOpen ( 0 ) ;
409
+ } ) ;
410
+
411
+ it ( 'ignores requests to restart the timer for manually-closed toasts' , function ( ) {
412
+ toastrConfig . timeOut = 5000 ;
413
+ var toast = openToast ( 'success' , 'foo' ) ;
414
+ spyOn ( toast . scope , 'refreshTimer' ) ;
415
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
416
+ intervalFlush ( 1000 ) ;
417
+ toastr . clear ( toast ) ;
418
+ intervalFlush ( 1000 ) ;
419
+ toastr . refreshTimer ( toast ) ;
420
+ expect ( toast . scope . refreshTimer ) . not . toHaveBeenCalled ( ) ;
421
+ } ) ;
422
+
423
+ it ( 'ignores requests to restart the timer for recently-expired toasts' , function ( ) {
424
+ toastrConfig . timeOut = 5000 ;
425
+ var toast = openToast ( 'success' , 'foo' ) ;
426
+ spyOn ( toast . scope , 'refreshTimer' ) ;
427
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
428
+ intervalFlush ( 5000 ) ;
429
+ toastr . refreshTimer ( toast ) ;
430
+ expect ( toast . scope . refreshTimer ) . not . toHaveBeenCalled ( ) ;
431
+ } ) ;
432
+
433
+ it ( 'ignores requests to restart the timer for old toasts' , function ( ) {
434
+ toastrConfig . timeOut = 5000 ;
435
+ var toast = openToast ( 'success' , 'foo' ) ;
436
+ spyOn ( toast . scope , 'refreshTimer' ) ;
437
+ expect ( $document ) . toHaveToastOpen ( 1 ) ;
438
+ intervalFlush ( 60000 ) ;
439
+ expect ( $document ) . toHaveToastOpen ( 0 ) ;
440
+ toastr . refreshTimer ( toast ) ;
441
+ expect ( toast . scope . refreshTimer ) . not . toHaveBeenCalled ( ) ;
442
+ } ) ;
443
+
386
444
} ) ;
387
445
388
446
describe ( 'container' , function ( ) {
0 commit comments