|
| 1 | +// End-to-end browser proof of the `homeView` host flag: when an embedder owns its |
| 2 | +// own session-less landing (e.g. sideshow cloud's "Home" feed), the engine must NOT |
| 3 | +// auto-pick a session on boot — it stays session-less so nothing is highlighted |
| 4 | +// behind the host's landing. With the flag OFF (self-hosted default) the engine |
| 5 | +// auto-selects the latest session exactly as before, so parity is preserved. |
| 6 | +// |
| 7 | +// Same harness as embed-main-slot.spec.ts: publish a real surface (which creates a |
| 8 | +// session), then mount the engine with a router whose route carries NO session |
| 9 | +// (`sessionId: null`) — the host's home state — and toggle `homeView`. |
| 10 | +import { readFileSync } from "node:fs"; |
| 11 | +import { fileURLToPath } from "node:url"; |
| 12 | +import { expect, publish, test } from "./fixtures.ts"; |
| 13 | + |
| 14 | +const embedDir = fileURLToPath(new URL("../viewer/dist-embed", import.meta.url)); |
| 15 | + |
| 16 | +function contentType(path: string): string { |
| 17 | + if (path.endsWith(".js") || path.endsWith(".mjs")) return "text/javascript"; |
| 18 | + if (path.endsWith(".wasm")) return "application/wasm"; |
| 19 | + if (path.endsWith(".css")) return "text/css"; |
| 20 | + return "application/octet-stream"; |
| 21 | +} |
| 22 | + |
| 23 | +// Mount with a session-less route (the host's home state) and a togglable homeView. |
| 24 | +const embedHtml = (homeView: boolean) => `<!doctype html> |
| 25 | +<html><head><meta charset="utf-8"><style>html,body{margin:0;height:100%}#m{position:fixed;inset:0}</style></head> |
| 26 | +<body><div id="m"></div> |
| 27 | +<script type="module"> |
| 28 | + import { mountViewer } from "/__embed/engine.js"; |
| 29 | + mountViewer(document.getElementById("m"), { |
| 30 | + basePath: "", |
| 31 | + homeView: ${homeView ? "true" : "false"}, |
| 32 | + router: { |
| 33 | + get: () => ({ sessionId: null }), |
| 34 | + navigate() {}, |
| 35 | + subscribe() { return () => {}; }, |
| 36 | + }, |
| 37 | + }); |
| 38 | +</script></body></html>`; |
| 39 | + |
| 40 | +async function mount(page: import("@playwright/test").Page, serverUrl: string, homeView: boolean) { |
| 41 | + page.on("pageerror", (e) => console.error("[pageerror]", e.message)); |
| 42 | + page.on("console", (m) => m.type() === "error" && console.error("[console]", m.text())); |
| 43 | + const path = `/__embedtest-home-${homeView ? "on" : "off"}`; |
| 44 | + await page.route(`**${path}`, (route) => |
| 45 | + route.fulfill({ contentType: "text/html", body: embedHtml(homeView) }), |
| 46 | + ); |
| 47 | + await page.route("**/__embed/**", (route) => { |
| 48 | + const name = new URL(route.request().url()).pathname.replace("/__embed/", ""); |
| 49 | + route.fulfill({ contentType: contentType(name), body: readFileSync(`${embedDir}/${name}`) }); |
| 50 | + }); |
| 51 | + await page.goto(`${serverUrl}${path}`); |
| 52 | +} |
| 53 | + |
| 54 | +test("homeView: a session-less route lands with NO session selected", async ({ page, server }) => { |
| 55 | + // Seed a real session so the sidebar has something to (not) select. |
| 56 | + await publish(server.url, { html: "<p>card</p>", title: "Seeded", agent: "e2e" }, ""); |
| 57 | + |
| 58 | + await mount(page, server.url, true); |
| 59 | + |
| 60 | + // The session loads into the sidebar... |
| 61 | + await expect(page.locator("aside .sess").first()).toBeVisible(); |
| 62 | + // ...but none is selected, and the engine never auto-opened the session (its |
| 63 | + // post cards aren't loaded — the stream stays empty behind the host's home). |
| 64 | + await expect(page.locator(".sess.sel")).toHaveCount(0); |
| 65 | + await expect(page.locator(".sess[aria-current='true']")).toHaveCount(0); |
| 66 | + await expect(page.locator(".card:not(#whatsNew)")).toHaveCount(0); |
| 67 | +}); |
| 68 | + |
| 69 | +test("homeView OFF (self-hosted default): a session-less route auto-selects the latest", async ({ |
| 70 | + page, |
| 71 | + server, |
| 72 | +}) => { |
| 73 | + await publish(server.url, { html: "<p>card</p>", title: "Seeded", agent: "e2e" }, ""); |
| 74 | + |
| 75 | + await mount(page, server.url, false); |
| 76 | + |
| 77 | + // Parity: with the flag off the engine auto-selects the one session and opens it. |
| 78 | + await expect(page.locator(".sess.sel")).toHaveCount(1); |
| 79 | + await expect(page.locator("#stream")).toBeVisible(); |
| 80 | +}); |
0 commit comments