From 4206e387fecd4631d07f4d8224ce0a813d7c8856 Mon Sep 17 00:00:00 2001 From: Jamey Huffnagle Date: Thu, 2 Jan 2025 12:46:59 -0500 Subject: [PATCH] fix(app): never idle the screen if the config value is the magic idle number --- app/src/local-resources/dom-utils/constants.ts | 1 + .../dom-utils/hooks/__tests__/useScreenIdle.test.ts | 10 ++++++++++ .../local-resources/dom-utils/hooks/useScreenIdle.ts | 10 +++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/local-resources/dom-utils/constants.ts b/app/src/local-resources/dom-utils/constants.ts index 1c7b0e2727d..88b913174da 100644 --- a/app/src/local-resources/dom-utils/constants.ts +++ b/app/src/local-resources/dom-utils/constants.ts @@ -1 +1,2 @@ +// See RQA-3813 and associated PR. export const SLEEP_NEVER_MS = 604800000 diff --git a/app/src/local-resources/dom-utils/hooks/__tests__/useScreenIdle.test.ts b/app/src/local-resources/dom-utils/hooks/__tests__/useScreenIdle.test.ts index 02a87fdb42a..e449b0cd82e 100644 --- a/app/src/local-resources/dom-utils/hooks/__tests__/useScreenIdle.test.ts +++ b/app/src/local-resources/dom-utils/hooks/__tests__/useScreenIdle.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest' import { renderHook } from '@testing-library/react' import { useScreenIdle } from '../useScreenIdle' +import { SLEEP_NEVER_MS } from '/app/local-resources/dom-utils' const MOCK_EVENTS: Array = [ 'mousedown', @@ -65,4 +66,13 @@ describe('useIdle', () => { expect(result.current).toBe(true) }, 3600001) }) + + it(`should always return false if the idle time is exactly ${SLEEP_NEVER_MS}`, () => { + const mockTime = SLEEP_NEVER_MS + const { result } = renderHook(() => useScreenIdle(mockTime, MOCK_OPTIONS)) + expect(result.current).toBe(false) + setTimeout(() => { + expect(result.current).toBe(false) + }, 604800001) + }) }) diff --git a/app/src/local-resources/dom-utils/hooks/useScreenIdle.ts b/app/src/local-resources/dom-utils/hooks/useScreenIdle.ts index 00932c55824..d36c6cfb326 100644 --- a/app/src/local-resources/dom-utils/hooks/useScreenIdle.ts +++ b/app/src/local-resources/dom-utils/hooks/useScreenIdle.ts @@ -1,4 +1,5 @@ import { useState, useEffect, useRef } from 'react' +import { SLEEP_NEVER_MS } from '/app/local-resources/dom-utils' const USER_EVENTS: Array = [ 'click', @@ -48,9 +49,12 @@ export function useScreenIdle( window.clearTimeout(idleTimer.current) } - idleTimer.current = window.setTimeout(() => { - setIdle(true) - }, idleTime) + // See RQA-3813 and associated PR. + if (idleTime !== SLEEP_NEVER_MS) { + idleTimer.current = window.setTimeout(() => { + setIdle(true) + }, idleTime) + } } events.forEach(event => {