// SPDX-License-Identifier: CPAL-1.0 // Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution // License 1.0: see LICENSE (its Exhibit A is this file's notice). // The main flows of ROADMAP §4 in a real browser, on the built UI and the demo control plane, with // the clicks counted as in the smoke test (tests/flows.test.ts). Each is recorded: the showcase // videos (docs/fabrica.md part 5) are target/e2e/videos/.webm. import type { Locator, Page } from "@playwright/test"; import { expect, test } from "../fixtures"; function counter() { let n = 0; return { click: async (l: Locator) => { n++; await l.click(); }, get count() { return n; }, }; } /** A beat for the viewer of the video, so a screen is seen before the next click. */ const beat = (page: Page) => page.waitForTimeout(700); const nav = (page: Page) => page.getByRole("navigation", { name: "Main" }).first(); test("Add a host: + Host → fill → Apply = 2 clicks, kept", { annotation: { type: "video", description: "add-host" } }, async ({ page, open }) => { const c = counter(); await open("/"); await expect(page.getByRole("button", { name: "More for wiki.home.test" })).toBeVisible(); await beat(page); await c.click(page.getByRole("button", { name: "Add a host" })); await page.getByLabel("Hostname").pressSequentially("notes.home.test"); await page.getByLabel("Send traffic to").fill("http://192.0.2.60:8080"); await beat(page); await c.click(page.getByRole("button", { name: "Apply" })); await expect(page.locator("dialog.ia-panel")).toHaveCount(0, { timeout: 10_000 }); await expect(page.getByRole("button", { name: "More for notes.home.test" })).toBeVisible(); await beat(page); expect(c.count).toBe(2); }); test("Undo the last change = 1 click", { annotation: { type: "video", description: "undo" } }, async ({ page, open }) => { const c = counter(); await open("/"); const undo = page.getByRole("button", { name: /^Undo: Added recipes\.home\.test/ }); await expect(undo).toBeVisible(); await beat(page); const sent = page.waitForRequest((r) => r.method() === "POST" && r.url().endsWith("/api/v1/undo")); await c.click(undo); expect((await sent).postDataJSON()).toMatchObject({ target_change_id: "ch_0008" }); await beat(page); expect(c.count).toBe(1); }); test("Restore: History → pick → Restore = 3 clicks", { annotation: { type: "video", description: "restore" } }, async ({ page, open }) => { const c = counter(); await open("/"); await expect(page.getByRole("button", { name: "Add a host" })).toBeVisible(); await c.click(nav(page).getByRole("link", { name: "History" })); await beat(page); await c.click(page.getByRole("button", { name: /Turned share links on for wiki\.home\.test/ })); await expect(page.getByRole("button", { name: "Restore this version" })).toBeVisible(); await beat(page); const sent = page.waitForRequest((r) => r.method() === "POST" && r.url().endsWith("/api/v1/restore")); await c.click(page.getByRole("button", { name: "Restore this version" })); await sent; await beat(page); expect(c.count).toBe(3); }); test("Share link: ⋯ → Share link → Copy = 3 clicks, 7 days", { annotation: { type: "video", description: "share-link" } }, async ({ page, context, open }) => { await context.grantPermissions(["clipboard-read", "clipboard-write"]); const c = counter(); await open("/"); await c.click(page.getByRole("button", { name: "More for wiki.home.test" })); const minted = page.waitForRequest((r) => r.method() === "POST" && r.url().endsWith("/share-links")); await c.click(page.getByRole("menuitem", { name: /Share link/ })); expect((await minted).postDataJSON()).toMatchObject({ expires_in_s: 604800 }); const copy = page.getByRole("button", { name: "Copy link" }); await expect(copy).not.toHaveAttribute("aria-disabled", /.*/); await beat(page); await c.click(copy); await expect(page.getByText("Copied")).toBeVisible(); await beat(page); expect(c.count).toBe(3); }); test("Switch engine: engine chip → Switch to Caddy = 2 clicks", { annotation: { type: "video", description: "engine" } }, async ({ page, open }) => { const c = counter(); await open("/"); await c.click(page.getByRole("button", { name: /^Engine: Pingora/ })); await expect(page.getByRole("button", { name: "Switch to Caddy" })).toBeVisible(); await beat(page); await c.click(page.getByRole("button", { name: "Switch to Caddy" })); await expect(page.getByText("Now serving with Caddy.")).toBeVisible({ timeout: 10_000 }); await beat(page); expect(c.count).toBe(2); }); test("Device certificate: Certificates → + Device → Issue = 3 clicks", { annotation: { type: "video", description: "device-certificate" } }, async ({ page, open }) => { const c = counter(); await open("/"); await expect(page.getByRole("button", { name: "Add a host" })).toBeVisible(); await c.click(nav(page).getByRole("link", { name: "Certificates" })); await beat(page); await c.click(page.getByRole("button", { name: "Add a device certificate" })); await page.getByLabel("Device name").fill("felix's tablet"); await c.click(page.getByRole("button", { name: "Issue" })); await expect(page.getByLabel("Match code 47 19 83")).toBeVisible(); expect(c.count).toBe(3); await expect(page.getByRole("button", { name: "Show QR code" })).toBeVisible({ timeout: 10_000 }); await beat(page); });