mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
The dashboard now leads with a daily band: the greeting, the one item that matters right now — an overdue or upcoming dose, a very high blood-pressure reading, weight drifting from its range, a run of short nights, a quiet stretch, a score drop, or the briefing's key finding — with a single action, today's dose tally beside the next due time, and the health score as a ring on the right. The verdict resolves from a fixed nine-rung ladder on the client with the thresholds shared from the nudge engine through a dependency-free module, the blood-pressure rung uses fixed crisis floors rather than personal target ranges, and a cached next-due in the past never renders as overdue. The band reserves its exact footprint from the first paint, swaps in with the tiles in one pass, respects the hour-format preference, and can be turned off in the dashboard settings; the greeting moves out of the page header into the band.
88 lines
3.9 KiB
TypeScript
88 lines
3.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
/**
|
|
* v1.4.40 W-RSC — dashboard Suspense boundaries.
|
|
*
|
|
* Audit-H2 flagged "no `<Suspense>` boundaries anywhere in the app".
|
|
* The v1.4.40 W-RSC wave wraps every dashboard tile cell and every
|
|
* chart cell in a per-cell `<Suspense>` boundary so the composition
|
|
* reads as a grid of independently-suspending islands rather than a
|
|
* flat client tree with shared loading semantics.
|
|
*
|
|
* Today the boundary is a structural no-op for the dynamic-loaded
|
|
* charts because their loading skeleton lives inside the
|
|
* `next/dynamic({ loading: <ChartSkeleton/> })` contract. The benefit
|
|
* is future-proofing: any descendant that later suspends (an
|
|
* `useSuspenseQuery` migration, an RSC hoist of a static legend) gets
|
|
* its own fallback without re-architecting the row.
|
|
*
|
|
* The test pins the structural presence by greppig the page source —
|
|
* a future refactor that drops the boundary lands a failing test
|
|
* rather than silently regressing the streaming-composition contract.
|
|
*/
|
|
const ROOT = join(__dirname, "../../..");
|
|
const PAGE_PATH = join(ROOT, "src/app/page.tsx");
|
|
|
|
function load(path: string): string {
|
|
return readFileSync(path, "utf8");
|
|
}
|
|
|
|
describe("v1.4.40 — dashboard per-cell Suspense boundaries", () => {
|
|
it("imports Suspense from React", () => {
|
|
const src = load(PAGE_PATH);
|
|
expect(src).toMatch(/from\s+"react"/);
|
|
expect(src).toMatch(/\bSuspense\b/);
|
|
});
|
|
|
|
it("wraps the chart-row cell in a `<Suspense fallback={<ChartSkeleton />}>` boundary", () => {
|
|
const src = load(PAGE_PATH);
|
|
// `<Suspense fallback={<ChartSkeleton />}>{entry.node}</Suspense>`
|
|
// exact contract: the chart row's per-cell fallback uses the same
|
|
// ChartSkeleton primitive the dynamic-loaded charts already paint
|
|
// during JS chunk resolution.
|
|
expect(src).toMatch(
|
|
/<Suspense\s+fallback=\{<ChartSkeleton\s*\/>\}>\s*\{entry\.node\}\s*<\/Suspense>/,
|
|
);
|
|
});
|
|
|
|
it("wraps each tile-strip cell in a `<Suspense>` boundary with a layout-stable placeholder", () => {
|
|
const src = load(PAGE_PATH);
|
|
// v1.4.41 W-FRONTEND-FACTORY (UX M1) swapped the prior `null`
|
|
// fallback for an `aria-hidden` placeholder div; v1.16.0 upgraded
|
|
// it to the structured `<TrendCardSkeleton>` silhouette (the
|
|
// aria-hidden + trend-card chrome now live inside the component,
|
|
// see `trend-card-skeleton.tsx`). The tile body is synchronous
|
|
// today so the fallback rarely paints, but a future RSC hoist of
|
|
// any tile slot would otherwise leave the grid track empty and
|
|
// trigger CLS as the cell paints in. The structural pin guards the
|
|
// contract.
|
|
expect(src).toMatch(
|
|
/<Suspense\s+fallback=\{<TrendCardSkeleton\s*\/>\}>\s*\{entry\.node\}\s*<\/Suspense>/,
|
|
);
|
|
});
|
|
|
|
it("hoists DASHBOARD_QUERY_OPTS to module scope (audit-M2)", () => {
|
|
const src = load(PAGE_PATH);
|
|
// Module-scope declaration — search outside the component body.
|
|
// Pre-fix the const was declared inside `DashboardPage` so every
|
|
// render created a fresh `{}` reference.
|
|
const moduleSliceEnd = src.indexOf("export default function DashboardPage");
|
|
expect(moduleSliceEnd).toBeGreaterThan(0);
|
|
const moduleSlice = src.slice(0, moduleSliceEnd);
|
|
expect(moduleSlice).toMatch(/const\s+DASHBOARD_QUERY_OPTS\s*=\s*\{/);
|
|
});
|
|
|
|
it("keeps the per-render Intl hour walk off the page (audit-H4 successor)", () => {
|
|
const src = load(PAGE_PATH);
|
|
// The audit-H4 `useMemo(getHourForTimeZone, [userTimezone])` pin
|
|
// retired with the greeting itself: the hero band derives the
|
|
// daypart from the snapshot's server-computed `greetingHour`
|
|
// (`dashboard-hero.tsx`), so the page no longer instantiates any
|
|
// `Intl.DateTimeFormat` for the greeting — per render or otherwise.
|
|
expect(src).not.toContain("getHourForTimeZone");
|
|
expect(src).not.toContain("welcomeText");
|
|
});
|
|
});
|