mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Hidden states of the floating coach button now leave the tab order and accessibility tree, its focus ring carries an offset, its icon is dark on the gradient, an unread nudge is announced once via a live region, and it sits correctly above the fold on tablet widths and yields to the onboarding tour. Chart error cards announce themselves, share the exact height variables of the skeleton band, carry per-chart retry labels, and a failed chunk renders inside the regular card shell. The header icon cluster spaces its extended hit areas apart, the tab strip keeps horizontal paint room for focus rings, the streak row reserves its slot in every card state, the selection bar clears the bottom nav on landscape phones, and the version poller keeps an in-memory reload guard for browsers that block session storage. Mood notes render as plain paragraphs with a toggle that appears only when text is actually clamped, the remember control reveals on hover and hands focus to its confirmation, and the hypnogram names its source and paints only the lanes the night contains.
95 lines
3.0 KiB
TypeScript
95 lines
3.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
import {
|
|
SleepHypnogram,
|
|
type SleepHypnogramSession,
|
|
} from "../sleep-hypnogram";
|
|
|
|
/**
|
|
* v1.16.8 — hypnogram polish: the night's measuring source rides the
|
|
* header as a muted caption, and the depth lanes derive from the stages
|
|
* actually present in the night's spans (in `LANE_ORDER` order) instead
|
|
* of always painting all six — an Apple night (AWAKE/REM/CORE/DEEP)
|
|
* used to carry two permanently empty rows.
|
|
*
|
|
* Project convention: SSR-only tests. Recharts' `ResponsiveContainer`
|
|
* paints nothing without measured dimensions, so the lane derivation is
|
|
* pinned structurally against the source.
|
|
*/
|
|
|
|
const baseSession: SleepHypnogramSession = {
|
|
night: "2026-06-09",
|
|
source: "Apple Health",
|
|
start: "2026-06-08T22:30:00.000Z",
|
|
end: "2026-06-09T06:00:00.000Z",
|
|
asleepMinutes: 420,
|
|
inBedMinutes: 450,
|
|
awakeMinutes: 30,
|
|
awakenings: 2,
|
|
stages: { DEEP: 90, REM: 100, CORE: 230, AWAKE: 30 },
|
|
segments: [
|
|
{
|
|
stage: "AWAKE",
|
|
start: "2026-06-08T22:30:00.000Z",
|
|
end: "2026-06-08T22:45:00.000Z",
|
|
minutes: 15,
|
|
},
|
|
{
|
|
stage: "CORE",
|
|
start: "2026-06-08T22:45:00.000Z",
|
|
end: "2026-06-09T01:00:00.000Z",
|
|
minutes: 135,
|
|
},
|
|
{
|
|
stage: "DEEP",
|
|
start: "2026-06-09T01:00:00.000Z",
|
|
end: "2026-06-09T02:30:00.000Z",
|
|
minutes: 90,
|
|
},
|
|
],
|
|
};
|
|
|
|
function render(session: SleepHypnogramSession, locale: "en" | "de" = "en") {
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale={locale}>
|
|
<SleepHypnogram session={session} />
|
|
</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
describe("<SleepHypnogram> — source caption", () => {
|
|
it("surfaces the night's measuring source as a muted header caption", () => {
|
|
const html = render(baseSession);
|
|
expect(html).toContain('data-slot="sleep-hypnogram-source"');
|
|
expect(html).toContain("Source: Apple Health");
|
|
});
|
|
|
|
it("localises the caption label", () => {
|
|
const html = render(baseSession, "de");
|
|
expect(html).toContain("Quelle: Apple Health");
|
|
});
|
|
|
|
it("omits the caption when the session carries no source", () => {
|
|
const html = render({ ...baseSession, source: null });
|
|
expect(html).not.toContain('data-slot="sleep-hypnogram-source"');
|
|
});
|
|
});
|
|
|
|
describe("<SleepHypnogram> — lane derivation", () => {
|
|
it("derives the Y lanes from the stages present in the spans", () => {
|
|
const src = readFileSync(
|
|
join(process.cwd(), "src/components/insights/sleep-hypnogram.tsx"),
|
|
"utf8",
|
|
);
|
|
// Lanes come from the present stages, preserving LANE_ORDER…
|
|
expect(src).toContain("LANE_ORDER.filter((stage) => present.has(stage))");
|
|
// …and the axis reads the derived lane list, not the full constant.
|
|
expect(src).toContain("domain={[-0.5, lanes.length - 0.5]}");
|
|
expect(src).toContain("ticks={lanes.map((_, i) => lanes.length - 1 - i)}");
|
|
});
|
|
});
|