test(search): pin the clock in the age-chip assertion

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.
This commit is contained in:
Dave 2026-10-15 16:02:57 +02:00
parent d55e54680b
commit 1a03a1422a

View file

@ -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(