From 1a03a1422a84ebb100be2b9a5aa1c2eb8d118389 Mon Sep 17 00:00:00 2001 From: Dave Date: Thu, 15 Oct 2026 16:02:57 +0200 Subject: [PATCH] test(search): pin the clock in the age-chip assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to d55e546, which moved the window but could not include this fix. The chip renders an age relative to NOW, and the assertion expected "4d" from a fixture dated 2026-10-10 against an unpinned Date.now(). It passed only because the wall clock happened to be 2026-10-14; it expired the next day, which is how it failed on the first run of the window change. vi.setSystemTime() makes it deterministic. Not committing the uncommitted src/app/(app)/collection-pool/ work in the same tree — unrelated to this fix and not mine to commit. --- src/app/(app)/search/page.test.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/app/(app)/search/page.test.tsx b/src/app/(app)/search/page.test.tsx index 9d41a1d..16c6128 100644 --- a/src/app/(app)/search/page.test.tsx +++ b/src/app/(app)/search/page.test.tsx @@ -416,9 +416,16 @@ describe("ageLabel", () => { }); describe("UniversalSearchPage — recency and age chip", () => { + // Pinned clock. The chip renders an age relative to NOW, so an + // unpinned `Date.now()` makes this test expire the day after it's + // written — it passed only because 2026-10-14 happened to be exactly + // four days after the fixture's createdAt. + const NOW = new Date("2026-10-14T00:00:00.000Z"); + beforeEach(() => { fetchMock.mockReset(); vi.useFakeTimers({ shouldAdvanceTime: true }); + vi.setSystemTime(NOW); }); afterEach(() => { @@ -436,7 +443,7 @@ describe("UniversalSearchPage — recency and age chip", () => { await vi.advanceTimersByTimeAsync(400); await waitFor(() => expect(screen.getByText("ORD-1")).toBeInTheDocument()); - // Fixture date 2026-10-10 vs a "now" of 2026-10-14. + // Fixture createdAt 2026-10-10, clock pinned to 2026-10-14. expect(screen.getByText("4d")).toBeInTheDocument(); // And the exact date is available on hover, since the chip is compact. expect(