From b037276bfcd4a2ab019f7bc3fd4bdcfbc5617d5b Mon Sep 17 00:00:00 2001 From: Georges-Antoine Assi Date: Sun, 26 Jul 2026 09:07:14 -0400 Subject: [PATCH] Add Playwright e2e cover for permission gating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The #3954 fix is about what a read-only user can SEE, which the Vitest specs can't reach: visibility depends on grants the backend resolves and `useCan` projects. These drive a real instance instead. frontend/e2e/rom-actions.spec.ts ⋯ menu items + divider collapse frontend/e2e/profile-role.spec.ts no self-editable role control frontend/e2e/game-media-files.spec.ts Media/Files upload + delete Every spec asserts both sides -- absent for `e2e_viewer`, present for `e2e_admin` -- so it can't pass against a page that failed to render, and notices a fix that over-hides. Verified by reverting the fix: 8 of 15 fail, and the 6 admin-side guards stay green. `backend/tools/seed_e2e_users.py` seeds the two fixture users idempotently. Specs live in e2e/ so Vitest's src/** and test/** globs skip them, and tsconfig now covers them so they're typechecked. Not wired into CI: that needs a backend, a database and a library fixture in the runner. --- .gitignore | 6 ++ CLAUDE.md | 1 + backend/tools/seed_e2e_users.py | 107 +++++++++++++++++++++ frontend/e2e/README.md | 58 +++++++++++ frontend/e2e/fixtures/auth.ts | 74 +++++++++++++++ frontend/e2e/game-media-files.spec.ts | 132 ++++++++++++++++++++++++++ frontend/e2e/profile-role.spec.ts | 37 ++++++++ frontend/e2e/rom-actions.spec.ts | 92 ++++++++++++++++++ frontend/package-lock.json | 64 +++++++++++++ frontend/package.json | 5 +- frontend/playwright.config.ts | 33 +++++++ frontend/tsconfig.json | 8 +- 12 files changed, 615 insertions(+), 2 deletions(-) create mode 100644 backend/tools/seed_e2e_users.py create mode 100644 frontend/e2e/README.md create mode 100644 frontend/e2e/fixtures/auth.ts create mode 100644 frontend/e2e/game-media-files.spec.ts create mode 100644 frontend/e2e/profile-role.spec.ts create mode 100644 frontend/e2e/rom-actions.spec.ts create mode 100644 frontend/playwright.config.ts diff --git a/.gitignore b/.gitignore index 22f98cc84..5ea662615 100644 --- a/.gitignore +++ b/.gitignore @@ -79,3 +79,9 @@ switch_product_ids.json # Local dev scripts /dev.sh + +# Playwright (e2e) artifacts +frontend/test-results/ +frontend/playwright-report/ +frontend/blob-report/ +frontend/.last-run.json diff --git a/CLAUDE.md b/CLAUDE.md index 9505c650e..576614b88 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -93,6 +93,7 @@ npm install # install (Node 24) npm run dev # dev server :3000 npm run typecheck # vue-tsc npm run test # vitest (+ Storybook play() tests) +npm run test:e2e # playwright (needs a running app + seeded e2e users) npm run build # production build npm run generate # regenerate types from backend OpenAPI (backend must be running) npm run build:tokens # regenerate v2 tokens.css (auto on predev/prebuild) diff --git a/backend/tools/seed_e2e_users.py b/backend/tools/seed_e2e_users.py new file mode 100644 index 000000000..8569f0346 --- /dev/null +++ b/backend/tools/seed_e2e_users.py @@ -0,0 +1,107 @@ +"""Seed (or reset) the fixture users the Playwright e2e suite logs in as. + +Idempotent: re-running resets the passwords and group assignment rather than +erroring on the existing rows. Pass ``--remove`` to delete the fixtures again. + + uv run python tools/seed_e2e_users.py + uv run python tools/seed_e2e_users.py --remove + +Two accounts, matching the two sides of every permission assertion: + + * ``e2e_admin`` — role admin, so `useCan` short-circuits to true and every + gated affordance must be present. + * ``e2e_viewer`` — the seeded "Viewer (legacy)" group, i.e. library read plus + own collections/assets. Every ROM write affordance must be absent. + +Never point this at a real library: it writes users with a known password. +""" + +from __future__ import annotations + +import argparse +import os +import sys + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +from handler.auth import auth_handler # noqa: E402 +from handler.database import db_permission_handler, db_user_handler # noqa: E402 +from models.user import Role, User # noqa: E402 + +VIEWER_GROUP_NAME = "Viewer (legacy)" + +ADMIN_USERNAME = "e2e_admin" +VIEWER_USERNAME = "e2e_viewer" +# Fixture-only credential for a throwaway dev instance, overridable so nothing +# has to rely on the literal. The e2e suite reads the same env var +# (see frontend/e2e/fixtures/auth.ts). Not a secret: it authenticates two +# purpose-made users on a local database. +PASSWORD = os.environ.get("E2E_PASSWORD", "e2e-Passw0rd!") # nosec B105 + + +def _viewer_group_id() -> int: + for group in db_permission_handler.get_groups(): + if group.name == VIEWER_GROUP_NAME: + return group.id + raise SystemExit( + f"No {VIEWER_GROUP_NAME!r} group found -- run `alembic upgrade head` first." + ) + + +def _upsert(username: str, role: Role, permission_group_id: int | None) -> None: + hashed = auth_handler.get_password_hash(PASSWORD) + existing = db_user_handler.get_user_by_username(username) + if existing: + db_user_handler.update_user( + existing.id, + { + "hashed_password": hashed, + "role": role, + "enabled": True, + "permission_group_id": permission_group_id, + }, + ) + print(f"reset {username} (id={existing.id}, role={role})") + return + + user = db_user_handler.add_user( + User( + username=username, + hashed_password=hashed, + email=f"{username}@example.invalid", + role=role, + enabled=True, + permission_group_id=permission_group_id, + ) + ) + print(f"create {username} (id={user.id}, role={role})") + + +def _remove() -> None: + for username in (ADMIN_USERNAME, VIEWER_USERNAME): + user = db_user_handler.get_user_by_username(username) + if user: + db_user_handler.delete_user(user.id) + print(f"delete {username} (id={user.id})") + else: + print(f"absent {username}") + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--remove", action="store_true", help="delete the fixture users instead" + ) + args = parser.parse_args() + + if args.remove: + _remove() + return 0 + + _upsert(ADMIN_USERNAME, Role.ADMIN, None) + _upsert(VIEWER_USERNAME, Role.USER, _viewer_group_id()) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/frontend/e2e/README.md b/frontend/e2e/README.md new file mode 100644 index 000000000..ffcf519e1 --- /dev/null +++ b/frontend/e2e/README.md @@ -0,0 +1,58 @@ +# End-to-end tests (Playwright) + +These drive a **real running RomM instance** — app, backend and database — unlike +the Vitest specs, which mount components in isolation. They exist to cover +behaviour that only shows up in the assembled app: chiefly **permission gating**, +where the question "is this button visible?" depends on grants resolved by the +backend and projected through `useCan`. + +They live in `e2e/` rather than `src/` or `test/` because Vitest's globs +(`src/**/*.{test,spec}.ts`, `test/**/*.{test,spec}.ts`) would otherwise try to +run them in jsdom. + +## Running them + +1. Have the app up and reachable (default `http://localhost:3000`, override with + `E2E_BASE_URL`), with a populated library — the specs pick the first ROM they + find. + +2. Seed the two fixture users, from `backend/`: + + ```bash + uv run python tools/seed_e2e_users.py # --remove to clean up afterwards + ``` + +3. Run, from `frontend/`: + + ```bash + npm run test:e2e # headless + npm run test:e2e:ui # interactive, for debugging a failure + ``` + +## The two fixture users + +Every gating spec asserts **both sides**, which is the point: + +| User | Grants | Expectation | +| ------------ | -------------------------------------------------------------- | -------------------------------- | +| `e2e_viewer` | "Viewer (legacy)" group — library read, own collections/assets | write affordances **absent** | +| `e2e_admin` | role=admin, so `useCan` short-circuits | the same affordances **present** | + +Asserting only the viewer side would let a spec pass against a page that failed +to render at all, and would not notice a fix that over-hides and breaks admins. +Where a section is per-user rather than ROM-scoped (e.g. "My screenshots"), the +spec asserts it _stays_ writable for the viewer. + +## Notes for whoever edits these + +- **Scope to the visible panel** in the Media tab. It keeps every subtab mounted + (`v-show`, not `v-if`) so the heavy async panels don't re-mount on each switch, + which means a document-wide locator also matches hidden panels. +- **Prefer auto-waiting assertions** (`expect(locator)`) over bare `count()`. + `count()` resolves immediately and reads `0` before an async panel mounts, + which silently turns a real check into a no-op. +- **Keep the worker pool small.** All workers hit one dev server whose on-demand + Vite transforms are the bottleneck; too much parallelism turns passes into + timeouts. Tune with `E2E_WORKERS`. +- Not wired into CI — that needs a backend, database and library fixture in the + runner. Run locally when touching permission gating. diff --git a/frontend/e2e/fixtures/auth.ts b/frontend/e2e/fixtures/auth.ts new file mode 100644 index 000000000..73550b2f0 --- /dev/null +++ b/frontend/e2e/fixtures/auth.ts @@ -0,0 +1,74 @@ +import { expect, type Page } from "@playwright/test"; + +// Fixture accounts seeded by `backend/tools/seed_e2e_users.py`. `viewer` sits in +// the "Viewer (legacy)" group: library read plus own collections/assets, and no +// ROM write grant. `admin` is role=admin, so `useCan` short-circuits to true and +// every gated affordance must be present -- which is what makes these specs a +// two-sided check rather than "the button is missing". +export const USERS = { + admin: process.env.E2E_ADMIN_USERNAME ?? "e2e_admin", + viewer: process.env.E2E_VIEWER_USERNAME ?? "e2e_viewer", +} as const; + +export const PASSWORD = process.env.E2E_PASSWORD ?? "e2e-Passw0rd!"; + +export type Role = keyof typeof USERS; + +/** Log in through the real form and wait for the app shell to take over. */ +export async function login(page: Page, role: Role) { + await page.goto("/login"); + await page.fill('input[name="username"]', USERS[role]); + await page.fill('input[name="password"]', PASSWORD); + await page.click('button[type="submit"]'); + // The router replaces /login on success; a failed login leaves us here with a + // snackbar, so assert the navigation rather than a fixed timeout. + await expect(page).not.toHaveURL(/\/login/, { timeout: 15_000 }); +} + +/** Navigate to the logged-in user's own profile page (route `/user/:user`). */ +export async function gotoOwnProfile(page: Page) { + const res = await page.request.get("/api/users/me"); + expect(res.ok(), "could not resolve the current user").toBe(true); + const me = await res.json(); + await page.goto(`/user/${me.id}`); + return me; +} + +/** Navigate to the first ROM of the first non-empty platform. */ +export async function gotoFirstRom(page: Page) { + const res = await page.request.get("/api/roms?limit=1&order_by=name"); + expect(res.ok(), "could not list ROMs -- is the dev library populated?").toBe( + true, + ); + const body = await res.json(); + const rom = body.items?.[0]; + expect(rom, "the dev library has no ROMs to test against").toBeTruthy(); + await page.goto(`/rom/${rom.id}`); + return rom; +} + +/** Open the ⋯ more-actions menu and return the teleported panel locator. */ +export async function openMoreMenu(page: Page) { + await page.getByRole("button", { name: "More actions" }).first().click(); + const panel = page.locator('[role="menu"]'); + await expect(panel).toBeVisible(); + return panel; +} + +/** Visible labels of every item in an open menu panel, in DOM order. */ +export async function menuLabels(page: Page): Promise { + return page.locator('[role="menu"] .r-menu-item__label').allInnerTexts(); +} + +/** Force the v2 UI and a known theme before the app boots. + * vueuse's `useLocalStorage` uses the string serializer for string refs, so + * these are stored raw -- NOT JSON-quoted. */ +export async function seedUiState(page: Page, theme: "dark" | "light") { + await page.addInitScript( + ([t]) => { + localStorage.setItem("settings.uiVersion", "v2"); + localStorage.setItem("settings.theme", t); + }, + [theme], + ); +} diff --git a/frontend/e2e/game-media-files.spec.ts b/frontend/e2e/game-media-files.spec.ts new file mode 100644 index 000000000..89b6de28c --- /dev/null +++ b/frontend/e2e/game-media-files.spec.ts @@ -0,0 +1,132 @@ +import { expect, type Locator, type Page, test } from "@playwright/test"; +import { gotoFirstRom, login, seedUiState } from "./fixtures/auth"; + +// The Media and Files tabs write to the ROM (manuals, soundtracks, shared +// screenshots, ROM files) and every one of those endpoints gates on ROMS_WRITE. +// A read-only user must not be offered upload/delete there -- same 403-to-logout +// trap as the ⋯ menu. +// +// The per-user "My screenshots" section is the deliberate exception: it writes +// user assets, which every authenticated user may do. +// +// NOTE: MediaTab keeps every subtab panel mounted (v-show, not v-if) so the +// heavy async panels don't re-mount on each switch. Assertions must therefore +// scope to the VISIBLE panel -- a document-wide locator would also match the +// hidden panels and pass or fail for the wrong reason. + +async function openTab(page: Page, tab: string) { + await page.getByRole("tab", { name: tab }).click(); +} + +// Media subtabs are a sidebar list of role=tab buttons, distinct from the +// top-level RTabNav tabs. +async function openSubtab(page: Page, subtab: string) { + await page.locator(".r-v2-media__subtab-btn", { hasText: subtab }).click(); +} + +/** The one Media panel currently on screen. */ +function visiblePanel(page: Page): Locator { + return page.locator(".r-v2-media__panel:visible"); +} + +test.describe("Media tab write affordances", () => { + // Both panels whose upload path is ROM-scoped, so both must be inert. + for (const [subtab, emptyText] of [ + ["Manual", "No manual yet"], + ["Soundtrack", "No soundtrack yet"], + ] as const) { + test(`${subtab}: a read-only user gets the empty state, not a dropzone`, async ({ + page, + }) => { + await seedUiState(page, "dark"); + await login(page, "viewer"); + await gotoFirstRom(page); + await openTab(page, "Media"); + await openSubtab(page, subtab); + + const panel = visiblePanel(page); + // The plain REmptyState replaces the dropzone: same message, no CTA, + // no drag-and-drop hint, no Upload button. + await expect(panel.getByText(emptyText)).toBeVisible(); + await expect(panel.locator(".r-dropzone__cta")).toHaveCount(0); + await expect( + panel.getByText("Drag and drop, or click to browse"), + ).toHaveCount(0); + await expect( + panel.getByRole("button", { name: "Upload", exact: true }), + ).toHaveCount(0); + }); + + test(`${subtab}: an admin still gets the dropzone`, async ({ page }) => { + await seedUiState(page, "dark"); + await login(page, "admin"); + await gotoFirstRom(page); + await openTab(page, "Media"); + await openSubtab(page, subtab); + + const panel = visiblePanel(page); + // Empty ROM => CTA dropzone; populated ROM => Upload button. Either is a + // write affordance, and a read-only user gets neither. `.or()` keeps this + // auto-waiting: a bare `count()` reads 0 before the async panel mounts. + const writeAffordance = panel + .locator(".r-dropzone__cta") + .or(panel.getByRole("button", { name: "Upload", exact: true })); + await expect(writeAffordance.first()).toBeVisible(); + }); + } + + test("Screenshots: the shared ROM section is hidden but the per-user one stays writable", async ({ + page, + }) => { + await seedUiState(page, "dark"); + await login(page, "viewer"); + await gotoFirstRom(page); + await openTab(page, "Media"); + await openSubtab(page, "Screenshots"); + + const panel = visiblePanel(page); + // Shared section writes to the ROM: gone for a read-only user with nothing + // to show. + await expect(panel.getByText("ROM screenshots")).toHaveCount(0); + // Per-user section writes user assets: must survive, dropzone included. + // Hiding this would be the regression in the opposite direction. + await expect(panel.getByText("My screenshots")).toBeVisible(); + await expect(panel.locator(".r-dropzone__cta")).not.toHaveCount(0); + }); + + test("Screenshots: an admin sees the shared ROM section", async ({ + page, + }) => { + await seedUiState(page, "dark"); + await login(page, "admin"); + await gotoFirstRom(page); + await openTab(page, "Media"); + await openSubtab(page, "Screenshots"); + + await expect(visiblePanel(page).getByText("ROM screenshots")).toBeVisible(); + }); +}); + +test.describe("Files tab write affordances", () => { + test("a read-only user gets no upload button", async ({ page }) => { + await seedUiState(page, "dark"); + await login(page, "viewer"); + await gotoFirstRom(page); + await openTab(page, "Files"); + + await expect( + page.getByRole("button", { name: "Upload", exact: true }), + ).toHaveCount(0); + }); + + test("an admin gets the upload button", async ({ page }) => { + await seedUiState(page, "dark"); + await login(page, "admin"); + await gotoFirstRom(page); + await openTab(page, "Files"); + + await expect( + page.getByRole("button", { name: "Upload", exact: true }), + ).toBeVisible(); + }); +}); diff --git a/frontend/e2e/profile-role.spec.ts b/frontend/e2e/profile-role.spec.ts new file mode 100644 index 000000000..1c0f09fc6 --- /dev/null +++ b/frontend/e2e/profile-role.spec.ts @@ -0,0 +1,37 @@ +import { expect, test } from "@playwright/test"; +import { gotoOwnProfile, login, seedUiState } from "./fixtures/auth"; + +// Regression cover for #3954: the profile page shipped an editable role picker, +// but `update_user` ignores `role` on a self-edit. Saving reported success and +// then silently reverted on reload -- for admins as much as for regular users. +// The role is display-only now: the chip in the identity row. +test.describe("Profile page role field", () => { + for (const role of ["viewer", "admin"] as const) { + test(`${role} gets no editable role control`, async ({ page }) => { + await seedUiState(page, "dark"); + await login(page, role); + await gotoOwnProfile(page); + + // The editable rows that SHOULD be there, so a blank page can't pass. + await expect(page.locator('input[type="email"]')).toBeVisible(); + + // No role row in the Account Details form. + const form = page.locator(".r-v2-section-stack"); + await expect(form.getByText("Role", { exact: true })).toHaveCount(0); + // And no select rendered anywhere on the page. + await expect(page.locator(".r-select")).toHaveCount(0); + }); + } + + test("the role is still shown as a read-only chip", async ({ page }) => { + await seedUiState(page, "dark"); + await login(page, "viewer"); + await gotoOwnProfile(page); + + // Identity row keeps the role visible -- removing the picker must not + // remove the information. + const chip = page.locator(".r-v2-profile__role-tag"); + await expect(chip).toBeVisible(); + await expect(chip).toHaveText(/user/i); + }); +}); diff --git a/frontend/e2e/rom-actions.spec.ts b/frontend/e2e/rom-actions.spec.ts new file mode 100644 index 000000000..3db9f7db9 --- /dev/null +++ b/frontend/e2e/rom-actions.spec.ts @@ -0,0 +1,92 @@ +import { expect, test } from "@playwright/test"; +import { + gotoFirstRom, + login, + menuLabels, + openMoreMenu, + seedUiState, +} from "./fixtures/auth"; + +// Regression cover for #3954: the ⋯ menu offered Match / Refresh metadata / +// Edit / Delete to users with no ROM write grant. Those endpoints gate on +// ROMS_WRITE, so the click 403'd and the axios interceptor turned that into a +// logout -- the "page reloads back to the login page" in the bug report. +const WRITE_ACTIONS = [ + "Match ROM", + "Refresh metadata", + "Edit", + "Delete", +] as const; + +test.describe("ROM more-actions menu", () => { + test("a read-only user is offered no write or destructive action", async ({ + page, + }) => { + await seedUiState(page, "dark"); + await login(page, "viewer"); + await gotoFirstRom(page); + await openMoreMenu(page); + + const labels = await menuLabels(page); + for (const action of WRITE_ACTIONS) { + expect(labels, `"${action}" must not be offered`).not.toContain(action); + } + // The actions they CAN perform are still there -- otherwise this spec would + // also pass against a menu that failed to render at all. + expect(labels).toContain("Download"); + expect(labels).toContain("Add to favourites"); + }); + + test("a read-only user's menu has no trailing separator", async ({ + page, + }) => { + await seedUiState(page, "dark"); + await login(page, "viewer"); + await gotoFirstRom(page); + const panel = await openMoreMenu(page); + + // Hiding the metadata + destructive groups must hide their leading dividers + // too, or the menu ends in stray rules. One divider survives: the split + // between the primary and per-user groups. + await expect(panel.locator('[role="separator"]')).toHaveCount(1); + + // And the last thing in the panel is an item, not a rule. + const lastChildIsSeparator = await panel.evaluate((el) => { + const body = el.querySelector(".r-menu__body") ?? el; + const kids = Array.from(body.children).filter( + (c) => (c as HTMLElement).offsetParent !== null || c.clientHeight > 0, + ); + const last = kids[kids.length - 1]; + return last?.getAttribute("role") === "separator"; + }); + expect(lastChildIsSeparator).toBe(false); + }); + + test("an admin still gets every action", async ({ page }) => { + await seedUiState(page, "dark"); + await login(page, "admin"); + await gotoFirstRom(page); + const panel = await openMoreMenu(page); + + const labels = await menuLabels(page); + for (const action of WRITE_ACTIONS) { + expect(labels, `"${action}" must still be offered to admins`).toContain( + action, + ); + } + // Primary | per-user | metadata | destructive => three dividers. + await expect(panel.locator('[role="separator"]')).toHaveCount(3); + }); + + test("the read-only menu renders in light theme too", async ({ page }) => { + await seedUiState(page, "light"); + await login(page, "viewer"); + await gotoFirstRom(page); + const panel = await openMoreMenu(page); + + await expect(panel).toBeVisible(); + const labels = await menuLabels(page); + expect(labels).not.toContain("Delete"); + expect(labels.length).toBeGreaterThan(0); + }); +}); diff --git a/frontend/package-lock.json b/frontend/package-lock.json index fedb13519..2ee177b37 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -34,6 +34,7 @@ }, "devDependencies": { "@eslint/js": "^10.0.1", + "@playwright/test": "^1.61.1", "@storybook/addon-a11y": "^10.2.19", "@storybook/addon-docs": "^10.2.19", "@storybook/addon-themes": "^10.2.19", @@ -3781,6 +3782,22 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.61.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.61.1.tgz", + "integrity": "sha512-8nKv6+0RJSL9FE4jYOEGXnPeM/Hg12qZpmqzZjRh3qM0Y7c3z1mrOTfFLids72RDQYVh9WpLEfR5WdpNX4fkig==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.61.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@polka/url": { "version": "1.0.0-next.29", "resolved": "https://registry.npmjs.org/@polka/url/-/url-1.0.0-next.29.tgz", @@ -10233,6 +10250,53 @@ } } }, + "node_modules/playwright": { + "version": "1.61.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.61.1.tgz", + "integrity": "sha512-DWnY5o3YbLWK4GovuAVwpqL+1VwGNdUGrRr++8j8PtQQzvAVZUIMjKQ90fY689sEJZJBbZVw1rXaOKSTitkzPQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.61.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.61.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.61.1.tgz", + "integrity": "sha512-h7Qlt6m4REp25qvIdvbDtVmD4LqVXfpRxhORv9L0jzETM05p4fuPJ3dKyuSXQxDSbXnmS79HAgi9589lGSpLkg==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/pngjs": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 804e83c61..0338ce75f 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -33,7 +33,9 @@ "test:ui": "vitest --ui", "storybook": "storybook dev -p 6006", "storybook:build": "storybook build", - "storybook:test": "vitest run test/storybook.test.ts" + "storybook:test": "vitest run test/storybook.test.ts", + "test:e2e": "playwright test", + "test:e2e:ui": "playwright test --ui" }, "dependencies": { "@floating-ui/vue": "^1.1.11", @@ -61,6 +63,7 @@ }, "devDependencies": { "@eslint/js": "^10.0.1", + "@playwright/test": "^1.61.1", "@storybook/addon-a11y": "^10.2.19", "@storybook/addon-docs": "^10.2.19", "@storybook/addon-themes": "^10.2.19", diff --git a/frontend/playwright.config.ts b/frontend/playwright.config.ts new file mode 100644 index 000000000..20cb82e8d --- /dev/null +++ b/frontend/playwright.config.ts @@ -0,0 +1,33 @@ +import { defineConfig, devices } from "@playwright/test"; + +// End-to-end suite. Unlike the Vitest specs (which live beside the code under +// `src/**`), these drive a REAL running RomM instance: the app on +// E2E_BASE_URL, a live backend, and the fixture users seeded by +// `backend/tools/seed_e2e_users.py`. They are deliberately kept out of `src/` +// and `test/` so Vitest's globs never pick them up. +// +// uv run python tools/seed_e2e_users.py # once, from backend/ +// npm run test:e2e +export default defineConfig({ + testDir: "./e2e", + // Permission gating is global state on the server (the fixture users' grants), + // so the specs read it rather than mutate it and are safe to parallelise. + fullyParallel: true, + forbidOnly: !!process.env.CI, + retries: process.env.CI ? 2 : 1, + // Every worker logs in and hammers ONE dev server, whose on-demand Vite + // transforms are the bottleneck. Too many workers turns real passes into + // timeouts, so keep the pool small. + workers: Number(process.env.E2E_WORKERS ?? 2), + reporter: process.env.CI ? "github" : "list", + timeout: 45_000, + expect: { timeout: 10_000 }, + use: { + baseURL: process.env.E2E_BASE_URL ?? "http://localhost:3000", + trace: "retain-on-failure", + screenshot: "only-on-failure", + actionTimeout: 15_000, + navigationTimeout: 30_000, + }, + projects: [{ name: "chromium", use: { ...devices["Desktop Chrome"] } }], +}); diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index aa301ae76..18c03ad69 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -1,6 +1,12 @@ { "extends": "@vue/tsconfig/tsconfig.dom.json", - "include": ["src/**/*.ts", "src/**/*.vue", "src/**/*.d.ts"], + "include": [ + "src/**/*.ts", + "src/**/*.vue", + "src/**/*.d.ts", + "e2e/**/*.ts", + "playwright.config.ts" + ], "exclude": ["node_modules"], "types": ["node", "lodash", "js-cookie", "vue-router", "vue"], "compilerOptions": {