mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
test(insights): freeze the clock in the freshness-caption tests to fix the midnight-boundary flake
This commit is contained in:
1 parent
f4919e9634
commit
4702546cdb
2 files changed
+36
-17
No files matched your search
@@ -131,13 +131,22 @@ describe("<DailyBriefing>", () => {
|
||||
|
||||
it("renders the 'Updated today, <time>' caption when updatedAt is supplied", () => {
|
||||
// v1.22 (W6) — the footer now uses `formatUpdatedLabel`: a same-day
|
||||
// timestamp reads "Updated today, HH:MM".
|
||||
const fiveMinutesAgo = new Date(Date.now() - 5 * 60_000).toISOString();
|
||||
const html = render(
|
||||
<DailyBriefing briefing={baseBriefing} updatedAt={fiveMinutesAgo} />,
|
||||
);
|
||||
expect(html).toMatch(/data-slot="daily-briefing-updated"/);
|
||||
expect(html).toContain("Updated today");
|
||||
// timestamp reads "Updated today, HH:MM". The label derives "today" from the
|
||||
// real clock in the profile timezone (Europe/Berlin), so freeze the clock to
|
||||
// a fixed mid-day instant and base `updatedAt` on it — otherwise a run that
|
||||
// straddles local midnight reads the five-minutes-ago stamp as "yesterday".
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-05-10T12:00:00+02:00"));
|
||||
try {
|
||||
const fiveMinutesAgo = new Date(Date.now() - 5 * 60_000).toISOString();
|
||||
const html = render(
|
||||
<DailyBriefing briefing={baseBriefing} updatedAt={fiveMinutesAgo} />,
|
||||
);
|
||||
expect(html).toMatch(/data-slot="daily-briefing-updated"/);
|
||||
expect(html).toContain("Updated today");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("does NOT render the updated caption when updatedAt is missing", () => {
|
||||
|
||||
@@ -108,16 +108,26 @@ describe("<HeroStrip>", () => {
|
||||
// v1.22 — the hero freshness line now uses `formatUpdatedLabel` for parity
|
||||
// with the briefing + per-metric cards: a same-day timestamp reads
|
||||
// "Updated today, HH:MM" rather than the old relative "Generated … ago".
|
||||
const fiveMinutesAgo = new Date(Date.now() - 5 * 60_000).toISOString();
|
||||
const html = render(
|
||||
<HeroStrip
|
||||
briefing={null}
|
||||
updatedAt={fiveMinutesAgo}
|
||||
now={morningLocal}
|
||||
/>,
|
||||
);
|
||||
expect(html).toMatch(/data-slot="insights-hero-strip-generated"/);
|
||||
expect(html).toContain("Updated today");
|
||||
// `formatUpdatedLabel` derives "today" from the real clock, so freeze it to a
|
||||
// fixed instant and base `updatedAt` on the same instant — otherwise a run
|
||||
// that straddles local midnight reads the five-minutes-ago stamp as
|
||||
// "yesterday".
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(morningLocal);
|
||||
try {
|
||||
const fiveMinutesAgo = new Date(Date.now() - 5 * 60_000).toISOString();
|
||||
const html = render(
|
||||
<HeroStrip
|
||||
briefing={null}
|
||||
updatedAt={fiveMinutesAgo}
|
||||
now={morningLocal}
|
||||
/>,
|
||||
);
|
||||
expect(html).toMatch(/data-slot="insights-hero-strip-generated"/);
|
||||
expect(html).toContain("Updated today");
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("does NOT render the generated caption when updatedAt is missing", () => {
|
||||
|
||||
Reference in new issue
Block a user