test(desktop): pin the clock in the session-row timestamp test
The sidebar row's Tip trigger test derives its fixture from the wall clock:
const startedAt = Math.floor(Date.now() / 1000) - 5 * 60
...
expect(age.getAttribute('aria-label')).toMatch(/^5m, Today at /)
"Five minutes ago" is only today when the run does not straddle local
midnight. Between 00:00 and 00:05 the timestamp falls into the previous
day, formatMessageTimestamp correctly returns the yesterday label, and
the test fails on a day boundary it was never written to exercise:
AssertionError: expected '5m, Yesterday at 11:56 PM'
to match /^5m, Today at /
This is a real CI failure, not a theoretical one - it took down a
check:test:ui shard on an unrelated desktop PR at 00:01 UTC, and it will
do so for any PR whose shard happens to land in that five-minute window.
Pin the clock to local noon before deriving the timestamp so the fixture
can never cross a day boundary. Only Date is faked (toFake: ['Date']),
so the component's own timers - the running arc and the tooltip open
delay - keep running for real; the neighbouring tooltip tests that
advance timers are unaffected. The describe block gains the
useRealTimers teardown its sibling already had.
The production formatter is not changed: rendering "Yesterday at 11:56
PM" for a session started five minutes before midnight is correct, and
the assertion is about the label's composition, not about which day it
names.
This commit is contained in:
@@ -231,6 +231,10 @@ describe('SidebarSessionRow running arc', () => {
|
||||
})
|
||||
|
||||
describe('SidebarSessionRow', () => {
|
||||
afterEach(() => {
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('keeps an aria-label on the kebab without wrapping it in a Tip', () => {
|
||||
render(
|
||||
<SidebarSessionRow
|
||||
@@ -322,6 +326,17 @@ describe('SidebarSessionRow', () => {
|
||||
})
|
||||
|
||||
it('exposes the exact session time through a focusable Tip trigger', () => {
|
||||
// Pin the clock before deriving the timestamp. The assertion below is
|
||||
// about the *composition* of the label (relative age + absolute time),
|
||||
// but "5 minutes ago" only falls on today when the run does not straddle
|
||||
// local midnight. Between 00:00 and 00:05 the row correctly renders
|
||||
// "Yesterday at 11:5x PM" and this test failed for a day boundary it was
|
||||
// never written to exercise. Only `Date` is faked, so the component's
|
||||
// own timers (the running arc, the tooltip open delay) keep running for
|
||||
// real.
|
||||
vi.useFakeTimers({ toFake: ['Date'] })
|
||||
vi.setSystemTime(new Date(2026, 2, 5, 12, 0, 0))
|
||||
|
||||
const startedAt = Math.floor(Date.now() / 1000) - 5 * 60
|
||||
|
||||
render(
|
||||
|
||||
Reference in New Issue
Block a user