mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
Merge remote-tracking branch 'origin/feat/documents-procedure-filter' into release/v1.40.2
This commit is contained in:
commit
03c43ef70a
24 files changed
+1308
-54
No files matched your search
@@ -0,0 +1,131 @@
|
||||
/**
|
||||
* Document vault — the procedure filter.
|
||||
*
|
||||
* The facet beside the condition filter: it lists the procedures that hold a
|
||||
* document, labelled the way the visits page heads them, narrows the list to
|
||||
* one procedure's documents through the real `encounterId` filter, writes the
|
||||
* choice to the URL (`?encounter=`), comes back from a deep link, and clears
|
||||
* with the one clear control. Run at a 1440 px desktop and a 390 px phone,
|
||||
* where the filter row must stay a single line with no sideways scroll.
|
||||
*
|
||||
* Fixture: `ensureProcedureFixture` (two procedures over a namespaced trio of
|
||||
* documents), upserted before every test because the visits spec clears the
|
||||
* account's visits; the dates sit far outside that spec's ±7-day window.
|
||||
*/
|
||||
import type { Page } from "@playwright/test";
|
||||
import { expect, test } from "./setup/test";
|
||||
|
||||
import { STORAGE_STATE_PATH } from "./setup/global-setup";
|
||||
import {
|
||||
ensureProcedureFixture,
|
||||
ensureVaultFixture,
|
||||
PROCEDURE_DOC_PREFIX,
|
||||
PROCEDURE_KNEE_ID,
|
||||
} from "./setup/vault-fixture";
|
||||
|
||||
function card(page: Page, n: number) {
|
||||
return page
|
||||
.getByRole("button", {
|
||||
name: `Open ${PROCEDURE_DOC_PREFIX} ${String(n).padStart(3, "0")}`,
|
||||
})
|
||||
.first();
|
||||
}
|
||||
|
||||
/** The filter row is one line and never scrolls sideways. */
|
||||
async function expectOneRow(page: Page) {
|
||||
const bar = page.locator('[data-slot="document-filter-bar"]');
|
||||
const row = bar.locator("> div").first();
|
||||
const box = await row.boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
expect(box!.height).toBeLessThan(48);
|
||||
const overflow = await page.evaluate(
|
||||
() => document.documentElement.scrollWidth - window.innerWidth,
|
||||
);
|
||||
expect(overflow).toBeLessThanOrEqual(0);
|
||||
}
|
||||
|
||||
async function shot(page: Page, name: string, isMobile: boolean) {
|
||||
const dir = process.env.E2E_SHOT_DIR;
|
||||
if (!dir) return;
|
||||
await page.screenshot({
|
||||
path: `${dir}/${name}-${isMobile ? "390" : "1440"}.png`,
|
||||
animations: "disabled",
|
||||
});
|
||||
}
|
||||
|
||||
test.describe("document vault — procedure filter", () => {
|
||||
test.use({ storageState: STORAGE_STATE_PATH });
|
||||
|
||||
test.beforeAll(async () => {
|
||||
await ensureVaultFixture();
|
||||
});
|
||||
|
||||
test.beforeEach(async ({ page, isMobile }) => {
|
||||
await ensureProcedureFixture();
|
||||
await page.setViewportSize(
|
||||
isMobile ? { width: 390, height: 844 } : { width: 1440, height: 900 },
|
||||
);
|
||||
});
|
||||
|
||||
test("picks a procedure, narrows to its documents, and clears", async ({
|
||||
page,
|
||||
isMobile,
|
||||
}) => {
|
||||
await page.goto(`/documents?q=${PROCEDURE_DOC_PREFIX}`);
|
||||
await expect(card(page, 3)).toBeVisible();
|
||||
await expect(card(page, 1)).toBeVisible();
|
||||
|
||||
const trigger = page.locator('[data-slot="document-procedure-filter"]');
|
||||
await expect(trigger).toBeVisible();
|
||||
await expect(trigger).toHaveAttribute("aria-label", "All procedures");
|
||||
await expectOneRow(page);
|
||||
await shot(page, "procedure-filter-idle", isMobile);
|
||||
|
||||
await trigger.click();
|
||||
const menu = page.getByRole("menu");
|
||||
await expect(menu).toBeVisible();
|
||||
await expect(menu).toContainText("Procedures and surgeries");
|
||||
// Headed like the visits page, with the body site and side beneath.
|
||||
const knee = menu.getByRole("menuitemcheckbox", {
|
||||
name: /Knee arthroscopy/,
|
||||
});
|
||||
await expect(knee).toContainText("Knee · Left");
|
||||
await expect(
|
||||
menu.getByRole("menuitemcheckbox", { name: /Appendectomy/ }),
|
||||
).toBeVisible();
|
||||
await shot(page, "procedure-filter-menu", isMobile);
|
||||
await knee.click();
|
||||
|
||||
await expect(page).toHaveURL(new RegExp(`encounter=${PROCEDURE_KNEE_ID}`));
|
||||
await expect(card(page, 1)).toBeVisible();
|
||||
await expect(card(page, 2)).toBeVisible();
|
||||
await expect(card(page, 3)).toHaveCount(0);
|
||||
await expect(trigger).toHaveAttribute("aria-label", "Knee arthroscopy");
|
||||
// Picked: the label shows at every width, phone included.
|
||||
await expect(trigger).toContainText("Knee arthroscopy");
|
||||
await expectOneRow(page);
|
||||
// The search field never collapses under the facets.
|
||||
const search = await page
|
||||
.getByRole("searchbox", { name: "Search documents" })
|
||||
.boundingBox();
|
||||
expect(search!.width).toBeGreaterThanOrEqual(48);
|
||||
await shot(page, "procedure-filter-active", isMobile);
|
||||
|
||||
await page.getByRole("button", { name: "Clear filters" }).click();
|
||||
await expect(page).not.toHaveURL(/encounter=/);
|
||||
await expect(trigger).toHaveAttribute("aria-label", "All procedures");
|
||||
});
|
||||
|
||||
test("a deep link lands filtered and the facet names the procedure", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto(
|
||||
`/documents?q=${PROCEDURE_DOC_PREFIX}&encounter=${PROCEDURE_KNEE_ID}`,
|
||||
);
|
||||
await expect(card(page, 2)).toBeVisible();
|
||||
await expect(card(page, 3)).toHaveCount(0);
|
||||
await expect(
|
||||
page.locator('[data-slot="document-procedure-filter"]'),
|
||||
).toHaveAttribute("aria-label", "Knee arthroscopy");
|
||||
});
|
||||
});
|
||||
@@ -550,6 +550,81 @@ export async function seedNamespaceDocs(
|
||||
}
|
||||
}
|
||||
|
||||
/** The procedure-filter fixture: two procedures, each with its own files. */
|
||||
export const PROCEDURE_KNEE_ID = "e2eprocknee0000000000001";
|
||||
export const PROCEDURE_APPENDIX_ID = "e2eprocappx0000000000001";
|
||||
export const PROCEDURE_DOC_PREFIX = "procfilter";
|
||||
|
||||
/**
|
||||
* Seed the procedure-filter fixture: three namespaced documents and two
|
||||
* procedures — a knee arthroscopy (reason + body site + side) holding two of
|
||||
* them, and an appendectomy holding the third. Dated far from the MRT report
|
||||
* so the visits spec's ±7-day window never sees them. Idempotent: the rows
|
||||
* upsert by fixed id and come back live, so a `resetEncounters` from the visits
|
||||
* spec between runs is repaired by the next call.
|
||||
*/
|
||||
export async function ensureProcedureFixture(): Promise<void> {
|
||||
const url = process.env.DATABASE_URL;
|
||||
if (!url) throw new Error("[vault-fixture] DATABASE_URL is not set");
|
||||
await seedNamespaceDocs(PROCEDURE_DOC_PREFIX, 3);
|
||||
const pool = new pg.Pool({ connectionString: url });
|
||||
try {
|
||||
const userId = await getUserId(pool);
|
||||
const procedures = [
|
||||
{
|
||||
id: PROCEDURE_KNEE_ID,
|
||||
at: "2024-03-12T08:00:00Z",
|
||||
reason: "Knee arthroscopy",
|
||||
site: "Knee",
|
||||
side: "LEFT",
|
||||
docs: [0, 1],
|
||||
},
|
||||
{
|
||||
id: PROCEDURE_APPENDIX_ID,
|
||||
at: "2023-06-20T08:00:00Z",
|
||||
reason: "Appendectomy",
|
||||
site: null,
|
||||
side: null,
|
||||
docs: [2],
|
||||
},
|
||||
];
|
||||
for (const p of procedures) {
|
||||
await pool.query(
|
||||
`INSERT INTO encounters
|
||||
(id, user_id, occurred_at, status, kind, reason_encrypted,
|
||||
body_site_encrypted, laterality, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, 'DONE', 'PROCEDURE', $4, $5, $6::laterality, NOW(), NOW())
|
||||
ON CONFLICT (id) DO UPDATE SET
|
||||
occurred_at = EXCLUDED.occurred_at, kind = 'PROCEDURE',
|
||||
status = 'DONE', reason_encrypted = EXCLUDED.reason_encrypted,
|
||||
body_site_encrypted = EXCLUDED.body_site_encrypted,
|
||||
laterality = EXCLUDED.laterality, deleted_at = NULL,
|
||||
updated_at = NOW()`,
|
||||
[
|
||||
p.id,
|
||||
userId,
|
||||
p.at,
|
||||
encryptStringToBytes(p.reason),
|
||||
p.site ? encryptStringToBytes(p.site) : null,
|
||||
p.side,
|
||||
],
|
||||
);
|
||||
for (const n of p.docs) {
|
||||
const docId = `e2e${PROCEDURE_DOC_PREFIX}${String(n).padStart(8, "0")}`;
|
||||
await pool.query(
|
||||
`INSERT INTO encounter_document_links
|
||||
(id, encounter_id, document_id, user_id, created_at)
|
||||
VALUES ($1, $2, $3, $4, NOW())
|
||||
ON CONFLICT (encounter_id, document_id) DO NOTHING`,
|
||||
[`${p.id.slice(0, 16)}lnk${n}`, p.id, docId, userId],
|
||||
);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* v1.28 — seed the clinician-share document trio (see the `SHARE_*_DOC_ID`
|
||||
* constants). Enables the vault module for the e2e user and upserts one
|
||||
|
||||
Reference in new issue
Block a user