// Exercise the REAL component after build-knowledge-map-preview.mjs. import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import { resolve } from "node:path"; import { pathToFileURL } from "node:url"; import { chromium } from "playwright"; const browser = await chromium.launch(); try { for (const width of [320, 390, 1280]) { const page = await browser.newPage({ viewport: { width, height: 900 } }); await page.goto(pathToFileURL(resolve(".tmp/knowledge-map-preview/index-dark.html")).href); await page .getByRole("button", { name: "Explore @example/search, package", exact: true }) .focus(); await page.keyboard.press("Enter"); assert.equal( await page.locator(".ui-map-center").evaluate((node) => node === document.activeElement), true, "keyboard traversal retains focus on the selected node", ); await page.getByRole("heading", { name: "Projects built with this" }).waitFor(); assert.equal( await page.getByRole("list", { name: "Recorded connections" }).getByRole("button").count(), 2, ); await page.getByRole("button", { name: "Back", exact: true }).click(); await page.getByRole("heading", { name: "Atlas", exact: true }).waitFor(); await page.getByRole("textbox", { name: "Search your map" }).fill("Canvs"); assert.equal( await page.locator(".ui-map-results .ui-map-result").count(), 1, "typo-tolerant SearchKit matches Canvas", ); await page.getByRole("textbox", { name: "Search your map" }).fill("unfindable"); await page.getByRole("button", { name: "Show everything", exact: true }).click(); assert.equal(await page.locator(".ui-map-results .ui-map-result").count(), 6); const [handoff] = await Promise.all([ page.waitForEvent("download"), page.getByRole("button", { name: "Markdown", exact: true }).click(), ]); const brief = await readFile(await handoff.path(), "utf8"); assert(brief.includes("Atlas — project handoff")); assert(brief.includes("not independently verified")); assert( !brief.includes("Customer research"), "a project handoff excludes personal/concept neighbors", ); await page.getByRole("button", { name: "Agent-readable map", exact: true }).click(); await page.getByRole("button", { name: "Download private JSON", exact: true }).waitFor(); assert((await page.locator(".ui-map-export").textContent()).includes("remembered people")); const [snapshot] = await Promise.all([ page.waitForEvent("download"), page.getByRole("button", { name: "Download private JSON", exact: true }).click(), ]); const exported = JSON.parse(await readFile(await snapshot.path(), "utf8")); assert.equal(exported.version, 1); assert.equal(exported.visibility, "private"); assert.equal(exported.nodes.length, 6); await page.getByRole("button", { name: "Cancel", exact: true }).click(); assert.equal(await page.locator(".ui-map-export").count(), 0); assert.equal( await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false, ); const small = await page .locator(".ui-map-satellite, .ui-map-result, .ui-map-actions button") .evaluateAll( (nodes) => nodes.filter((node) => { const rect = node.getBoundingClientRect(); return rect.width < 44 || rect.height < 44; }).length, ); assert.equal(small, 0, "map touch targets are at least 44px"); console.log( `${width}px: navigation, history, fuzzy search, private export disclosure and touch targets passed`, ); await page.close(); } for (const width of [320, 1280]) { const page = await browser.newPage({ viewport: { width, height: 900 } }); await page.goto( pathToFileURL(resolve(".tmp/knowledge-map-preview/index-dark.html")).href + "?busy=1", ); await page.locator(".ui-map-satellite").first().waitFor(); assert.equal(await page.locator(".ui-map-satellite").count(), 8); assert.equal(await page.locator(".ui-map-result").count(), 30); assert.equal( await page.getByRole("list", { name: "Recorded connections" }).getByRole("button").count(), 100, ); assert.equal( await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false, ); const overlap = await page.locator(".ui-map-satellite, .ui-map-center").evaluateAll((nodes) => { const boxes = nodes.map((node) => node.getBoundingClientRect()); return boxes.some((a, i) => boxes.some( (b, j) => j > i && a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top, ), ); }); assert.equal(overlap, false, "focused labels and touch targets do not collide"); const clippedRows = await page.locator(".ui-map-detail .ui-listrow").evaluateAll( (nodes) => nodes.filter((node) => { const row = node.getBoundingClientRect(); const secondary = node.querySelector(".ui-listrow-secondary")?.getBoundingClientRect(); return secondary && secondary.bottom > row.bottom + 1; }).length, ); assert.equal(clippedRows, 0, "scroll containers never squeeze row text into the next row"); await page .locator(".ui-map-detail") .screenshot({ path: `.tmp/knowledge-map-preview/busy-detail-${width}.png` }); console.log( `${width}px: 500-node workspace keeps directory, canvas and relationship DOM bounded; no collisions`, ); await page.close(); } const workspace = await browser.newPage({ viewport: { width: 390, height: 900 } }); await workspace.goto( pathToFileURL(resolve(".tmp/knowledge-map-preview/index-dark.html")).href + "?workspace=1", ); await workspace.getByText("Shared with this workspace").waitFor(); await workspace.getByText("Review @example/search", { exact: true }).waitFor(); await workspace.getByRole("button", { name: "Explore Atlas, project", exact: true }).click(); await workspace.getByRole("heading", { name: "Atlas", exact: true }).waitFor(); assert.equal(await workspace.getByRole("button", { name: "Copy agent handoff" }).count(), 0); assert.equal(await workspace.getByRole("button", { name: "Agent-readable map" }).count(), 0); console.log("workspace adapter: custom lens and record action work with exports disabled"); await workspace.close(); } finally { await browser.close(); }