From e19b0b22c3fc8a350c2711f270344610d92d458f Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 9 Nov 2026 15:13:47 +0000 Subject: [PATCH] test(ui-react): pin the clock in the digest slot-timer tests (#3801) Both tests recognise the card's slot timer by a delay over 60s, but the card arms it at the time to the next local 09:00/17:00 plus 30s of slack. In the last half minute before a slot it is a minute or less, so a run in that window captured no timer and failed. Pin Date.now to midday in those two tests and restore it with the setTimeout spy. Co-Authored-By: Claude Opus 5.5 --- packages/ui-react/tests/notification-zone.test.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/ui-react/tests/notification-zone.test.tsx b/packages/ui-react/tests/notification-zone.test.tsx index a23eae1332..dce568eb87 100644 --- a/packages/ui-react/tests/notification-zone.test.tsx +++ b/packages/ui-react/tests/notification-zone.test.tsx @@ -195,6 +195,12 @@ if (process.env[CHILD_MARKER]) { } as unknown as Parameters[0]; } const flush = () => act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); }); + // The slot-timer tests below recognise the card's slot timer by its long + // delay, so they pin the clock away from a slot: in the last half minute + // before a local 09:00 or 17:00 the timer is a minute or less, and a test + // reading the real clock then misses it (#3801). 12:00 in Athens. + const MIDDAY = Date.UTC(2026, 6, 12, 9, 0); + const pinClock = () => spyOn(Date, "now").mockReturnValue(MIDDAY); test("a read in flight when the card is dismissed cannot bring it back; a zone report re-arms the slot timer", async () => { let release: (() => void) | undefined; @@ -211,6 +217,7 @@ if (process.env[CHILD_MARKER]) { } as unknown as Parameters[0]; const timers: number[] = []; const real = globalThis.setTimeout; + const clock = pinClock(); const spy = spyOn(globalThis, "setTimeout").mockImplementation(((run: () => void, delay?: number) => { if ((delay ?? 0) > 60_000) { timers.push(delay!); return 0 as unknown as ReturnType; } return real(run, delay); @@ -230,7 +237,7 @@ if (process.env[CHILD_MARKER]) { await flush(); expect(view.container.textContent).not.toContain("Answer the Cyclops"); cleanup(); - } finally { spy.mockRestore(); } + } finally { spy.mockRestore(); clock.mockRestore(); } }); test("a dismissal on one root does not hide another root's older summary", async () => { @@ -283,6 +290,7 @@ if (process.env[CHILD_MARKER]) { const api = cardApi(() => response); const timers: Array<{ run: () => void; delay: number }> = []; const real = globalThis.setTimeout; + const clock = pinClock(); const spy = spyOn(globalThis, "setTimeout").mockImplementation(((run: () => void, delay?: number) => { if ((delay ?? 0) > 60_000) { timers.push({ run, delay: delay! }); return 0 as unknown as ReturnType; } return real(run, delay); @@ -304,7 +312,7 @@ if (process.env[CHILD_MARKER]) { await flush(); expect(view.container.textContent).toContain("Pass Scylla"); cleanup(); - } finally { spy.mockRestore(); } + } finally { spy.mockRestore(); clock.mockRestore(); } }); test("the digest card refetches after a first zone report and shows this client's new Actions", async () => {