// 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 release's screenshots (docs/release.md): every shot's screen is drawn from the demo control // plane alone (each click and wait selector found, no call unanswered), and nothing the demo // serves or the page shows names a real host, address or person. import { cleanup, render, waitFor } from "@testing-library/svelte"; import { afterEach, describe, expect, it } from "vitest"; import App from "../src/App.svelte"; import { app } from "../src/lib/app.svelte"; import { DOMI_ATTRIBUTION } from "@domi/ui"; import { CREDIT } from "../src/lib/credit"; import { SHOTS, demoApi, realLooking } from "./demo"; let served: { status: number; path: string; text: string | null }[] = []; function start(path: string) { history.replaceState({}, "", path); app.path = path; app.panel = null; app.overview = null; app.etag = null; app.signedOut = false; app.switchResult = null; app.renewedUntil = null; app.dismissed = []; served = []; const api = demoApi(); globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { const url = typeof input === "string" ? input : input instanceof URL ? input.pathname + input.search : input.url; const path = url.replace(/^.*\/api\/v1/, ""); const a = api(init?.method ?? "GET", path, init?.body ? JSON.parse(String(init.body)) : {}); served.push({ status: a.status, path, text: a.text }); return new Response(a.text, { status: a.status, headers: { "Content-Type": "application/json" } }); }) as typeof fetch; render(App); } function pageText(): string[] { const out: string[] = []; const walk = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); for (let n = walk.nextNode(); n; n = walk.nextNode()) if (n.textContent?.trim()) out.push(n.textContent); document.querySelectorAll("input, textarea").forEach((i) => out.push(i.value)); document.querySelectorAll("[href]").forEach((a) => out.push(a.getAttribute("href") ?? "")); return out; } afterEach(() => cleanup()); describe("realLooking", () => { it("passes invented names and refuses real-looking ones", () => { expect(realLooking("wiki.home.test http://192.0.2.10:3000 on 127.0.0.1 for ada")).toEqual([]); expect(realLooking("http://10.0.0.2:3000")).toEqual(["10.0.0.2"]); expect(realLooking("gitea.example.cz and Mark's phone")).toEqual(["gitea.example.cz", "mark"]); expect(realLooking("flowers.stage")).toEqual(["flowers.stage", "flowers"]); }); it("is the same credit as @domi/ui's, word for word", () => { expect([CREDIT.phrase, CREDIT.url, CREDIT.notice]).toEqual([DOMI_ATTRIBUTION.phrase, DOMI_ATTRIBUTION.url, DOMI_ATTRIBUTION.copyright]); }); it("leaves out only the licence's credit, exactly as written", () => { expect(realLooking("Built on Domi · Copyright (c) 2026 Marek Novák https://aula.marek-novak.cz")).toEqual([]); expect(realLooking("Marek's server at https://aula.marek-novak.cz/hosts")).toContain("marek"); expect(realLooking("files.marek-novak.cz")).toEqual(["files.marek-novak.cz", "marek", "novak"]); }); }); describe("the release's screenshots from the demo control plane", () => { for (const shot of SHOTS) { it(`${shot.name}: drawn from invented data only`, async () => { start(shot.path); for (const sel of shot.click ?? []) { const el = await waitFor(() => { const e = document.querySelector(sel); expect(e, `click ${sel}`).not.toBeNull(); return e as HTMLElement; }, { timeout: 5000 }); el.click(); } await waitFor(() => expect(document.querySelector(shot.wait), `wait ${shot.wait}`).not.toBeNull(), { timeout: 5000 }); expect(served.filter((s) => s.status === 404).map((s) => s.path)).toEqual([]); // Control's codes (apply.kept, pki.renew_due) are dotted words, not names. const json = served.map((s) => (s.text ?? "").replace(/"(?:code|message_code|error_code)":"[^"]*"/g, "")); const seen = [...json, ...pageText()]; expect(seen.flatMap(realLooking)).toEqual([]); }); } });