test(labs): pin the lab scan's waiting line to the copy that does not promise the page can be left

This commit is contained in:
Marc-André Bombeck committed 2026-10-03 23:13:59 +02:00
1 parent 367a1bb4b4
commit 0100256c60
1 file changed
+34 -1
@@ -15,7 +15,10 @@ import {
unitSkippedAnalytes,
} from "../ocr-review-dialog";
const hookState = vi.hoisted(() => ({ extractPending: false }));
const hookState = vi.hoisted(() => ({
extractPending: false,
runPhase: "idle" as "idle" | "running" | "waitingForWorker",
}));
vi.mock("@/components/ui/responsive-sheet", () => ({
ResponsiveSheet: ({
@@ -37,6 +40,7 @@ vi.mock("@/components/ui/responsive-sheet", () => ({
vi.mock("../use-ocr-extract", () => ({
useOcrExtract: () => ({
isPending: hookState.extractPending,
runPhase: hookState.runPhase,
mutate: vi.fn(),
reset: vi.fn(),
}),
@@ -174,6 +178,35 @@ describe("<OcrReviewDialog> document-reading consent", () => {
});
});
/**
* A lab scan's proposed rows live only in its run: nothing is stored until
* the person confirms them here. So the waiting line must not promise that
* the page can be left (the result would be lost, and a second scan costs
* another rate slot). Mutation check: swap `aiRuns.backgroundScan` for
* `aiRuns.backgroundDocument` in the dialog → both cases go red.
*/
describe("<OcrReviewDialog> background read", () => {
afterEach(() => {
hookState.extractPending = false;
hookState.runPhase = "idle";
});
it.each([
["en", "With a slow model", "leave this page"],
["de", "Mit einem langsamen Modell", "Seite verlassen"],
] as const)(
"(%s) says it reads in the background, never that the page can be left",
(locale, expected, forbidden) => {
hookState.extractPending = true;
hookState.runPhase = "running";
const html = render(locale);
expect(html).toContain('data-slot="ocr-run-phase"');
expect(html).toContain(expected);
expect(html).not.toContain(forbidden);
},
);
});
describe("extractErrorMessage", () => {
const t = (key: string) => key;
const refusal = (errorCode: string, status = 403) =>