Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(IdleTimer): Preventing the IdleTimer logic to start its timer if timeout is 0. #3825

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/react/src/components/SuiteHeader/util/IdleTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class IdleTimer {
}

startIdleUserDetectionInterval() {
if (this.TIMEOUT === 0) {
// No reason to do any of this if they have not defined a timeout
return;
}
// Push the cookie forward by this.TIMEOUT
this.updateUserInactivityTimeoutCookie();
// Reset the countdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ describe('IdleTimer', () => {
expect(clearInterval).not.toHaveBeenCalled();
expect(setInterval).toHaveBeenCalledTimes(1);
});
it('does not start the timer when timeout is zero', () => {
timer.cleanUp();
// The creation and cleanup of the first timer should have triggered setInterval and clearInterval once
expect(clearInterval).toHaveBeenCalled();
expect(setInterval).toHaveBeenCalledTimes(1);
// After the creation of the other timer with timeout set to 0, no new call to setInterval should happen
timer = new IdleTimer({ timeout: 0 });
expect(setInterval).toHaveBeenCalledTimes(1);
});
it('does nothing on an interval cycle if timeout has not been reached yet', () => {
// Simulate a timestamp cookie that is slightly in the future
Object.defineProperty(window.document, 'cookie', {
Expand Down
Loading