|
| 1 | +// End-to-end proof of the `hideBrand` host flag: an embedder that supplies its own |
| 2 | +// branding can suppress the engine's "sideshow" wordmark. With the flag off |
| 3 | +// (self-hosted default) the wordmark renders as before, so parity holds. |
| 4 | +// |
| 5 | +// Same harness as embed-main-slot.spec.ts. |
| 6 | +import { readFileSync } from "node:fs"; |
| 7 | +import { fileURLToPath } from "node:url"; |
| 8 | +import { expect, publish, test } from "./fixtures.ts"; |
| 9 | + |
| 10 | +const embedDir = fileURLToPath(new URL("../viewer/dist-embed", import.meta.url)); |
| 11 | + |
| 12 | +function contentType(path: string): string { |
| 13 | + if (path.endsWith(".js") || path.endsWith(".mjs")) return "text/javascript"; |
| 14 | + if (path.endsWith(".wasm")) return "application/wasm"; |
| 15 | + if (path.endsWith(".css")) return "text/css"; |
| 16 | + return "application/octet-stream"; |
| 17 | +} |
| 18 | + |
| 19 | +const embedHtml = (hideBrand: boolean) => `<!doctype html> |
| 20 | +<html><head><meta charset="utf-8"><style>html,body{margin:0;height:100%}#m{position:fixed;inset:0}</style></head> |
| 21 | +<body><div id="m"></div> |
| 22 | +<script type="module"> |
| 23 | + import { mountViewer } from "/__embed/engine.js"; |
| 24 | + mountViewer(document.getElementById("m"), { |
| 25 | + basePath: "", |
| 26 | + hideBrand: ${hideBrand ? "true" : "false"}, |
| 27 | + router: { get: () => ({ sessionId: null }), navigate() {}, subscribe() { return () => {}; } }, |
| 28 | + }); |
| 29 | +</script></body></html>`; |
| 30 | + |
| 31 | +async function mount(page: import("@playwright/test").Page, serverUrl: string, hideBrand: boolean) { |
| 32 | + page.on("pageerror", (e) => console.error("[pageerror]", e.message)); |
| 33 | + const path = `/__embedtest-brand-${hideBrand ? "off" : "on"}`; |
| 34 | + await page.route(`**${path}`, (route) => |
| 35 | + route.fulfill({ contentType: "text/html", body: embedHtml(hideBrand) }), |
| 36 | + ); |
| 37 | + await page.route("**/__embed/**", (route) => { |
| 38 | + const name = new URL(route.request().url()).pathname.replace("/__embed/", ""); |
| 39 | + route.fulfill({ contentType: contentType(name), body: readFileSync(`${embedDir}/${name}`) }); |
| 40 | + }); |
| 41 | + await page.goto(`${serverUrl}${path}`); |
| 42 | +} |
| 43 | + |
| 44 | +test("hideBrand: true suppresses the engine wordmark", async ({ page, server }) => { |
| 45 | + await publish(server.url, { html: "<p>card</p>", title: "Seeded", agent: "e2e" }, ""); |
| 46 | + await mount(page, server.url, true); |
| 47 | + await expect(page.locator("aside")).toBeVisible(); |
| 48 | + await expect(page.locator(".brand")).toHaveCount(0); |
| 49 | +}); |
| 50 | + |
| 51 | +test("hideBrand off (self-hosted default): the wordmark renders", async ({ page, server }) => { |
| 52 | + await publish(server.url, { html: "<p>card</p>", title: "Seeded", agent: "e2e" }, ""); |
| 53 | + await mount(page, server.url, false); |
| 54 | + await expect(page.locator("aside .brand")).toBeVisible(); |
| 55 | +}); |
0 commit comments