Skip to content

Commit e23233d

Browse files
markmaynardgrbsk
authored andcommitted
fix(idle): check expiry on timeout doCountdown
[On behalf of Lexmark International, Inc] Check expiry in docountdown to see if it has changed and if so interrupt. For multi-tab support.
1 parent 753afad commit e23233d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

modules/core/src/idle.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff 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

modules/core/src/idle.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)