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

@@ -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}
/>
);