Files
HealthLog/src/components/cycle/__tests__/cycle-ring.test.tsx
T
Marc-André BombeckandClaude Opus 4.8 4b10bdc5da feat(cycle): single-day read endpoint, symptom severity, and a richer log-day sheet
Add `GET /api/cycle/day-logs?date=YYYY-MM-DD` returning the full day-log DTO
(or null) for one tz-anchored day so the web log-day sheet pre-fills instead
of opening blank — a blank re-log no longer nulls untouched or HealthKit-sourced
fields. Delete resolves the row id from the same read.

Persist an optional 1-4 Likert severity per symptom link (migration
0133_v1150_cycle_symptom_severity), carried through the shared symptom-link
writer and surfaced in the day-log DTO.

Sheet now captures the previously missing fields — spotting between periods,
pregnancy/progesterone home-test results, contraceptive kind — plus per-symptom
severity chips, a one-tap end-period boundary, and a Delete action. The wheel
ring marker sits at the 12-o'clock origin again (drop the double rotation), the
cycle view goes two-column on desktop, and the empty ring carries a first-period
call to action. New copy is localized across all six locales; the prediction and
fertility surfaces keep their disclaimers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-06 12:39:28 +02:00

69 lines
2.3 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { CycleRing } from "../cycle-ring";
import { I18nProvider } from "@/lib/i18n/context";
function render(node: React.ReactNode, locale: "en" | "de" = "en") {
return renderToStaticMarkup(
<I18nProvider initialLocale={locale}>{node}</I18nProvider>,
);
}
describe("<CycleRing>", () => {
it("renders the root data-slot tagged with the active phase", () => {
const html = render(
<CycleRing
dayOfCycle={8}
cycleLength={28}
phase="FOLLICULAR"
spans={[
{ phase: "MENSTRUAL", fraction: 0.18 },
{ phase: "FOLLICULAR", fraction: 0.32 },
{ phase: "OVULATORY", fraction: 0.1 },
{ phase: "LUTEAL", fraction: 0.4 },
]}
/>,
);
expect(html).toContain('data-slot="cycle-ring"');
expect(html).toContain('data-phase="FOLLICULAR"');
});
it("shows the day-of-cycle number as centred text", () => {
const html = render(
<CycleRing dayOfCycle={12} cycleLength={28} phase="OVULATORY" />,
);
expect(html).toContain(">12<");
});
it("carries a phase-aware aria-label (never colour-only)", () => {
const html = render(
<CycleRing dayOfCycle={3} cycleLength={28} phase="MENSTRUAL" />,
);
expect(html).toContain('role="img"');
expect(html).toContain("aria-label");
// The label restates the day + phase.
expect(html).toContain("3");
});
it("parks the day-1 marker at the 12-o'clock origin (no double-rotate)", () => {
// The <svg> carries `-rotate-90`, so day 1 (progress 0, angle 0) must
// land at the un-rotated 3-o'clock SVG point (cx ≈ CX + R, cy ≈ CX) which
// renders at the top. The prior `-π/2` bug parked it at cx ≈ CX (9 o'clock
// after rotation). R = (100 - 8) / 2 = 46, CX = 50.
const html = render(
<CycleRing dayOfCycle={1} cycleLength={28} phase="MENSTRUAL" />,
);
// The marker circle's cx is the last <circle> with a stroke-width of 2.
expect(html).toMatch(/cx="9[0-9](\.\d+)?"/);
});
it("renders the no-cycle state for a null day with a fallback aria-label", () => {
const html = render(
<CycleRing dayOfCycle={null} cycleLength={null} phase={null} />,
);
expect(html).toContain('data-phase="none"');
expect(html).toContain('role="img"');
});
});