e2e/post-demo.spec.ts
Linked repository file from this build.
import { resetDemoFixture } from "./demo-fixture";
import { expect, test, type APIRequestContext } from "@playwright/test";
import type { ReviewCommand } from "../src/features/reviews/commands";
import { enterMoney } from "./money-input";
async function change(request: APIRequestContext, command: ReviewCommand) {
const stored = await (
await request.get("/api/reviews/aa1635c0-c99d-5f12-8f26-54d3f23bf13d")
).json();
const response = await request.post("/api/reviews/aa1635c0-c99d-5f12-8f26-54d3f23bf13d", {
data: {
version: stored.version,
requestId: crypto.randomUUID(),
commands: [
{
command,
id: crypto.randomUUID(),
},
],
},
});
expect(response.ok(), await response.text()).toBe(true);
}
test("undo survives Save, tab changes, Clear and Reset", async ({ page, request }) => {
await resetDemoFixture();
await change(request, { type: "reset_demo" });
await page.goto("/reviews/aa1635c0-c99d-5f12-8f26-54d3f23bf13d");
const name = page.locator("#client-name");
await expect(name).toHaveValue("Sarah Evans");
await name.fill("Before clear");
await page.getByRole("button", { name: "Save review", exact: true }).click();
await expect(page.getByText("Unsaved changes", { exact: true })).toHaveCount(0);
await page.getByRole("tab", { name: "Review", exact: true }).click();
await page.getByRole("tab", { name: "Household", exact: true }).click();
await page.keyboard.press("Control+z");
await expect(name).toHaveValue("Sarah Evans");
await name.fill("Before clear");
page.on("dialog", (dialog) => dialog.accept());
await page.getByRole("button", { name: "Clear all", exact: true }).click();
await expect(name).toHaveValue("");
await page.keyboard.press("Control+z");
await expect(name).toHaveValue("Before clear");
await page.getByRole("button", { name: "Reset all", exact: true }).click();
await expect(name).toHaveValue("Sarah Evans");
await page.keyboard.press("Control+z");
await expect(name).toHaveValue("Before clear");
});
test("saved computation can be undone and income foldout accepts farm loss", async ({
page,
request,
}) => {
await resetDemoFixture();
await change(request, { type: "reset_demo" });
await page.goto("/reviews/aa1635c0-c99d-5f12-8f26-54d3f23bf13d");
await page.getByRole("tab", { name: "Computation", exact: true }).click();
const size = page.getByLabel("Comp I Household size", { exact: true });
await size.fill("3");
await size.blur();
await page.getByRole("button", { name: "Save Comp I column", exact: true }).click();
await page.getByRole("tab", { name: "Review", exact: true }).click();
await page.getByRole("tab", { name: "Computation", exact: true }).click();
await page.keyboard.press("Control+z");
await expect(size).toHaveValue("");
await page.getByRole("button", { name: "Add income", exact: true }).nth(1).click();
const dialog = page.getByRole("dialog", { name: "Add income", exact: true });
await expect(dialog).toBeVisible();
await expect(page.locator('table [role="dialog"]')).toHaveCount(0);
await page.getByLabel("Income type code", { exact: true }).fill("11");
await page.getByLabel("Income category", { exact: true }).selectOption("self_employment");
await page.getByLabel("Self-employment kind", { exact: true }).selectOption("farm");
await enterMoney(page.getByLabel("Monthly gross", { exact: true }), "100.00");
await enterMoney(page.getByLabel("Monthly costs", { exact: true }), "200.00");
await page.getByLabel("Monthly costs", { exact: true }).blur();
await expect(page.getByText("Net loss: $100.00", { exact: true })).toBeVisible();
await page.getByRole("button", { name: "Confirm", exact: true }).click();
await expect(dialog).toHaveCount(0);
await expect(page.getByText("−$100.00", { exact: true })).toBeVisible();
await page.getByRole("button").filter({ hasText: "−$100.00" }).click();
await expect(page.getByRole("dialog", { name: "Edit income", exact: true })).toBeVisible();
await page.keyboard.press("Escape");
await expect(page.getByRole("dialog")).toHaveCount(0);
});
test("Policy uses the shared navigation and toolbar", async ({ page, context }) => {
await context.addCookies([
{ name: "qc-test-staff", value: "301", domain: "localhost", path: "/" },
]);
await page.goto("/policy");
await expect(page.getByRole("heading", { name: "Policy tables", exact: true })).toBeVisible();
await expect(page.locator(".app-shell .app-nav")).toBeAttached();
await expect(page.getByRole("textbox", { name: "Search reviews", exact: true })).toBeVisible();
await expect(page.getByRole("combobox", { name: "Published table", exact: true })).toBeVisible();
});