Files
HealthLog/src/components/insights/__tests__/ecg-waveform.test.tsx
T
Marc-André Bombeck 49ed0f41df feat(insights): view ECG recordings
ECG recordings synced from a compatible watch were stored encrypted but
shown nowhere. They now have a surface in Insights: a list of recordings,
each opening the full single-lead waveform on a familiar ECG grid, with the
date, duration, average heart rate, and the result the device recorded.

The read routes narrow ownership in the query and decrypt the waveform
through the existing fail-closed codec; the overview is min/max-decimated so
the R-wave peaks survive the reduction, with a raw path for a calibrated
view. The result shown is the recording device's own classification,
attributed to the device — HealthLog does not read or interpret the trace
and produces no verdict of its own. A permanent note states this, and a
non-normal result carries a line to discuss the recording with a clinician.
2026-07-16 09:55:35 +02:00

55 lines
1.9 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { I18nProvider } from "@/lib/i18n/context";
import { EcgWaveform } from "../ecg-waveform";
/**
* v1.28.50 — `<EcgWaveform>` SVG unit tests.
*
* The component draws the raw trace and nothing else: a single `<path>`
* over a grid `<pattern>`, labelled as a whole image whose accessible name
* carries the DEVICE's result verbatim. No interpretation, no annotation.
*/
function render(props: Partial<Parameters<typeof EcgWaveform>[0]> = {}) {
return renderToStaticMarkup(
<I18nProvider initialLocale="en">
<EcgWaveform
samples={[0, 10, -5, 40, -20, 5, 0]}
recordedAt="2026-06-01T09:15:00.000Z"
durationSeconds={30}
averageHeartRate={72}
resultLabel="Atrial fibrillation detected"
{...props}
/>
</I18nProvider>,
);
}
describe("<EcgWaveform>", () => {
it("renders a single trace path and the ECG grid pattern", () => {
const html = render();
expect(html).toContain('data-slot="ecg-waveform"');
expect(html).toContain('data-slot="ecg-trace"');
// A polyline d-string, not per-point elements.
expect(html).toMatch(/<path[^>]*d="M0/);
expect(html).toContain("<pattern");
});
it("exposes role=img with an accessible label carrying the device result", () => {
const html = render();
expect(html).toContain('role="img"');
expect(html).toContain("aria-label");
// The device's verdict is folded into the whole-image label verbatim.
expect(html).toContain("Atrial fibrillation detected");
expect(html).toContain("72 bpm");
});
it("renders no trace path for an empty sample array", () => {
const html = render({ samples: [] });
expect(html).toContain('data-slot="ecg-waveform"');
expect(html).not.toContain('data-slot="ecg-trace"');
});
});