|
| 1 | +/** |
| 2 | + * One review, from an empty app to an exported report, through a browser. |
| 3 | + * |
| 4 | + * The unit and route tests prove each part in isolation; this proves the parts |
| 5 | + * are connected, which is the one thing they cannot. It runs against a |
| 6 | + * production build with the fake engine, so it spends nothing and its answers |
| 7 | + * are the same ones the engine quality gate uses. |
| 8 | + * |
| 9 | + * Written as one test with named steps rather than several tests, because it |
| 10 | + * is one flow: each step depends on what the last one left on the screen, and |
| 11 | + * Playwright gives every separate test a fresh page. |
| 12 | + */ |
| 13 | + |
| 14 | +import { readFileSync } from "node:fs"; |
| 15 | +import { expect, test } from "@playwright/test"; |
| 16 | +import { APP_REPO, PROTOCOL_PATH } from "./setup"; |
| 17 | + |
| 18 | +test("a review, from an empty app to an exported report", async ({ page }) => { |
| 19 | + await test.step("an app with nothing in it says what to do first", async () => { |
| 20 | + await page.goto("/projects"); |
| 21 | + await expect(page.getByRole("heading", { name: "Projects" })).toBeVisible(); |
| 22 | + // An empty state that teaches the next step, rather than an apology. |
| 23 | + await expect(page.getByText("No projects yet")).toBeVisible(); |
| 24 | + await expect(page.getByText(/pick two branches and the rules/i)).toBeVisible(); |
| 25 | + }); |
| 26 | + |
| 27 | + await test.step("a repository is added and clones in the background", async () => { |
| 28 | + await page.getByPlaceholder("git@github.com:you/your-app.git").fill(`file://${APP_REPO}`); |
| 29 | + await page.getByRole("button", { name: "Add project" }).click(); |
| 30 | + // The clone runs in the background and the row appears at once, so the |
| 31 | + // name is what to wait for rather than a spinner finishing. |
| 32 | + await expect(page.getByRole("link", { name: "app", exact: true })).toBeVisible({ |
| 33 | + timeout: 60_000, |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + await test.step("a protocol document becomes a ruleset", async () => { |
| 38 | + await page.goto("/rulesets"); |
| 39 | + await page.getByLabel("Name").fill("Example protocol"); |
| 40 | + await page |
| 41 | + .getByPlaceholder("Paste the markdown protocol here") |
| 42 | + .fill(readFileSync(PROTOCOL_PATH, "utf8")); |
| 43 | + await page.getByRole("button", { name: "Import" }).click(); |
| 44 | + await expect(page.getByText(/Imported \d+ rule\(s\)/)).toBeVisible({ timeout: 30_000 }); |
| 45 | + }); |
| 46 | + |
| 47 | + await test.step("the project page lists its branches with how far they have moved", async () => { |
| 48 | + await page.goto("/projects"); |
| 49 | + await page.getByRole("link", { name: "app", exact: true }).click(); |
| 50 | + await expect(page.getByRole("heading", { name: "Branches" })).toBeVisible({ timeout: 60_000 }); |
| 51 | + await expect(page.getByRole("heading", { name: "Dependencies" })).toBeVisible(); |
| 52 | + }); |
| 53 | + |
| 54 | + await test.step("setting up a review shows what it will examine first", async () => { |
| 55 | + await page.getByRole("link", { name: "New review" }).click(); |
| 56 | + await expect(page.getByRole("heading", { name: "New review" })).toBeVisible(); |
| 57 | + |
| 58 | + // Both branches are chosen deliberately rather than left to the defaults. |
| 59 | + // This fixture's HEAD is the feature branch, so its detected default is |
| 60 | + // the branch under review, and taking the default would review main into |
| 61 | + // the feature branch: backwards, and a review of nothing anyone asked for. |
| 62 | + // Clicked the way a person clicks it: the radio itself is visually |
| 63 | + // hidden and the whole row is its label. |
| 64 | + await page |
| 65 | + .getByRole("main") |
| 66 | + .locator("label") |
| 67 | + .filter({ hasText: "feature/rename-prefs" }) |
| 68 | + .first() |
| 69 | + .click(); |
| 70 | + await page.getByLabel("Compare against").selectOption("main"); |
| 71 | + await page |
| 72 | + .getByLabel(/What was this change meant to do/) |
| 73 | + .fill("Rename the prefs field and migrate every consumer."); |
| 74 | + |
| 75 | + // The pre-flight is free and read-only, so it appears on its own once the |
| 76 | + // four decisions are made. |
| 77 | + await expect(page.getByText("What this review will examine")).toBeVisible({ timeout: 60_000 }); |
| 78 | + await expect(page.getByText("Files changed")).toBeVisible(); |
| 79 | + await expect(page.getByText(/pinned again when the review starts/)).toBeVisible(); |
| 80 | + }); |
| 81 | + |
| 82 | + await test.step("starting it walks the stages and then stops for a person", async () => { |
| 83 | + await page.getByRole("button", { name: "Start review" }).click(); |
| 84 | + await expect(page).toHaveURL(/\/reviews\/[A-Z0-9]+$/i, { timeout: 60_000 }); |
| 85 | + await expect(page.getByText("awaiting confirmation")).toBeVisible({ timeout: 120_000 }); |
| 86 | + await expect(page.getByText(/\d+ of \d+ decided/)).toBeVisible(); |
| 87 | + }); |
| 88 | + |
| 89 | + await test.step("one finding is dismissed with a reason", async () => { |
| 90 | + // Nothing is reported until a person says so, so completing is refused |
| 91 | + // while anything is still undecided. |
| 92 | + await expect(page.getByRole("button", { name: "Complete review" })).toBeDisabled(); |
| 93 | + |
| 94 | + await page |
| 95 | + .getByPlaceholder("Why is this not a problem?") |
| 96 | + .first() |
| 97 | + .fill("Deliberate: the caller already guards this."); |
| 98 | + await page.getByRole("button", { name: "Dismiss" }).first().click(); |
| 99 | + await expect(page.getByText("Deliberate: the caller already guards this.")).toBeVisible(); |
| 100 | + }); |
| 101 | + |
| 102 | + await test.step("the rest are confirmed from the keyboard", async () => { |
| 103 | + for (let guard = 0; guard < 30; guard += 1) { |
| 104 | + if ((await page.getByRole("button", { name: "Confirm" }).count()) === 0) break; |
| 105 | + await page.locator("body").press("c"); |
| 106 | + await page.waitForTimeout(200); |
| 107 | + } |
| 108 | + await expect(page.getByRole("button", { name: "Complete review" })).toBeEnabled({ |
| 109 | + timeout: 30_000, |
| 110 | + }); |
| 111 | + }); |
| 112 | + |
| 113 | + await test.step("completing it produces a report that can be exported", async () => { |
| 114 | + await page.getByRole("button", { name: "Complete review" }).click(); |
| 115 | + await expect(page.getByRole("heading", { name: "Report" })).toBeVisible({ timeout: 30_000 }); |
| 116 | + |
| 117 | + // The report says what was examined, not only what was found, and renders |
| 118 | + // findings in the structure the protocol defines. |
| 119 | + await expect(page.getByText("## What was examined")).toBeVisible(); |
| 120 | + await expect(page.getByText(/^File: app\//m).first()).toBeVisible(); |
| 121 | + |
| 122 | + await page.getByRole("button", { name: "Export" }).click(); |
| 123 | + await expect(page.getByText(/Written to .*exports/)).toBeVisible({ timeout: 30_000 }); |
| 124 | + }); |
| 125 | +}); |
0 commit comments