import { _electron as electron, expect, test, type Page } from "@playwright/test"; import { mkdirSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; import { randomUUID } from "node:crypto"; test("onboards, hires, and creates work in the Electron shell", async () => { const profileDir = join(tmpdir(), `agentcompany-new-e2e-${randomUUID()}`); mkdirSync(profileDir, { recursive: true }); const app = await electron.launch({ args: [resolve("out/main/index.js")], env: { ...process.env, AGENTCOMPANY_NEW_PROFILE_DIR: profileDir, }, }); try { const page = await app.firstWindow(); await expect(page.getByRole("heading", { name: "Welcome" })).toBeVisible(); await page.getByRole("button", { name: "Get started" }).click(); await page.getByLabel("API key").fill("e2e-secret"); await page.getByRole("button", { name: "Continue" }).click(); await page.getByLabel("Company name").fill("Acme Operations"); await page.getByLabel("Your name").fill("Dana Lee"); await page.getByLabel("Description").fill("Coordinate agents with auditable approvals."); await page.getByRole("button", { name: "Continue" }).click(); await page.getByRole("button", { name: "Continue" }).click(); await page.getByLabel("Goal").fill("Ship a verified control plane."); await page.getByLabel("Acceptance criteria").fill("The CEO creates the kickoff operating loop."); await page.getByRole("button", { name: "Launch" }).click(); await expect(page.getByRole("heading", { name: "Acme Operations" })).toBeVisible(); await page.getByRole("button", { name: "Team" }).click(); await page.getByRole("button", { name: "Hire" }).click(); await page.getByLabel("Name").fill("Alex Chen"); await page.getByLabel("Role").fill("CTO"); await page.getByLabel("Department").fill("Engineering"); await page.getByLabel("Monthly budget").fill("250"); await page.locator(".modal").getByRole("button", { name: "Hire" }).click(); await expect(page.getByText("Alex Chen").first()).toBeVisible(); await page.getByRole("button", { name: "Work" }).click(); await page.getByRole("button", { name: "New task" }).click(); await page.getByLabel("Title").fill("Production deploy"); await page.getByLabel("Description").fill("Deploy a high-risk change."); await page.getByLabel("Risk").selectOption("high"); await page.locator(".modal").getByRole("button", { name: "Create" }).click(); await expect(page.getByText("Production deploy").first()).toBeVisible(); await page.getByRole("button", { name: "Approvals" }).click(); await expect(page.getByText("Production deploy").first()).toBeVisible(); await page.getByRole("button", { name: "Messages" }).click(); await page.getByRole("button", { name: "New space" }).click(); await page.getByLabel("Name").fill("release"); await page.getByLabel("Topic").fill("Release coordination"); await page.locator(".modal").getByRole("button", { name: "Create" }).click(); await expect(page.getByText("release").first()).toBeVisible(); await page.getByRole("textbox", { name: "Message" }).fill("Release channel opened."); await page.getByRole("button", { name: "Send" }).click(); await expect(page.getByText("Release channel opened.")).toBeVisible(); await verifyPagesDoNotOverflow(page); } finally { await app.close(); } }); async function verifyPagesDoNotOverflow(page: Page): Promise { for (const size of [{ width: 1280, height: 860 }, { width: 980, height: 700 }]) { await page.setViewportSize(size); for (const nav of ["Home", "Team", "Work", "Messages", "Files", "Approvals", "Social", "Settings"]) { await page.getByRole("button", { name: nav }).click(); await expectPageToFit(page); } for (const tab of ["Providers", "Skills", "Policies", "Migration"]) { await page.getByRole("button", { name: "Settings" }).click(); await page.getByRole("button", { name: tab }).click(); await expectPageToFit(page); } } } async function expectPageToFit(page: Page): Promise { const dimensions = await page.evaluate(() => ({ documentScrollWidth: document.documentElement.scrollWidth, documentClientWidth: document.documentElement.clientWidth, bodyScrollWidth: document.body.scrollWidth, bodyClientWidth: document.body.clientWidth, })); expect(dimensions.documentScrollWidth).toBeLessThanOrEqual(dimensions.documentClientWidth + 1); expect(dimensions.bodyScrollWidth).toBeLessThanOrEqual(dimensions.bodyClientWidth + 1); }