import { expect, stubDesktop, test } from "./fixtures"; test("keeps local and remote projects flat in all recent-project lists without row overlap", async ({ workbench: page, }) => { await page.setViewportSize({ width: 980, height: 740 }); await stubDesktop(page); await page.evaluate(async () => { const localProjects = [ { path: "/Users/dev/git/gocommon", name: "gocommon", openedAtMs: 70_000, branch: "main" }, { path: "/Users/dev/git/openidea_all", name: "openidea_all", openedAtMs: 40_000, branch: null }, { path: "/Users/dev/git/superpowers", name: "superpowers", openedAtMs: 20_000, branch: "main" }, ]; const remoteProjects = [ { target: { kind: "ssh", config: "devbox" }, path: "/home/coder/git/openidea_all", name: "openidea_all", host: "dev@devbox.coder:22", openedAtMs: 100_000, }, { target: { kind: "ssh", config: "mbp1" }, path: "/Users/dev/git/gocommon", name: "gocommon", host: "dev-mbp1.local", openedAtMs: 90_000, }, { target: { kind: "ssh", config: "devbox" }, path: "/home/coder/git/gocommon", name: "gocommon", host: "dev@devbox.coder:22", openedAtMs: 60_000, }, { target: { kind: "wsl", distro: "Ubuntu-24.04" }, path: "/home/dev/git/openidea_all", name: "openidea_all", host: "Ubuntu-24.04", openedAtMs: 30_000, }, ]; localStorage.setItem("openidea.remote.recent", JSON.stringify(remoteProjects)); window.__ipc.handlers.recent_projects = () => localProjects; window.__ipc.handlers.recent_project_groups = () => []; window.__ipc.handlers.app_info = () => ({ version: "0.1.55" }); window.__ipc.handlers.window_open_projects = () => [ { name: "openidea_all", root: "/Users/dev/git/openidea_all", current: true, remote: null }, { name: "openidea_all", root: "/home/coder/git/openidea_all", current: false, remote: { kind: "ssh", config: "devbox" }, }, ]; const projectMod = "/src/platform/project.ts"; const recentMod = "/src/features/welcome/recent.ts"; const { useProject } = await import(/* @vite-ignore */ projectMod); const { loadRecent, useRecent } = await import(/* @vite-ignore */ recentMod); await loadRecent(); useRecent.setState({ home: "/Users/dev" }); const prev = useProject.getState().project; if (prev) { useProject.setState({ project: { ...prev, name: "openidea_all", displayName: "openidea_all", root: "/Users/dev/git/openidea_all" }, }); } }); // 1. The project widget uses the same row layout for local and remote projects. await page.getByRole("button", { name: "openidea_all" }).click(); const projectPopup = page.getByRole("dialog", { name: "Projects" }); await expect(projectPopup).toBeVisible(); await expect(projectPopup).toContainText("Open Projects"); await expect(projectPopup).toContainText("Recent Projects"); await expect(projectPopup).toContainText("dev-mbp1.local"); await expect(projectPopup.getByText("Local", { exact: true })).toHaveCount(0); await expect(projectPopup).toContainText("Ubuntu-24.04"); // The two section headers and every project badge share the same left inset. const headers = [ projectPopup.getByText("Open Projects", { exact: true }), projectPopup.getByText("Recent Projects", { exact: true }), ]; const headerMetrics = await Promise.all( headers.map((header) => header.evaluate((el) => { const style = getComputedStyle(el); const rect = el.getBoundingClientRect(); return { x: rect.x + parseFloat(style.paddingLeft), height: rect.height, fontSize: style.fontSize }; }), ), ); expect(headerMetrics[1]).toEqual(headerMetrics[0]); const projectRows = projectPopup.getByRole("option").filter({ hasText: "/git/" }); await expect(projectRows).toHaveCount(7); await expect(projectRows.locator("[data-remote-badge]")).toHaveCount(4); const rowMetrics = await projectRows.evaluateAll((rows) => rows.map((el) => ({ x: el.firstElementChild!.getBoundingClientRect().x, height: el.getBoundingClientRect().height, })), ); for (const row of rowMetrics) expect(row.x).toBeCloseTo(headerMetrics[0]!.x, 0); // Both open projects have no branch metadata and must have identical heights. expect(rowMetrics[0]!.height).toBeCloseTo(rowMetrics[1]!.height, 0); await expect(projectPopup.getByRole("separator")).toHaveCount(2); await page.keyboard.press("Escape"); await expect(projectPopup).toBeHidden(); // 2. Recent Projects popup is flat and never overlaps rows, including search results. await page.evaluate(async () => { const popupMod = "/src/features/welcome/RecentProjectsPopup.tsx"; const { showRecentProjectsPopup } = await import(/* @vite-ignore */ popupMod); showRecentProjectsPopup(); }); const recentDialog = page.getByRole("dialog", { name: "Recent Projects" }); await expect(recentDialog).toBeVisible(); const assertNoVerticalOverlap = async () => { const options = recentDialog.getByRole("option"); const count = await options.count(); expect(count).toBeGreaterThan(1); const boxes = await Promise.all(Array.from({ length: count }, (_, i) => options.nth(i).boundingBox())); for (let i = 1; i < boxes.length; i++) { expect(boxes[i]!.y).toBeGreaterThanOrEqual(boxes[i - 1]!.y + boxes[i - 1]!.height - 0.5); } }; await expect(recentDialog.getByRole("option")).toHaveCount(6); await expect(recentDialog.locator("[aria-expanded]")).toHaveCount(0); await expect(recentDialog.locator("[data-remote-badge]")).toHaveCount(4); await assertNoVerticalOverlap(); await recentDialog.getByRole("textbox", { name: "Search recent projects" }).fill("openidea_all"); await assertNoVerticalOverlap(); await page.keyboard.press("Escape"); await expect(recentDialog).toBeHidden(); // 3. Welcome › Projects keeps all projects in recency order without host headers. await page.evaluate(async () => { const projectMod = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ projectMod); useProject.setState({ project: null, lightEdit: false }); }); const welcomeList = page.getByRole("listbox", { name: "Recent projects" }); const welcomeRows = welcomeList.getByRole("option"); await expect(welcomeRows).toHaveCount(7); await expect(welcomeList.locator("[aria-expanded]")).toHaveCount(0); await expect(welcomeList.locator("[data-remote-badge]")).toHaveCount(4); await expect(welcomeRows.nth(0)).toContainText("dev@devbox.coder:22:/home/coder/git/openidea_all"); await expect(welcomeRows.nth(1)).toContainText("dev-mbp1.local:/Users/dev/git/gocommon"); await expect(welcomeRows.nth(2)).toContainText("~/git/gocommon"); await expect(welcomeRows.nth(3)).toContainText("dev@devbox.coder:22:/home/coder/git/gocommon"); });