File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,27 @@ describe('core/Idle', () => {
404404 instance . stop ( ) ;
405405 } ) ) ;
406406
407+ it ( 'emits an onInterrupt event when the countdown ticks and expiry last has been updated' , fakeAsync ( ( ) => {
408+ spyOn ( instance . onInterrupt , 'emit' ) . and . callThrough ( ) ;
409+
410+ instance . setTimeout ( 3 ) ;
411+ expiry . mockNow = new Date ( ) ;
412+ instance . watch ( ) ;
413+
414+ expiry . mockNow = new Date ( expiry . now ( ) . getTime ( ) + instance . getIdle ( ) * 1000 ) ;
415+ tick ( 3000 ) ;
416+ expect ( instance . isIdling ( ) ) . toBe ( true ) ;
417+
418+ tick ( 1000 ) ; // going once
419+ tick ( 1000 ) ; // going twice
420+ expiry . last ( new Date ( expiry . now ( ) . getTime ( ) + 6000 ) ) ;
421+ tick ( 1000 ) ; // going thrice
422+
423+ expect ( instance . onInterrupt . emit ) . toHaveBeenCalledTimes ( 1 ) ;
424+
425+ instance . stop ( ) ;
426+ } ) ) ;
427+
407428 it ( 'does not emit an onTimeoutWarning when timeout is disabled' , fakeAsync ( ( ) => {
408429 spyOn ( instance . onTimeoutWarning , 'emit' ) . and . callThrough ( ) ;
409430
Original file line number Diff line number Diff line change @@ -343,6 +343,15 @@ export class Idle implements OnDestroy {
343343 }
344344
345345 private doCountdown ( ) : void {
346+ let timeout = ! this . timeoutVal ? 0 : this . timeoutVal ;
347+ let now : Date = this . expiry . now ( ) ;
348+ let diff : Number = this . expiry . last ( ) . getTime ( ) - now . getTime ( ) - ( timeout * 1000 ) ;
349+ if ( diff > 0 ) {
350+ this . safeClearInterval ( 'timeoutHandle' ) ;
351+ this . interrupt ( true ) ;
352+ return ;
353+ }
354+
346355 if ( ! this . idling ) {
347356 return ;
348357 }
You can’t perform that action at this time.
0 commit comments