mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
Merge remote-tracking branch 'origin/release/v1.42.0' into v142/qol-1
# Conflicts: # src/app/insights/mood/page.tsx # src/components/charts/mood-heatmap.tsx # src/components/documents/document-bulk-bar.tsx
This commit is contained in:
commit
17b8b35397
67 files changed
+3990
-1675
No files matched your search
@@ -0,0 +1,315 @@
|
||||
import type { Locator, Page, TestInfo } from "@playwright/test";
|
||||
|
||||
import { aiBlockAvailable, serveAiBlock } from "./setup/ai-capabilities";
|
||||
import { DAY_DOORS_ANALYTE } from "./setup/day-doors-fixture";
|
||||
import { mockDay } from "./setup/day-mock";
|
||||
import {
|
||||
DAY_DOORS_STORAGE_STATE_PATH,
|
||||
MOBILE_ROUTES_STORAGE_STATE_PATH,
|
||||
} from "./setup/global-setup";
|
||||
import { expect, test } from "./setup/test";
|
||||
|
||||
/**
|
||||
* v1.42 — every chart drawn in days opens its days, the same way.
|
||||
*
|
||||
* The day view first reached six metric pages; the recovery page beside them
|
||||
* offered no day at all. These journeys walk the surfaces that came after,
|
||||
* each through the same doors: on a fine pointer a click on a point (or a
|
||||
* calendar cell) opens the day beside the page; on a touch screen the first
|
||||
* tap shows the value and the tooltip's "View the whole day" opens it as a
|
||||
* bottom sheet, the tapped value on top. A date in a list opens in one tap.
|
||||
* The dashed line (or outline) marks the open day, the row of dots and the
|
||||
* caption sit under every chart, and the data table's dates are the
|
||||
* keyboard way to the same days.
|
||||
*
|
||||
* - recovery (the page the beta reported), sleep, a lab marker, a chart
|
||||
* with its comparison period on and a dashboard chart: line charts;
|
||||
* - the mood calendar: a heatmap;
|
||||
* - a metric's "all values" list: a date in a row.
|
||||
*
|
||||
* The day itself is a route mock in the contract's shape, as in
|
||||
* `day-view.spec.ts`: these journeys pin the client's doors, not the day.
|
||||
* Stable data attributes only.
|
||||
*/
|
||||
|
||||
const panel = (page: Page) => page.locator('[data-slot="day-panel"]');
|
||||
const isPhone = (testInfo: TestInfo) =>
|
||||
testInfo.project.name === "chromium-mobile";
|
||||
|
||||
/** Open the day of the point at 80 % across a day-linked plot. */
|
||||
async function openFromPlot(page: Page, plot: Locator, testInfo: TestInfo) {
|
||||
await plot.scrollIntoViewIfNeeded();
|
||||
await expect(plot).toHaveAttribute("data-day-links", "true");
|
||||
const box = (await plot.boundingBox())!;
|
||||
const x = box.x + box.width * 0.8;
|
||||
const y = box.y + box.height / 2;
|
||||
if (isPhone(testInfo)) {
|
||||
await page.touchscreen.tap(x, y);
|
||||
const open = page.locator('[data-slot="chart-tooltip-open-day"]:visible');
|
||||
await expect(open).toBeVisible();
|
||||
// A tap alone never opens a sheet: a point is a small target.
|
||||
await expect(panel(page)).toHaveCount(0);
|
||||
// The button is a calm, full 44 px row.
|
||||
expect((await open.boundingBox())!.height).toBeGreaterThanOrEqual(44);
|
||||
await open.tap();
|
||||
await expect(panel(page)).toHaveAttribute("data-shell", "bottom");
|
||||
} else {
|
||||
await page.mouse.move(x, y);
|
||||
await page.mouse.click(x, y);
|
||||
await expect(panel(page)).toHaveAttribute("data-shell", "docked");
|
||||
}
|
||||
await expect(page).toHaveURL(/[?&]day=\d{4}-\d{2}-\d{2}/);
|
||||
await expect(page.locator('[data-slot="day-view"]')).toBeVisible();
|
||||
}
|
||||
|
||||
test.describe("every chart drawn in days opens its days", () => {
|
||||
test.use({ storageState: DAY_DOORS_STORAGE_STATE_PATH });
|
||||
|
||||
test.beforeEach(async ({ page, context }, testInfo) => {
|
||||
const baseURL = testInfo.project.use.baseURL ?? "http://localhost:3000";
|
||||
await context.addCookies([
|
||||
{ name: "healthlog-locale", value: "en", url: baseURL },
|
||||
]);
|
||||
await mockDay(page, { index: "full" });
|
||||
});
|
||||
|
||||
test("recovery: a point opens its day, and the open day is marked", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
if (!isPhone(testInfo)) {
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
}
|
||||
await page.goto("/insights/recovery");
|
||||
const plot = page
|
||||
.locator('[data-slot="chart-plot"][data-day-links="true"]')
|
||||
.first();
|
||||
await expect(plot).toBeVisible();
|
||||
// Under the chart: the caption and the row of day dots, which draws the
|
||||
// days the index names, one of them ringed as notable.
|
||||
const rug = page.locator('[data-slot="day-rug"]').first();
|
||||
await expect(
|
||||
page.locator('[data-slot="chart-day-caption"]').first(),
|
||||
).toBeVisible();
|
||||
await expect(rug.locator("[data-day]").first()).toBeAttached();
|
||||
await expect(rug.locator('[data-notable="true"]')).toHaveCount(1);
|
||||
|
||||
await openFromPlot(page, plot, testInfo);
|
||||
const day = await page
|
||||
.locator('[data-slot="day-view"]')
|
||||
.getAttribute("data-day");
|
||||
// The value the person came from heads the day.
|
||||
await expect(page.locator('[data-slot="day-focus"]')).toBeVisible();
|
||||
// The open day's dot is the filled one.
|
||||
await expect(rug.locator(`[data-day="${day}"]`)).toHaveAttribute(
|
||||
"data-open",
|
||||
"true",
|
||||
);
|
||||
});
|
||||
|
||||
test("recovery: the data table's dates are the keyboard way to a day", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
test.skip(isPhone(testInfo), "keyboard path");
|
||||
await page.goto("/insights/recovery");
|
||||
const toggle = page
|
||||
.locator('[data-slot="chart-data-table-toggle"]')
|
||||
.first();
|
||||
await toggle.scrollIntoViewIfNeeded();
|
||||
await toggle.focus();
|
||||
await page.keyboard.press("Enter");
|
||||
const link = page
|
||||
.locator('[data-slot="chart-data-table-region"] [data-slot="day-link"]')
|
||||
.first();
|
||||
await link.focus();
|
||||
const day = await link.getAttribute("data-day");
|
||||
await page.keyboard.press("Enter");
|
||||
await expect(page.locator('[data-slot="day-view"]')).toHaveAttribute(
|
||||
"data-day",
|
||||
day!,
|
||||
);
|
||||
// Escape closes the day and gives the keyboard back to the date.
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(panel(page)).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("sleep: a night's point opens its day", async ({ page }, testInfo) => {
|
||||
await page.goto("/insights/sleep");
|
||||
const plot = page
|
||||
.locator('[data-slot="chart-plot"][data-day-links="true"]')
|
||||
.first();
|
||||
await expect(plot).toBeVisible();
|
||||
await openFromPlot(page, plot, testInfo);
|
||||
});
|
||||
|
||||
test("the mood calendar: a logged day's cell opens it", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
await page.goto("/insights/mood");
|
||||
// A logged, openable cell: it carries the pointer cursor.
|
||||
const cell = page.locator("rect.cursor-pointer[data-day]").last();
|
||||
await cell.scrollIntoViewIfNeeded();
|
||||
await expect(cell).toBeVisible();
|
||||
const day = await cell.getAttribute("data-day");
|
||||
if (isPhone(testInfo)) {
|
||||
await cell.tap();
|
||||
const open = page.locator(
|
||||
'[data-slot="heatmap-tooltip"] [data-slot="chart-tooltip-open-day"]',
|
||||
);
|
||||
await expect(open).toBeVisible();
|
||||
await expect(panel(page)).toHaveCount(0);
|
||||
await open.tap();
|
||||
await expect(panel(page)).toHaveAttribute("data-shell", "bottom");
|
||||
} else {
|
||||
await cell.click();
|
||||
}
|
||||
await expect(page.locator('[data-slot="day-view"]')).toHaveAttribute(
|
||||
"data-day",
|
||||
day!,
|
||||
);
|
||||
// The open day's cell is outlined.
|
||||
await expect(page.locator('[data-slot="heatmap-open-day"]')).toHaveCount(1);
|
||||
});
|
||||
|
||||
test("a lab marker's reading opens the day it was taken", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
await page.goto("/labs");
|
||||
await page
|
||||
.locator('[data-slot="lab-list-analyte"]')
|
||||
.filter({ hasText: DAY_DOORS_ANALYTE })
|
||||
.first()
|
||||
.click();
|
||||
const plot = page
|
||||
.locator('[data-slot="chart-plot"][data-day-links="true"]')
|
||||
.first();
|
||||
await expect(plot).toBeVisible();
|
||||
await openFromPlot(page, plot, testInfo);
|
||||
// The reading on top, with the one before it beside it.
|
||||
await expect(page.locator('[data-slot="day-focus"]')).toBeVisible();
|
||||
});
|
||||
|
||||
test("a chart with its comparison period on still opens its days", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
await page.goto("/insights/weight");
|
||||
const plot = page
|
||||
.locator('[data-slot="chart-plot"][data-day-links="true"]')
|
||||
.first();
|
||||
await expect(plot).toBeVisible();
|
||||
await page
|
||||
.locator('[data-slot="chart-overlay-controls-trigger"]')
|
||||
.first()
|
||||
.click();
|
||||
await page
|
||||
.locator('[data-slot="chart-overlay-comparison-lastMonth"]')
|
||||
.click();
|
||||
await page.keyboard.press("Escape");
|
||||
// The overlay menu is closed before the chart is touched, so the tap
|
||||
// lands on the chart and not on the menu's outside-dismiss.
|
||||
await expect(
|
||||
page.locator('[data-slot="chart-overlay-controls-content"]'),
|
||||
).toHaveCount(0);
|
||||
await expect(
|
||||
page.locator('[data-slot="chart-compare-caption"]').first(),
|
||||
).toBeAttached();
|
||||
await openFromPlot(page, plot, testInfo);
|
||||
await expect(page.locator('[data-slot="day-focus"]')).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("the dashboard and the list of all values", () => {
|
||||
test.use({ storageState: DAY_DOORS_STORAGE_STATE_PATH });
|
||||
|
||||
test.beforeEach(async ({ page, context }, testInfo) => {
|
||||
const baseURL = testInfo.project.use.baseURL ?? "http://localhost:3000";
|
||||
await context.addCookies([
|
||||
{ name: "healthlog-locale", value: "en", url: baseURL },
|
||||
]);
|
||||
await mockDay(page, { index: "full" });
|
||||
});
|
||||
|
||||
test("a dashboard chart opens its day; the today hero offers none", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
if (!isPhone(testInfo)) {
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
}
|
||||
await page.goto("/");
|
||||
await expect(
|
||||
page.locator(
|
||||
'[data-slot^="today-hero"] [data-slot="day-link"], [data-slot^="today-hero"] [data-day-links="true"]',
|
||||
),
|
||||
).toHaveCount(0);
|
||||
const plot = page
|
||||
.locator('[data-slot="chart-plot"][data-day-links="true"]')
|
||||
.first();
|
||||
await expect(plot).toBeVisible({ timeout: 20_000 });
|
||||
await openFromPlot(page, plot, testInfo);
|
||||
// Closing leaves the dashboard on today.
|
||||
await page.locator('[data-slot="day-close"]').click();
|
||||
await expect(panel(page)).toHaveCount(0);
|
||||
await expect(page).toHaveURL(/\/$/);
|
||||
});
|
||||
|
||||
test("a date in a metric's list of all values opens its day", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
await page.goto("/insights/values/WEIGHT");
|
||||
const link = page.locator('[data-slot="day-link"]:visible').first();
|
||||
await expect(link).toBeVisible();
|
||||
const day = await link.getAttribute("data-day");
|
||||
if (isPhone(testInfo)) await link.tap();
|
||||
else await link.click();
|
||||
await expect(page.locator('[data-slot="day-view"]')).toHaveAttribute(
|
||||
"data-day",
|
||||
day!,
|
||||
);
|
||||
});
|
||||
|
||||
test("the docked day moves the Coach button off its footer", async ({
|
||||
page,
|
||||
}, testInfo) => {
|
||||
test.skip(isPhone(testInfo), "docked from 1280 px");
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
// The launcher follows the `coach` capability, which needs a provider
|
||||
// the suite cannot reach, so the capability reads available here; this
|
||||
// journey is about where the button sits, not what it opens.
|
||||
await serveAiBlock(page, aiBlockAvailable());
|
||||
await page.goto("/insights/weight");
|
||||
const fab = page.locator('[data-slot="coach-fab"]');
|
||||
await expect(fab).toBeVisible();
|
||||
const plot = page
|
||||
.locator('[data-slot="chart-plot"][data-day-links="true"]')
|
||||
.first();
|
||||
await openFromPlot(page, plot, testInfo);
|
||||
const panelBox = (await panel(page).boundingBox())!;
|
||||
// Wait out the 150 ms move, then the launcher sits left of the column.
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const b = (await fab.boundingBox())!;
|
||||
return b.x + b.width;
|
||||
})
|
||||
.toBeLessThanOrEqual(panelBox.x);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("the readiness link into a medication's edit form", () => {
|
||||
test.use({ storageState: MOBILE_ROUTES_STORAGE_STATE_PATH });
|
||||
|
||||
test("?edit=1 opens the medication's edit form and leaves the URL", async ({
|
||||
page,
|
||||
}) => {
|
||||
const res = await page.request.get("/api/medications");
|
||||
const body = (await res.json()) as {
|
||||
data: Array<{ id: string }> | { medications?: Array<{ id: string }> };
|
||||
};
|
||||
const list = Array.isArray(body.data)
|
||||
? body.data
|
||||
: (body.data.medications ?? []);
|
||||
expect(list.length).toBeGreaterThan(0);
|
||||
await page.goto(`/medications/${list[0]!.id}?edit=1`);
|
||||
await expect(page.getByRole("dialog")).toBeVisible();
|
||||
// A reload after closing the form must not open it again.
|
||||
await expect(page).not.toHaveURL(/[?&]edit=1/);
|
||||
});
|
||||
});
|
||||
+13
-87
@@ -1,5 +1,6 @@
|
||||
import type { Page, Route } from "@playwright/test";
|
||||
import type { Page } from "@playwright/test";
|
||||
|
||||
import { mockDay } from "./setup/day-mock";
|
||||
import { expect, test } from "./setup/test";
|
||||
import { MOBILE_ROUTES_STORAGE_STATE_PATH } from "./setup/global-setup";
|
||||
import { MOBILE_ROUTES_ANALYTE } from "./setup/mobile-routes-fixture";
|
||||
@@ -20,97 +21,13 @@ import { MOBILE_ROUTES_ANALYTE } from "./setup/mobile-routes-fixture";
|
||||
* - `?day=` opens the layer on any page, Back and Escape close it, a date in
|
||||
* the future is dropped;
|
||||
* - stepping to the neighbouring days never adds history entries;
|
||||
* - the dashboard's today area offers no door.
|
||||
* - the dashboard's today area offers no door; its charts below do.
|
||||
*
|
||||
* Stable data attributes only: `day-panel` (+ `data-shell`), `day-link`,
|
||||
* `chart-plot[data-day-links]`, `chart-tooltip-open-day`, `day-prev` /
|
||||
* `day-next` / `day-close`.
|
||||
*/
|
||||
|
||||
function dayFixture(date: string) {
|
||||
return {
|
||||
date,
|
||||
tz: "Europe/Berlin",
|
||||
counts: { values: 2, entries: 1 },
|
||||
running: [
|
||||
{
|
||||
kind: "illness",
|
||||
section: "illness",
|
||||
id: "ep1",
|
||||
title: "Common cold",
|
||||
sub: null,
|
||||
since: date,
|
||||
until: null,
|
||||
dayIndex: 1,
|
||||
dayCount: null,
|
||||
href: "/illness",
|
||||
},
|
||||
],
|
||||
values: [
|
||||
{
|
||||
type: "BLOOD_PRESSURE_SYS",
|
||||
value: 124,
|
||||
unit: "mmHg",
|
||||
at: `${date}T07:00:00.000Z`,
|
||||
source: "MANUAL",
|
||||
band: { lo: 118, hi: 128, n: 20 },
|
||||
},
|
||||
{
|
||||
type: "BLOOD_PRESSURE_DIA",
|
||||
value: 79,
|
||||
unit: "mmHg",
|
||||
at: `${date}T07:00:00.000Z`,
|
||||
source: "MANUAL",
|
||||
band: { lo: 76, hi: 82, n: 20 },
|
||||
},
|
||||
],
|
||||
events: [
|
||||
{
|
||||
at: `${date}T07:00:00.000Z`,
|
||||
kind: "mood",
|
||||
section: "mood",
|
||||
id: "m1",
|
||||
title: "Mood: good",
|
||||
meta: null,
|
||||
note: null,
|
||||
docs: [],
|
||||
href: "/mood",
|
||||
},
|
||||
],
|
||||
notable: [],
|
||||
sections: {},
|
||||
};
|
||||
}
|
||||
|
||||
async function mockDay(page: Page) {
|
||||
await page.route("**/api/day/**", async (route: Route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname === "/api/day/index") {
|
||||
const from = url.searchParams.get("from") ?? "";
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
from,
|
||||
to: url.searchParams.get("to") ?? "",
|
||||
days: {},
|
||||
notable: [],
|
||||
},
|
||||
error: null,
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
const date = url.pathname.split("/").pop() ?? "";
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ data: dayFixture(date), error: null }),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const panel = (page: Page) => page.locator('[data-slot="day-panel"]');
|
||||
|
||||
function isoDaysAgo(days: number): string {
|
||||
@@ -252,6 +169,8 @@ test.describe("the day view", () => {
|
||||
await open.tap();
|
||||
await expect(panel(page)).toBeVisible();
|
||||
await expect(panel(page)).toHaveAttribute("data-shell", "bottom");
|
||||
// The tapped value heads the day.
|
||||
await expect(page.locator('[data-slot="day-focus"]')).toBeVisible();
|
||||
});
|
||||
|
||||
test("the dashboard's today area offers no day door", async ({ page }) => {
|
||||
@@ -259,8 +178,15 @@ test.describe("the day view", () => {
|
||||
await expect(
|
||||
page.locator('[data-slot="main-content-wrapper"]'),
|
||||
).toBeVisible();
|
||||
// The hero is today: nothing in it opens another day. (The charts
|
||||
// further down do; `day-doors.spec.ts` walks one.)
|
||||
await expect(
|
||||
page.locator('[data-slot="chart-plot"][data-day-links="true"]'),
|
||||
page.locator('[data-slot^="today-hero"]').first(),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.locator(
|
||||
'[data-slot^="today-hero"] [data-slot="day-link"], [data-slot^="today-hero"] [data-day-links="true"]',
|
||||
),
|
||||
).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
@@ -48,6 +48,8 @@ const NOT_SIGNED_IN: Record<string, string> = {
|
||||
"/invite/[token]":
|
||||
"an invitation landing page for somebody without an account",
|
||||
"/c/[token]": "the clinician share-link page, opened without a session",
|
||||
"/claim/[token]":
|
||||
"the managed-profile handover link, opened by the person without a session (covered by v142-managed-profile-handover.spec.ts)",
|
||||
"/confirm-access": "the re-proof page, reached only from a stale session",
|
||||
"/enroll-mfa": "the forced second-factor enrolment of a policy-bound account",
|
||||
"/onboarding": "the first-run setup flow; covered by setup-flow-*.spec.ts",
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* The record `day-doors.spec.ts` opens days from.
|
||||
*
|
||||
* Every chart the journey clicks needs points to click: ten days of the
|
||||
* autonomic charge (the recovery page), of sleep and of mood (the sleep
|
||||
* chart, the mood line and the mood calendar), weight over the last ten days
|
||||
* and the same ten days a month earlier (the comparison chart draws a prior
|
||||
* period only where one exists), and two readings of one lab marker.
|
||||
*
|
||||
* Written through the app's own routes, once, from `globalSetup`. An account
|
||||
* that already holds the lab marker is taken as seeded, so a local re-run
|
||||
* against a reused database does not double every row.
|
||||
*/
|
||||
import { request as playwrightRequest } from "@playwright/test";
|
||||
|
||||
export const DAY_DOORS_ANALYTE = "Ferritin";
|
||||
|
||||
export async function seedDayDoorsRecord(
|
||||
baseURL: string,
|
||||
storageStatePath: string,
|
||||
): Promise<void> {
|
||||
const ctx = await playwrightRequest.newContext({
|
||||
baseURL,
|
||||
storageState: storageStatePath,
|
||||
});
|
||||
try {
|
||||
const labs = await ctx.get("/api/labs");
|
||||
const body = (await labs.json()) as { data: unknown };
|
||||
if (JSON.stringify(body.data ?? null).includes(DAY_DOORS_ANALYTE)) return;
|
||||
|
||||
const post = async (path: string, data: unknown): Promise<void> => {
|
||||
const res = await ctx.post(path, { data });
|
||||
if (res.status() === 409 || res.ok()) return;
|
||||
throw new Error(
|
||||
`[day-doors-fixture] ${path} answered ${res.status()}: ${(await res.text()).slice(0, 200)}`,
|
||||
);
|
||||
};
|
||||
const daysAgo = (days: number, hour = 8) => {
|
||||
const at = new Date(Date.now() - days * 86_400_000);
|
||||
at.setUTCHours(hour, 0, 0, 0);
|
||||
return at.toISOString();
|
||||
};
|
||||
|
||||
for (let day = 1; day <= 10; day += 1) {
|
||||
await post("/api/measurements", {
|
||||
type: "ANS_CHARGE",
|
||||
value: 5 + day,
|
||||
measuredAt: daysAgo(day, 5),
|
||||
});
|
||||
await post("/api/measurements", {
|
||||
type: "SLEEP_DURATION",
|
||||
value: 400 + day * 4,
|
||||
measuredAt: daysAgo(day, 6),
|
||||
});
|
||||
await post("/api/measurements", {
|
||||
type: "WEIGHT",
|
||||
value: 72 + day / 10,
|
||||
measuredAt: daysAgo(day, 7),
|
||||
});
|
||||
// The same ten days, a month before: the prior period the comparison
|
||||
// draws beside them.
|
||||
await post("/api/measurements", {
|
||||
type: "WEIGHT",
|
||||
value: 73 + day / 10,
|
||||
measuredAt: daysAgo(day + 30, 7),
|
||||
});
|
||||
await post("/api/mood-entries", {
|
||||
mood: day % 2 ? "GUT" : "OKAY",
|
||||
moodLoggedAt: daysAgo(day, 19),
|
||||
});
|
||||
}
|
||||
|
||||
for (const [days, value] of [
|
||||
[60, 41],
|
||||
[4, 58],
|
||||
] as const) {
|
||||
await post("/api/labs", {
|
||||
analyte: DAY_DOORS_ANALYTE,
|
||||
panel: "Eisenstoffwechsel",
|
||||
value,
|
||||
unit: "ng/mL",
|
||||
referenceLow: 30,
|
||||
referenceHigh: 300,
|
||||
takenAt: daysAgo(days),
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
await ctx.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/**
|
||||
* The day routes, answered in the contract's shape.
|
||||
*
|
||||
* The day itself (`GET /api/day/{date}`) and the index (`GET /api/day/index`)
|
||||
* are route mocks, so a journey pins the client: which door opens which day,
|
||||
* what the history does, where no door is. The server's own answers are
|
||||
* pinned by the integration suite.
|
||||
*/
|
||||
import type { Page, Route } from "@playwright/test";
|
||||
|
||||
function dayFixture(date: string) {
|
||||
return {
|
||||
date,
|
||||
tz: "Europe/Berlin",
|
||||
counts: { values: 2, entries: 1 },
|
||||
running: [
|
||||
{
|
||||
kind: "illness",
|
||||
section: "illness",
|
||||
id: "ep1",
|
||||
title: "Common cold",
|
||||
sub: null,
|
||||
since: date,
|
||||
until: null,
|
||||
dayIndex: 1,
|
||||
dayCount: null,
|
||||
href: "/illness",
|
||||
},
|
||||
],
|
||||
values: [
|
||||
{
|
||||
type: "BLOOD_PRESSURE_SYS",
|
||||
value: 124,
|
||||
unit: "mmHg",
|
||||
at: `${date}T07:00:00.000Z`,
|
||||
source: "MANUAL",
|
||||
band: { lo: 118, hi: 128, n: 20 },
|
||||
},
|
||||
{
|
||||
type: "BLOOD_PRESSURE_DIA",
|
||||
value: 79,
|
||||
unit: "mmHg",
|
||||
at: `${date}T07:00:00.000Z`,
|
||||
source: "MANUAL",
|
||||
band: { lo: 76, hi: 82, n: 20 },
|
||||
},
|
||||
],
|
||||
events: [
|
||||
{
|
||||
at: `${date}T07:00:00.000Z`,
|
||||
kind: "mood",
|
||||
section: "mood",
|
||||
id: "m1",
|
||||
title: "Mood: good",
|
||||
meta: null,
|
||||
note: null,
|
||||
docs: [],
|
||||
href: "/mood",
|
||||
},
|
||||
],
|
||||
notable: [],
|
||||
sections: {},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Every day from `from` to `to`, each holding values: what the row of day
|
||||
* dots under a chart reads when the whole window has entries.
|
||||
*/
|
||||
function everyDay(from: string, to: string): Record<string, string[]> {
|
||||
const days: Record<string, string[]> = {};
|
||||
if (!from || !to) return days;
|
||||
const at = new Date(`${from}T12:00:00.000Z`);
|
||||
const end = new Date(`${to}T12:00:00.000Z`);
|
||||
while (at <= end) {
|
||||
days[at.toISOString().slice(0, 10)] = ["values"];
|
||||
at.setUTCDate(at.getUTCDate() + 1);
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
export async function mockDay(
|
||||
page: Page,
|
||||
options: { index?: "empty" | "full" } = {},
|
||||
) {
|
||||
await page.route("**/api/day/**", async (route: Route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (url.pathname === "/api/day/index") {
|
||||
const from = url.searchParams.get("from") ?? "";
|
||||
const to = url.searchParams.get("to") ?? "";
|
||||
const days = options.index === "full" ? everyDay(from, to) : {};
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({
|
||||
data: {
|
||||
from,
|
||||
to,
|
||||
days,
|
||||
// The first day of the window stands out: the rug draws a ring.
|
||||
notable: Object.keys(days).slice(0, 1),
|
||||
},
|
||||
error: null,
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
const date = url.pathname.split("/").pop() ?? "";
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: "application/json",
|
||||
body: JSON.stringify({ data: dayFixture(date), error: null }),
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import {
|
||||
} from "@playwright/test";
|
||||
import pg from "pg";
|
||||
|
||||
import { seedDayDoorsRecord } from "./day-doors-fixture";
|
||||
import { seedMobileRoutesRecord } from "./mobile-routes-fixture";
|
||||
|
||||
// Resolve relative to the project root rather than __dirname/import.meta.url —
|
||||
@@ -249,6 +250,26 @@ export const TIMELINE_STORAGE_STATE_PATH = resolve(
|
||||
"e2e/setup/storageStateTimeline.json",
|
||||
);
|
||||
|
||||
/**
|
||||
* The day-doors journey's own account (`day-doors.spec.ts`).
|
||||
*
|
||||
* It turns a chart's comparison overlay on, which is a per-account
|
||||
* preference; on a shared account a parallel spec would find its chart
|
||||
* drawing a prior period it never asked for. Its record carries the series
|
||||
* the journey clicks (recovery, sleep, mood, weight, a lab marker).
|
||||
*/
|
||||
export const E2E_DAY_DOORS = {
|
||||
email: "e2e-day-doors@healthlog.test",
|
||||
username: "e2e-day-doors",
|
||||
password: "Dy4!Rk8wQm2vTz6P",
|
||||
role: "USER",
|
||||
} as const;
|
||||
|
||||
export const DAY_DOORS_STORAGE_STATE_PATH = resolve(
|
||||
process.cwd(),
|
||||
"e2e/setup/storageStateDayDoors.json",
|
||||
);
|
||||
|
||||
export const AI_OPTIONAL_STORAGE_STATE_PATH = resolve(
|
||||
process.cwd(),
|
||||
"e2e/setup/storageStateAiOptional.json",
|
||||
@@ -950,6 +971,30 @@ export default async function globalSetup(config: FullConfig): Promise<void> {
|
||||
],
|
||||
);
|
||||
|
||||
// The day-doors journey's account. Every module the journey reaches is
|
||||
// on; its record is written after the login capture.
|
||||
await pool.query(
|
||||
`INSERT INTO users
|
||||
(id, username, email, password_hash, role, created_at, updated_at,
|
||||
onboarding_completed_at, onboarding_tour_completed,
|
||||
module_preferences_json)
|
||||
VALUES ($1, $2, $3, $4, 'USER', $5, $5, $5, true, NULL)
|
||||
ON CONFLICT (username) DO UPDATE SET
|
||||
email = EXCLUDED.email,
|
||||
password_hash = EXCLUDED.password_hash,
|
||||
updated_at = EXCLUDED.updated_at,
|
||||
onboarding_completed_at = EXCLUDED.onboarding_completed_at,
|
||||
onboarding_tour_completed = EXCLUDED.onboarding_tour_completed,
|
||||
module_preferences_json = NULL`,
|
||||
[
|
||||
cuid(),
|
||||
E2E_DAY_DOORS.username,
|
||||
E2E_DAY_DOORS.email,
|
||||
await hashPassword(E2E_DAY_DOORS.password),
|
||||
now,
|
||||
],
|
||||
);
|
||||
|
||||
// The notification-dispatch journey's account. Seeded like the others;
|
||||
// its channels, devices, ledger rows and preferences are reset by
|
||||
// `e2e/setup/notification-fixture.ts` before every test, because the
|
||||
@@ -1556,6 +1601,10 @@ export default async function globalSetup(config: FullConfig): Promise<void> {
|
||||
// The timeline journey's jar — see `E2E_TIMELINE`.
|
||||
await capture(E2E_TIMELINE, TIMELINE_STORAGE_STATE_PATH);
|
||||
|
||||
// The day-doors journey's jar, then its record — see `E2E_DAY_DOORS`.
|
||||
await capture(E2E_DAY_DOORS, DAY_DOORS_STORAGE_STATE_PATH);
|
||||
await seedDayDoorsRecord(baseURL, DAY_DOORS_STORAGE_STATE_PATH);
|
||||
|
||||
await capture(E2E_SCOPE_DELEGATE, SCOPE_DELEGATE_STORAGE_STATE_PATH);
|
||||
await capture(E2E_SCOPE_DELEGATE, SCOPE_A11Y_STORAGE_STATE_PATH);
|
||||
await capture(E2E_SCOPE_DELEGATE, SCOPE_CAPABILITIES_STORAGE_STATE_PATH);
|
||||
|
||||
@@ -319,7 +319,9 @@ test.describe("mood insights", () => {
|
||||
const watch = () => {
|
||||
if (
|
||||
!w.__seen.heatmap &&
|
||||
document.querySelector('[data-slot="mood-heatmap-day-list"]')
|
||||
document.querySelector(
|
||||
'[data-slot="mood-heatmap-body"] svg[role="img"]',
|
||||
)
|
||||
)
|
||||
w.__seen.heatmap = performance.now();
|
||||
if (
|
||||
@@ -339,7 +341,7 @@ test.describe("mood insights", () => {
|
||||
|
||||
await page.goto("/insights/mood");
|
||||
await expect(
|
||||
page.locator('[data-slot="mood-heatmap-day-list"]'),
|
||||
page.locator('[data-slot="mood-heatmap-body"] svg[role="img"]'),
|
||||
).toBeAttached({
|
||||
timeout: 15_000,
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user