Testing the web app: Playwright and the per-role menu check
Owner: @zuki · Written by the Frontend Engineer · Last reviewed: 2026-10-12 · Conforms to the decisions through D33
How the web app is tested end to end: Playwright on the local Supabase stack, for the per-role menu check, a few smoke specs and a short list of journeys. The Frontend Engineer keeps this guide; the decisions and the rules outrank it (how we work).
It is the Playwright half of the Google doc [Guide] Testing v2: SQL tests, Playwright and staff testing, moved here on 2026-10-12 (#55, D28). The pgTAP half is Testing the database. Staff testing and the go/no-go gate are written once, in the cutover guide, and aren't repeated here.
Where each kind of test is
Section titled “Where each kind of test is”| Layer | Checks | Where it is written up |
|---|---|---|
| pgTAP | Every rule and every business action (each RPC); every error key asserted | Testing the database |
| v1 behaviour as data | The inputs v1 took, and the rows and balances it produced | Testing the database |
| Playwright | The per-role menu check, a few smoke specs and D19's journeys | This page |
| Staff testing and go/no-go | Real people doing their real day on staging; the gate | Cutover weekend and rollback |
The rules themselves are pgTAP's. A Playwright spec checks what a page shows, never a rule a pgTAP test already proves, because the rules live in Postgres and Playwright is the most expensive and least reliable layer (D19).
Where this layer stands
Section titled “Where this layer stands”On 2026-10-12 apps/web has no Playwright specs yet: there is no apps/web/e2e folder. What is written below is the design the packs follow, and each part says which pack builds it.
- Pack E (#19, timeline row 29) builds the Playwright setup, the smoke specs and the per-role menu check. It waits for the sign-in and the shell (packs B and C) and for the rules its specs cite, which the Docs Engineer writes in apps/docs.
- Each module's frontend pack writes that module's journeys, before its pages (D27).
- The CI job that runs the specs on every pull request is TL-M0-19; what it needs from the frontend is on the M0 page.
How a spec is written
Section titled “How a spec is written”The rule comes first, then the test that cites it, then the code (D27, how rules are written).
- Specs live in apps/web/e2e, where
pnpm docs:rulesreads them. - Every test title starts with the ID of the rule it proves, as in
test('R-XX-01: a wrong password is refused', …).pnpm docs:rulestakes any rule ID in a .ts file under apps/web/e2e as a citation, comments included, so a spec names only IDs that exist. - One spec for each rule. If a title needs "and", it is two rules and two specs.
- The rule's Status moves from planned to built in the same change that adds the spec and the page, and the change edits nothing else in apps/docs. A rule that looks wrong goes back to the Docs Engineer as a docs pull request, or to a change request when it conflicts with a decision; it is never changed to fit the code.
- The check fails when a spec cites an ID no rule defines or a retired rule, and when a built rule has no spec or test that cites it (the check).
- Runs are serial, because the specs share the E2E logins.
Logins and the E2E organization
Section titled “Logins and the E2E organization”A sealed test tenant lives in the local and staging databases: organization E2E Test, pools E2A (Jakarta) and E2B (Surabaya). It is described under the E2E organization in the database guide.
- One login per system role, made by
pnpm db:e2e-users(BE-M0-25), each at every pool of the E2E organization. The script writesE2E_PASSWORDand oneE2E_<ROLE>_EMAILper role to the git-ignored.env.e2eat the repository root, and Playwright reads it. It makes a random password on the first run and reuses it after that. - A spec signs in as the role that does the work, never as super_admin for a test about another role. A journey runs in the E2E organization, in Indonesian.
- No secret is ever written in a spec, a runbook, a chat or the wiki. In CI the local stack's keys and the E2E logins exist only inside the job, so no repository secret is needed.
The smoke specs
Section titled “The smoke specs”Pack E writes one spec for each of these. The sentences are the Frontend Engineer's proposal for the rules the Docs Engineer writes; until a rule has an ID, its spec isn't written.
| Spec | What it proves |
|---|---|
| Signed out | A visitor without a session who opens any page except /login is sent to /login. |
| Wrong password | A wrong email or password is refused with "Email atau kata sandi salah.", and the email stays filled in. |
| Sign-out | After Keluar the session ends, and the next page opened is /login. |
| Landing page | After sign-in each role lands on its page: finance on /collection, satpam on /gate, background_check on /screening, every other role on /dashboard. |
| Menu | Each role's menu shows the modules its permissions allow, the same as its v1 role sees (below). |
| Design preview | /design-preview stays off unless NEXT_PUBLIC_DESIGN_PREVIEW=1: a signed-in user gets 404 and a signed-out visitor is sent to /login, so it never shows on staging or production. |
The landing page and menu specs run once for each of the 11 system roles. The job leaves NEXT_PUBLIC_DESIGN_PREVIEW unset, which is what the last spec relies on.
The per-role menu check
Section titled “The per-role menu check”Each role sees the same modules as its v1 role, with v1's menus mapped through the permission renames (D19). v1's Backup menu has no v2 page.
- The expected menu comes from v1's access specs (below), which recorded the exact menus each v1 role gives.
- v2's menu comes from one list, lib/nav.ts, which also decides each role's landing page and the refusal page (pack C). The check proves that what a browser shows matches it, for every role, signed in as that role.
- A page outside the role shows the refusal page, not an error.
Journeys
Section titled “Journeys”D19 lists the journeys, one for each flow. Each is written when its module's pages are built, in this order:
| Journey | Module |
|---|---|
| Queue to lead to background check | M3 |
| Booking, contract and handover | M4 |
| Checkpoint inspection | M5 |
| Return with damages | M5 |
| Gate out with approvals | M5 |
| Payment and allocation | M6 |
- A journey checks what the page shows: statuses, figures, and a refusal as the user reads it, which is the mapper's Indonesian text for the error key (D29). The rules themselves are pgTAP's.
- It signs in as the role that does the work, never as super_admin, in the E2E organization, in Indonesian.
- The money journey can also check what a role without payment:margin doesn't see: margin and company amounts (D31).
- The frontend pack writes the journeys first, each title starting with the rule's ID, and then the pages. The rest of the module's behaviour is proved by pgTAP and by reconcile (plan).
v1's access specs
Section titled “v1's access specs”v1 behaviour is captured as data, not as v1 page objects for every flow (D19, Testing the database). v1's access specs are the one part of v1's Playwright suite that carries over, as the reference for the menu check.
- What they cover, read-only against v1 staging: per role, the landing page, the exact menus the role gives and the refusal of a page outside the role; the public queue form opens without a login; a wrong password is refused.
- They aren't in this repository. No v1 spec or workflow is here, and v2's specs never call v1.
- v1's repair cases are data cases, checked by pgTAP or reconcile, not by specs: overwritten and duplicate leads, the plate change, the rental anchor shift, double handover, swapped photos, ledger gaps and orphan bills.
- How they were run, recorded from the Google guide so it isn't lost when that is archived:
cp .env.example .env.e2ewithV1_BASE_URL,E2E_PASSWORDand oneE2E_<ROLE>_EMAILper v1 role, thenpnpm e2e:v1(playwright test --project=v1); in GitHub Actions, workflow e2e-v1.yml, nightly at 03:00 WIB and on demand, with the same names as repository secrets,VERCEL_AUTOMATION_BYPASS_SECRETif the preview is behind Vercel Deployment Protection, and the HTML report uploaded as an artifact. A v1 hot fix that breaks a spec means updating the spec and adding the fix to the port log, so v2 gets it too.
Running the specs
Section titled “Running the specs”Once pack E is merged, from the repository root:
pnpm db:signing-keypnpm supabase startpnpm supabase db resetpnpm db:e2e-userspnpm --filter web e2e- apps/web needs
.env.local, written frompnpm supabase status -o envas in FE-M0-06 block 5. LeaveNEXT_PUBLIC_DESIGN_PREVIEWunset. - The invitation journeys also need the local stack's secret key as
SUPABASE_SECRET_KEY=<LOCAL_SECRET_KEY>, theSECRET_KEYline ofpnpm supabase status -o env. Only lib/supabase/admin.ts reads it, to send invite emails (D98); it is server-only and never takes theNEXT_PUBLIC_prefix.pnpm e2e:localexports it for you. pnpm --filter web e2estarts the built app itself, so build it first withpnpm --filter web build.- The browser comes from
pnpm --filter web exec playwright install chromium. - Stop the stack afterwards with
pnpm supabase stop.
Troubleshooting
Section titled “Troubleshooting”| Problem | Fix |
|---|---|
| Every spec fails at sign-in | .env.e2e is missing or from an older reset. Run pnpm supabase db reset, then pnpm db:e2e-users. |
| The design preview spec fails | NEXT_PUBLIC_DESIGN_PREVIEW is set in the shell or in apps/web/.env.local. Unset it; the spec proves the preview is off. |
| An invitation journey times out waiting for the invite email | Mailpit at http://127.0.0.1:54324 shows a "You've been invited" email with a token= link: the stack was started before supabase/templates/invite.html was configured. Run pnpm supabase stop, then pnpm supabase start. |
| Specs interfere with each other | Runs are serial because the specs share the E2E logins. Don't turn on parallel runs. |
| A role's menu differs from what the spec expects | Compare lib/nav.ts with the role's permissions in the database; if the database is right and the expected menu is wrong, the rule goes back to the Docs Engineer. |
pnpm docs:rules fails on a spec |
The title cites an ID no rule defines, or a retired one. Fix the ID, or ask the Docs Engineer for the rule. |
| Browser version mismatch | Run pnpm --filter web exec playwright install chromium again. |
| A v1 access spec gets 403 from staging | Run it in GitHub Actions or from a network that can reach it, and add the Vercel bypass secret if the preview is protected. |
Related
Section titled “Related”- Testing the database: pgTAP and v1 as data
- Cutover weekend and rollback: staff testing and the go/no-go gate
- Using the Opleet design system
- How rules are written
- Plan: modules M0 to M7