Skip to content

test(home): pin the calendar widget fixture clock to today's real date - #1945

Merged
h4yfans merged 1 commit into
mainfrom
calendar-widget-refresh-test
Sep 2, 2026
Merged

test(home): pin the calendar widget fixture clock to today's real date#1945
h4yfans merged 1 commit into
mainfrom
calendar-widget-refresh-test

Conversation

@h4yfans

@h4yfans h4yfans commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Unit & integration tests has been failing on main itself, and therefore on every open PR, at
calendar-widget-refresh.test.tsx > shows an event created elsewhere while the board is open
with expected "vi.fn()" to be called 1 times, but got 2 times. This unblocks the six other
open PRs in the #1934 batch, which all inherit the failure.

The second getRange call is real, but the test manufactures it. beforeEach faked the clock
onto 2026-08-31T09:30:00.000Z, the day the suite was written. use-today snapshots the local
date into module scope when it is imported and re-reads the wall clock for its first subscriber,
so on any later day that fake clock arrives as a midnight rollover. useToday changes value
during mount, todayCalendarRange moves with it, the useCalendarRange query key moves with
that, and react-query fetches the second day. A probe against the mock confirms the shape rather
than inferring it. The two calls carry different ranges, 2026-09-01 then 2026-08-31, the
first from the module snapshot and the second from the fake clock. The suite was green on
exactly one calendar day and has been red every day since.

So this is a test-hygiene bug, not a product double-fetch, and the fix is a test-only change.
The product behaviour under a day rollover is correct and wanted: when the local day changes the
widget must query the new day. Nothing in the assertion is loosened. NOW is now derived from
the real clock with only the time of day pinned, and projectionItem hangs its event hours off
that same instant, so the mount no longer straddles a day boundary and the count is genuinely 1.
The clock is pinned from local date fields rather than a UTC instant because far enough from UTC
the two name different days, which would reintroduce the rollover from the other direction. The
sibling calendar-widget.test.tsx already used local fields, so this matches the convention.

Blast radius is one test file. No product code changes, so home-calendar-widget-refresh.e2e.ts
exercises unchanged behaviour and was not run. useCalendarChangeEvents, useCalendarRange and
CalendarWidget are untouched.

Release note

none

Test plan

  • vitest run --project renderer calendar-widget-refresh.test.tsx before the fix: 1 failed, 5 passed. After: 6 passed.
  • Red then green from the index. git checkout origin/main -- <file> fails and git checkout HEAD -- <file> passes, under Europe/Istanbul, Pacific/Kiritimati (UTC+14) and Pacific/Midway (UTC-11), whose local dates differ from each other.
  • Timezone sweep of the file, 6 passed in UTC, Pacific/Kiritimati, Pacific/Midway, Asia/Kathmandu, America/Los_Angeles, Europe/Istanbul. An earlier sweep passing two spec paths at once ran zero tests and still exited 0, so every run is now guarded on a nonzero test count.
  • Green again on 2026-09-02, the day after the run that proved it red. The old fixture had never survived a date change.
  • Mutation check, 4 applied and 4 killed. Restoring the hardcoded 2026-08-31 clock. Building NOW from a UTC instant instead of local fields, killed under Pacific/Kiritimati. Dropping the onCalendarChanged subscription in useCalendarChangeEvents, 4 failed, which shows the suite still catches the bug fix(home): keep the calendar widget current when the board is a background tab #1916 fixed. Changing its settings key guard to calendars, 2 failed.
  • pnpm --filter @memry/desktop test:renderer: 705 files, 8628 passed, 2 expected fail, 7 skipped.
  • typecheck:web, typecheck:node, typecheck:test, pnpm lint (0 errors), i18n:check, check:architecture, check:contracts, git diff --check: all pass. The file is not in the typecheck:test exclude backlog, so it really compiles.
  • Not run, with reasons. ipc:check, no contract, preload or IPC handler touched. test:main, no main-process code touched. E2E, no product code touched. The docs gate needed no skip flag, docs-impact --strict reports no docs-relevant changes for a test-only diff.

The calendar widget refresh suite faked the clock onto 2026-08-31, the day it was
written. use-today snapshots the local date into module scope at import and re-reads
the wall clock for its first subscriber, so on every later day that fake clock arrives
as a midnight rollover. todayCalendarRange moves, the useCalendarRange query key moves
with it, and the widget fetches a second day during mount, which is the second
getRange call the first test counted.

Derive the fixture clock and its event hours from the real local date instead, so the
mount no longer straddles a day boundary. Local date fields rather than a UTC instant,
because far enough from UTC the two name different days.
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 05c5840.

@github-actions github-actions Bot added bug Something isn't working test labels Sep 2, 2026
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@h4yfans
h4yfans marked this pull request as ready for review September 2, 2026 09:17
@h4yfans
h4yfans merged commit 7a07448 into main Sep 2, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant