import type { Page } from "@playwright/test"; import type { BuildModel, BuildTool, MavenDependency } from "../src/platform/ipc"; import { expect, stubDesktop, test } from "./fixtures"; const jsonCore: MavenDependency = { groupId: "com.example.json", artifactId: "json-core", version: "2.1.0", type: "jar", classifier: null, scope: "compile", optional: false, children: [], }; const model: BuildModel = { maven: { projects: [ { pom: "pom.xml", dir: "", groupId: "com.example", artifactId: "orders", version: "1.0.0", packaging: "jar", displayName: "Orders service", parent: null, modules: [], aggregated: false, plugins: [], dependencies: [ jsonCore, { ...jsonCore, artifactId: "json-mapper", children: [{ ...jsonCore, version: "2.0.0", omitted: "conflict", conflictWith: "2.1.0" }], }, ], profiles: [], javaVersion: 21, command: "mvn", options: [], env: {}, }, ], profiles: [], syncedAt: 1, stale: false, syncError: null, }, gradle: [ { dir: "", command: "gradle", env: {}, javaVersion: 21, syncedAt: 1, stale: false, syncError: null, projects: [{ path: ":", name: "orders", dir: "", buildFile: "build.gradle", tasks: [] }], }, ], }; async function showTool(page: Page, tool: BuildTool) { await stubDesktop(page); await page.evaluate( async ({ tool, model }) => { window.__ipc.handlers.build_model = () => model; window.__ipc.handlers.run_configs = () => []; const buildStore = "/src/features/build-tools/store.ts"; await (await import(/* @vite-ignore */ buildStore)).loadModel(); const layout = "/src/workbench/toolwindows/store.ts"; const { setToolWindowSize, showToolWindow } = await import(/* @vite-ignore */ layout); showToolWindow(tool, true); setToolWindowSize("right", 190); }, { tool, model }, ); } async function setWidth(page: Page, width: number) { await page.evaluate(async (px) => { const layout = "/src/workbench/toolwindows/store.ts"; (await import(/* @vite-ignore */ layout)).setToolWindowSize("right", px); }, width); } for (const tool of ["maven", "gradle"] as const) { const name = tool === "maven" ? "Maven" : "Gradle"; test(`${name} keeps its toolbar actions reachable as the pane resizes`, async ({ workbench: page }) => { await showTool(page, tool); const toolbar = page.getByRole("toolbar", { name: `${name} actions` }); const more = toolbar.getByRole("button", { name: "More Actions", exact: true }); const menu = page.getByRole("menu", { name: "More Actions", exact: true }); const skipTests = "Toggle 'Skip Tests' Mode"; await expect(toolbar.getByRole("button", { name: `Reload All ${name} Projects` })).toBeVisible(); await expect(toolbar.getByRole("button", { name: new RegExp(`Execute ${name}`) })).toBeVisible(); await expect(page.getByRole("tree", { name: `${name} projects` })).toBeVisible(); expect(await toolbar.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); await more.click(); await expect(menu.getByRole("menuitem", { name: "Analyze Dependencies…" })).toBeVisible(); await expect(menu.getByRole("menuitem", { name: "Expand All" })).toBeVisible(); await menu.getByRole("menuitemcheckbox", { name: skipTests, checked: false }).click(); await expect(menu).toBeHidden(); await more.click(); await expect(menu.getByRole("menuitemcheckbox", { name: skipTests, checked: true })).toBeVisible(); await setWidth(page, 360); await expect(menu).toBeHidden(); await expect(more).toBeHidden(); await expect(toolbar.getByRole("button", { name: skipTests, pressed: true })).toBeVisible(); await expect(toolbar.getByRole("button", { name: "Collapse All" })).toBeVisible(); await setWidth(page, 190); await expect(more).toBeVisible(); await expect(menu).toBeHidden(); }); } test("Dependency Analyzer pairs its pane controls and stacks usages in a narrow editor", async ({ workbench: page, }) => { await page.setViewportSize({ width: 1360, height: 780 }); await showTool(page, "maven"); const toolActions = page.getByRole("toolbar", { name: "Maven actions" }); await toolActions.getByRole("button", { name: "More Actions", exact: true }).click(); await page.getByRole("menuitem", { name: "Analyze Dependencies…", exact: true }).click(); const filters = page.getByRole("toolbar", { name: "Dependency Analyzer", exact: true }); const resolved = page.getByRole("heading", { name: "Resolved Dependencies", exact: true }); const usages = page.getByRole("heading", { name: "Usages of com.example.json:json-core:2.1.0", exact: true }); const dependencies = page.getByRole("tree", { name: "Dependencies", exact: true }); const core = dependencies.getByRole("treeitem", { name: /^com\.example\.json:json-core\b/ }); const treeMode = page.getByRole("button", { name: "Show as Tree", exact: true }); const conflicts = filters.getByRole("button", { name: "Show conflicts only", exact: true }); await expect(resolved).toBeVisible(); await expect(filters.getByRole("button", { name: "Show as Tree" })).toHaveCount(0); await treeMode.click(); await expect(treeMode).toHaveAttribute("aria-pressed", "true"); await page.getByRole("button", { name: "Show as List", exact: true }).click(); await conflicts.press("Space"); await expect(conflicts).toHaveAttribute("aria-pressed", "true"); await expect(dependencies.getByRole("treeitem")).toHaveCount(1); await core.click(); await expect(usages).toBeVisible(); await expect(page.getByText("omitted for conflict with 2.1.0")).toBeVisible(); const wideLeft = (await resolved.boundingBox())!; const wideRight = (await usages.boundingBox())!; expect(Math.abs(wideLeft.y - wideRight.y)).toBeLessThan(1); expect(wideRight.x).toBeGreaterThan(wideLeft.x + wideLeft.width); await page.setViewportSize({ width: 790, height: 780 }); await expect .poll(async () => (await usages.boundingBox())!.y - (await resolved.boundingBox())!.y) .toBeGreaterThan(100); expect(Math.abs((await usages.boundingBox())!.x - (await resolved.boundingBox())!.x)).toBeLessThan(1); expect(await filters.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1); await expect(core).toHaveAttribute("aria-selected", "true"); await expect(page.getByRole("button", { name: "Copy Coordinates" })).toBeInViewport({ ratio: 1 }); });