import { expect, test } from "@playwright/test"; /** * Member-facing Tech Tree (/intelligence/tech-tree): read-only canvas sharing * the admin node cards, blackout veil cards for locked technologies, the * dossier side panels, and the node-click detail dialog. Seeded via the * cookie-authed REST API like the admin tech-tree suite; seeded docs are * removed at the end so later specs inherit a clean catalog. */ test.describe("Frontend Tech Tree", () => { const RUN = `fte-${Date.now().toString(36)}`; const seededTechIds: number[] = []; async function login(page: import("@playwright/test").Page) { await page.goto("/login"); await page.getByLabel("Username").fill("dev"); await page.getByLabel("Password").fill("Test123"); await page.getByRole("button", { name: "Log in" }).click(); await page.waitForURL((url) => !url.pathname.startsWith("/login"), { timeout: 60_000 }); } async function createTech( page: import("@playwright/test").Page, data: Record, ): Promise { const res = await page.request.post("/api/technologies", { data }); expect(res.ok(), `tech create failed: ${res.status()} ${await res.text()}`).toBe(true); const body = await res.json(); const id = (body.doc as { id: number }).id; seededTechIds.push(id); return id; } test.afterEach(async ({ page }) => { await page.goto("/").catch(() => {}); for (const id of seededTechIds.splice(0)) { await page.request.delete(`/api/technologies/${id}`).catch(() => {}); } }); test("renders the tree with veil cards and opens the detail dialog", async ({ page }) => { await login(page); const openName = `${RUN} Open Research`; const veiledName = `${RUN} Veiled Branch`; const hiddenName = `${RUN} Unapproved Draft`; const openId = await createTech(page, { name: openName, type: "asset", summary: "An approved technology ready for voting.", approvalStatus: "approved", researchCosts: { minimumResearchDuration: 1, maximumResearchDuration: 10 }, }); await createTech(page, { name: veiledName, type: "upgrade", summary: "Approved but gated behind a prerequisite.", approvalStatus: "approved", requirements: { prerequisiteTechnologies: [ { requiresAnd: { technology: [openId] }, requiresOr: { technology: [] } }, ], }, researchCosts: { minimumResearchDuration: 1, maximumResearchDuration: 5 }, }); await createTech(page, { name: hiddenName, type: "upgrade", summary: "Not approved yet; must not render at all.", approvalStatus: "in_progress", researchCosts: { minimumResearchDuration: 1, maximumResearchDuration: 5 }, }); // Sidebar entry under Intelligence. await page.goto("/intelligence/campaigns"); await expect(page.getByRole("link", { name: "Tech Tree" })).toBeVisible({ timeout: 30_000 }); await page.goto("/intelligence/tech-tree"); await expect(page.getByTestId("frontend-tech-tree-canvas")).toBeVisible({ timeout: 60_000 }); // Approved tech renders with the shared admin card + available overlay. await expect(page.getByTestId(`tech-node-${openId}`)).toBeVisible(); await expect(page.getByText("Available // votable").first()).toBeVisible(); // Locked-but-approved tech renders as a blackout veil without its name. await expect(page.getByTestId("tech-veil-node").first()).toBeVisible(); await expect(page.getByText(veiledName)).toHaveCount(0); // Unapproved tech never renders. await expect(page.getByText(hiddenName)).toHaveCount(0); // Dossier side panels are present (research disabled => standby states). await expect(page.getByText("No open ballot.")).toBeVisible(); await expect(page.getByText("R&D // UNIT CAPACITY")).toBeVisible(); // Node click opens the detail dialog with summary + costs. await page.getByTestId(`tech-node-${openId}`).click(); await expect(page.getByRole("dialog")).toBeVisible(); await expect(page.getByText("An approved technology ready for voting.")).toBeVisible(); await expect(page.getByText("Research costs")).toBeVisible(); }); });