fix(e2e,insights): the coach specs follow the drawer, and the status cards stop tearing hydration

The coach launcher deliberately opens the side drawer in place now —
the spec expected the old navigation and waited for a URL that never
comes; it asserts the drawer (bottom-sheet on the phone viewport) and
the nudge-dot lifecycle instead. The metric and slug status cards
rendered locale-dependent content in the hydration pass, which React
flagged as a mismatch (#418) on the dashboard and the mood page — they
ride the established mounted gate now, pinning the server branch for
the first paint. The midnight flake in the intake bucket tests is
pinned to a fixed clock: the fixtures minted UTC days while the route
buckets Berlin days, so runs between midnight and two failed.
This commit is contained in:
Marc-André Bombeck committed 2026-06-13 01:02:14 +02:00
1 parent a1511b33b3
commit 15c77597fc
9 files changed
+117 -14

No files matched your search

@@ -177,8 +177,11 @@ describe("v1.4.43 W11 — dashboard tile-strip skeleton (wiring)", () => {
const src = readFileSync(PAGE_PATH, "utf8");
// The placeholder count keys off the layout config minus the
// already-mounted (layout-gated) cells, and only while loading.
// `mounted &&` pins the hydration render to the SSR output — the
// auth query can settle before the page boundary hydrates, and an
// extra BMI silhouette then mismatched the server HTML (React #418).
expect(src).toMatch(
/const\s+chartRowPlaceholderCount\s*=\s*primaryLoading[\s\S]*?resolveChartRowPlaceholderCount\(layout,[\s\S]*?hasHeightCm:\s*Boolean\(user\?\.heightCm\)/,
/const\s+chartRowPlaceholderCount\s*=\s*primaryLoading[\s\S]*?resolveChartRowPlaceholderCount\(layout,[\s\S]*?hasHeightCm:\s*mounted\s*&&\s*Boolean\(user\?\.heightCm\)/,
);
expect(src).toMatch(/-\s*charts\.length/);
// The reserved cells render as aria-hidden ChartSkeletons in their
@@ -528,6 +528,25 @@ describe("v1.15.9 — schedule-anchored compliance buckets (BUG #1)", () => {
// engine's expected-dose count per day (not the count of logged intake
// rows). With partial adherence the per-day rate `taken / scheduled`
// genuinely reflects taken-of-expected — it is NOT pinned at ~100%.
//
// The clock is pinned to a fixed midday instant: the fixtures mint one
// event per UTC day, but the route buckets by the user's local
// (Europe/Berlin) day — with a live clock, a run between 00:00 and
// ~01:59 local (UTC date still "yesterday") left the local TODAY
// bucket with `scheduled = 1, taken = 0` and failed the full-adherence
// assertion. At 12:00 UTC the UTC day and the Berlin day coincide, so
// the per-UTC-day fixture math is exact. Only `Date` is faked — the
// route awaits real promises.
beforeEach(() => {
vi.useFakeTimers({
now: new Date("2026-06-10T12:00:00Z"),
toFake: ["Date"],
});
});
afterEach(() => {
vi.useRealTimers();
});
function activeDailyMed(createdAt: Date) {
return {
id: "m1",
+8 -1
View File
@@ -4,6 +4,7 @@ import { useCallback, useState } from "react";
import Link from "next/link";
import { useQueryClient } from "@tanstack/react-query";
import { useAuth } from "@/hooks/use-auth";
import { useMounted } from "@/hooks/use-mounted";
import { usePullToRefresh } from "@/hooks/use-pull-to-refresh";
import { MoodForm } from "@/components/mood/mood-form";
import { MoodList } from "@/components/mood/mood-list";
@@ -17,6 +18,7 @@ import { useTranslations } from "@/lib/i18n/context";
export default function MoodPage() {
const { isAuthenticated, isLoading } = useAuth();
const mounted = useMounted();
const router = useRouter();
const queryClient = useQueryClient();
const [dialogOpen, setDialogOpen] = useState(false);
@@ -45,7 +47,12 @@ export default function MoodPage() {
}
}, [isLoading, isAuthenticated, router]);
if (isLoading) {
// `!mounted` keeps the hydration render identical to the SSR HTML: the
// auth query is fired by the early-hydrating shell and can settle before
// this page boundary hydrates, so `isLoading` alone flipped the branch
// and React logged hydration error #418 — same fix as the measurements
// page; see `useMounted`.
if (!mounted || isLoading) {
return (
<div className="flex h-64 items-center justify-center">
<Loader2 className="text-primary h-8 w-8 animate-spin motion-reduce:animate-none" />
+7 -1
View File
@@ -1429,11 +1429,17 @@ export default function DashboardPage() {
// already mounted) so the page holds roughly its final
// footprint from first paint and the snapshot landing swaps
// content instead of growing the page.
// `mounted &&` pins the hydration render to the SSR output: the
// auth query is fired by the early-hydrating shell, so `user`
// can already carry a heightCm when this late-hydrating page
// boundary replays its first render — the extra BMI silhouette
// then mismatched the server HTML (React #418). The count may
// only personalise from the first client re-render.
const chartRowPlaceholderCount = primaryLoading
? Math.max(
0,
resolveChartRowPlaceholderCount(layout, {
hasHeightCm: Boolean(user?.heightCm),
hasHeightCm: mounted && Boolean(user?.heightCm),
}) - charts.length,
)
: 0;
@@ -104,7 +104,14 @@ describe("<HealthKitMetricPage> status mount", () => {
/>,
);
expect(html).toContain("Your HRV has trended upward");
// The server pass renders the card's loading skeleton even when the
// mocked query reports settled data: `<MetricStatusCard>` pins SSR +
// the hydration render to the loading branch (`!mounted`) so a query
// that settles before a late-hydrating boundary replays its first
// render cannot mismatch the server HTML (React #418). The settled
// text swaps in on the first client re-render.
expect(html).toContain('data-testid="insight-status-card-loading"');
expect(html).not.toContain("Your HRV has trended upward");
// The card fetch is enabled (statusMetric present + data present).
expect(metricStatusMock).toHaveBeenCalledWith("HEART_RATE_VARIABILITY", true);
});
@@ -3,6 +3,7 @@
import type { ReactNode } from "react";
import { useInsightMetricStatus } from "@/hooks/use-insight-status";
import { useMounted } from "@/hooks/use-mounted";
import { useTranslations } from "@/lib/i18n/context";
import type { MetricStatusMetricId } from "@/lib/insights/metric-status-registry";
import { InsightStatusCard } from "@/components/insights/insight-status-card";
@@ -35,6 +36,7 @@ export function MetricStatusCard({
enabled,
}: MetricStatusCardProps) {
const { t } = useTranslations();
const mounted = useMounted();
const { data: status, isLoading } = useInsightMetricStatus(metric, enabled);
return (
@@ -44,7 +46,11 @@ export function MetricStatusCard({
text={status?.text ?? null}
hasProvider={status?.hasProvider ?? false}
updatedAt={status?.updatedAt ?? null}
loading={isLoading}
// Same hydration gate as `<SlugInsightStatusCard>`: the hook is
// `enabled: isAuthenticated && enabled`, and both inputs can settle
// before a late-hydrating boundary replays its first render — the
// loading branch then disagrees with the server HTML (React #418).
loading={!mounted || isLoading}
preparing={status?.preparing ?? false}
/>
);
@@ -6,6 +6,7 @@ import {
useInsightStatus,
type InsightStatusMetric,
} from "@/hooks/use-insight-status";
import { useMounted } from "@/hooks/use-mounted";
import { useTranslations } from "@/lib/i18n/context";
import { InsightStatusCard } from "@/components/insights/insight-status-card";
@@ -32,6 +33,7 @@ export function SlugInsightStatusCard({
icon,
}: SlugInsightStatusCardProps) {
const { t } = useTranslations();
const mounted = useMounted();
const { data: status, isLoading } = useInsightStatus(slug);
return (
@@ -41,7 +43,12 @@ export function SlugInsightStatusCard({
text={status?.text ?? null}
hasProvider={status?.hasProvider ?? false}
updatedAt={status?.updatedAt ?? null}
loading={isLoading}
// `!mounted ||` keeps the SSR pass and the hydration render on the
// same skeleton branch. The status query is `enabled: isAuthenticated`,
// and the auth query resolves from the early-hydrating shell — a
// late-hydrating page boundary then saw `isLoading` flip true while
// the server HTML carried the settled card (React #418).
loading={!mounted || isLoading}
preparing={status?.preparing ?? false}
/>
);