Files
HealthLog/e2e/settings-export.spec.ts
T
Marc-André BombeckandClaude Opus 4.7 e628f33f06 test(export): coverage for export-section + endpoints
Adds an e2e smoke (`e2e/settings-export.spec.ts`) that:
  1. Asserts the five export cards render with stable testids
     (`export-card-doctor-report` etc) so the consolidated UI can't
     silently regress to fewer than five cards.
  2. Drives the Measurements CSV download end-to-end with the API
     stubbed — the browser-side wiring is what we lock in here, not
     the route's DB query (already covered by the integration test).

Component test coverage already landed in commit 621109c
(`export-section.test.tsx`); unit + integration coverage for the
endpoints landed in commit 226cac4 — this e2e is the missing piece.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 00:12:25 +02:00

72 lines
2.5 KiB
TypeScript

import { expect, test } from "@playwright/test";
import { STORAGE_STATE_PATH } from "./setup/global-setup";
/**
* v1.4.16 phase B7 — Settings → Export consolidated UI smoke.
*
* Validates that:
* 1. The five export cards are all rendered with their stable testids.
* 2. Clicking the Measurements CSV download button fires a real
* browser download — proving the new `/api/export/measurements`
* endpoint is reachable from the browser end-to-end.
*
* The other CSV / JSON cards share the same code path; one happy-path
* download is enough to lock in the wiring without doubling the e2e
* runtime.
*/
test.describe("Settings → Export", () => {
test.use({ storageState: STORAGE_STATE_PATH });
test("renders all five export cards with stable testids", async ({
page,
}) => {
await page.goto("/settings/export", { waitUntil: "domcontentloaded" });
for (const id of [
"export-card-doctor-report",
"export-card-measurements-csv",
"export-card-medications-csv",
"export-card-mood-csv",
"export-card-full-backup",
]) {
await expect(page.getByTestId(id)).toBeVisible({ timeout: 10_000 });
}
});
test("Measurements CSV download fires a real download event", async ({
page,
}) => {
// Stub the API so we don't need 90 days of seeded data — the
// browser-side wiring is what we're validating, not the route's
// DB query.
await page.route("**/api/export/measurements*", (route) =>
route.fulfill({
status: 200,
contentType: "text/csv; charset=utf-8",
headers: {
"Content-Disposition":
'attachment; filename="healthlog-measurements-test.csv"',
},
body: "type,value,unit,measuredAt,source,notes,glucoseContext\nWEIGHT,80,kg,2026-05-01T08:00:00.000Z,MANUAL,,\n",
}),
);
await page.goto("/settings/export", { waitUntil: "domcontentloaded" });
const downloadBtn = page.getByTestId("export-action-measurements-csv");
await expect(downloadBtn).toBeVisible({ timeout: 10_000 });
const downloadPromise = page.waitForEvent("download", {
timeout: 30_000,
});
await downloadBtn.click();
const download = await downloadPromise;
const path = await download.path();
expect(path).toBeTruthy();
const fs = await import("node:fs/promises");
const buf = await fs.readFile(path!);
expect(buf.byteLength).toBeGreaterThan(0);
expect(buf.toString("utf8")).toContain("WEIGHT,80,kg");
});
});