citation-evidence/tests/integration/forms-field-values.dom.test.tsx
tegwick d14514891e refactor(anchor): consume extracted evidence-anchor package (EANCH-WP-0001-T05)
Replace the in-repo src/anchor/ slice with a dependency on the extracted
@citation-evidence/evidence-anchor package (link:../evidence-anchor).

- package.json: add the link dependency
- repoint all @anchor/{index,selectors,types} imports and vi.mock targets to
  the package barrel; the node-env anchor-source-roundtrip test uses the pure
  ./selectors and ./types subpaths (no pdfjs pulled into a node environment)
- drop the @anchor alias from tsconfig paths and vite resolve
- delete src/anchor/ (behavior now owned by evidence-anchor)

Verified green: pnpm typecheck, pnpm test (26 files / 95 tests), pnpm build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 21:08:27 +02:00

73 lines
No EOL
2.3 KiB
TypeScript

/**
* CE-WP-0008-T01 — capture form field values persist across re-renders.
*/
// @vitest-environment happy-dom
import { cleanup, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import manifest from "../../fixtures/pdfs/manifest.json" with { type: "json" };
vi.mock("@citation-evidence/evidence-anchor", async (importOriginal) => {
const original = await importOriginal<typeof import("@citation-evidence/evidence-anchor")>();
const MockPdfSpikeViewer = () => (
<div data-testid="mock-pdf-viewer" />
);
return { ...original, PdfSpikeViewer: MockPdfSpikeViewer };
});
const FIXTURE = manifest.fixtures.find((f) => f.id === "fristsetzung-bezifferung")!;
const SYNTHETIC_CANONICAL = ["Pre.", FIXTURE.known_good_quote, "Post."].join(" ");
import { seedSessionWithDoc } from "./helpers/seed-session";
async function loadApp() {
const { App } = await import("@app/App");
return render(<App />);
}
describe("Capture — field value persistence (CE-WP-0008-T01)", () => {
beforeEach(() => {
globalThis.localStorage?.clear();
if (typeof window !== "undefined") {
history.replaceState(null, "", window.location.pathname);
}
seedSessionWithDoc({
sessionName: "T01-field-values",
documentTitle: FIXTURE.filename,
canonicalText: SYNTHETIC_CANONICAL,
mode: "forms",
});
});
afterEach(() => {
vi.restoreAllMocks();
cleanup();
});
it("keeps typed text after focusing another field", { timeout: 15000 }, async () => {
const user = userEvent.setup();
await loadApp();
const summary = screen.getByLabelText("Summary of the matter");
await user.type(summary, "Tenant owes arrears");
await user.click(screen.getByLabelText("Disputed amount"));
await user.click(summary);
expect((summary as HTMLTextAreaElement).value).toBe("Tenant owes arrears");
});
it("keeps a selected date after blur", { timeout: 15000 }, async () => {
const user = userEvent.setup();
await loadApp();
const deadline = screen.getByLabelText("Key deadline") as HTMLInputElement;
await user.clear(deadline);
await user.type(deadline, "2026-12-15");
await user.click(screen.getByLabelText("Disputed amount"));
expect(deadline.value).toBe("2026-12-15");
});
});