import { expect, ipcCalls, stubDesktop, test } from "./fixtures"; test.use({ video: "on" }); test("offers file templates for the selected workspace member", async ({ workbench: page }) => { await stubDesktop(page); await page.evaluate(async () => { const markers: Record = { "/work/api": ["go.mod"], "/work/web": ["pom.xml"], "/work/library": ["pom.xml"], "/work/tutor": ["package.json", "vite.config.ts"], }; window.__ipc.handlers.fs_read_dir = ({ path }) => { const files = (markers[String(path)] ?? []).map((name) => ({ name, path: `${path}/${name}`, kind: "file", size: 0, mtimeMs: 0, })); return path === "/work/tutor" ? [...files, { name: "src", path: "/work/tutor/src", kind: "dir", size: 0, mtimeMs: 0 }] : files; }; const backend = "/src/editor/core/backend.ts"; const { docBackend } = await import(/* @vite-ignore */ backend); window.__ipc.handlers.fs_create_file = ({ path }) => { docBackend().files.set(String(path), ""); return null; }; window.__ipc.handlers.run_configs = () => [ { id: "workspace:web:tomcat", name: "Web / Tomcat", kind: "tomcat", command: "catalina", args: ["run"], cwd: "/work/web", module: "/work/web", env: {}, detected: true, isTest: false, debugAdapter: null, }, ]; window.__ipc.handlers.project_roots = () => ({ folders: [] }); const module = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ module); const current = useProject.getState().project; useProject.setState({ project: { ...current, name: "Workspace", root: "/workspace", workspace: { version: 1, name: "Workspace", projects: Object.keys(markers) }, }, }); }); const newMenu = async (path: string) => { await page.locator(`[data-project-path="${path}"]`).click({ button: "right" }); await page.getByRole("menuitem", { name: "New", exact: true }).hover(); await expect(page.getByRole("menuitem", { name: "From Template…", exact: true })).toBeVisible(); }; await newMenu("/work/api"); await expect(page.getByRole("menuitem", { name: "Go File", exact: true })).toBeVisible(); await page.screenshot({ path: test.info().outputPath("go-new-menu.png"), animations: "disabled" }); await expect(page.getByRole("menuitem", { name: "Go Module", exact: true })).toBeVisible(); await expect(page.getByRole("menuitem", { name: "JSON File", exact: true })).toBeVisible(); await expect(page.getByRole("menuitem", { name: "Java Class", exact: true })).toHaveCount(0); await expect(page.getByRole("menuitem", { name: "Svelte Component", exact: true })).toHaveCount(0); await expect(page.getByRole("menuitem", { name: "Tomcat Context Descriptor", exact: true })).toHaveCount(0); await page.keyboard.press("Escape"); await page.keyboard.press("Escape"); await newMenu("/work/web"); await expect(page.getByRole("menuitem", { name: "Java Class", exact: true })).toBeVisible(); await expect(page.getByRole("menuitem", { name: "Tomcat Context Descriptor", exact: true })).toBeVisible(); await expect(page.getByRole("menuitem", { name: "Go File", exact: true })).toHaveCount(0); await expect(page.getByRole("menuitem", { name: "TypeScript File", exact: true })).toBeVisible(); await page.screenshot({ path: test.info().outputPath("tomcat-new-menu.png"), animations: "disabled" }); await page.keyboard.press("Escape"); await page.keyboard.press("Escape"); await page.locator('[data-project-path="/work/library"]').click(); await page.keyboard.press("Meta+n"); const popup = page.getByRole("dialog", { name: "New", exact: true }); await expect(popup.getByText("Java Class", { exact: true })).toBeVisible(); await expect(popup.getByText("Tomcat Context Descriptor", { exact: true })).toHaveCount(0); await expect(popup.getByText("Go File", { exact: true })).toHaveCount(0); await page.keyboard.press("Escape"); const tutor = page.getByRole("treeitem", { name: "tutor /work/tutor", exact: true }); if ((await tutor.getAttribute("aria-expanded")) !== "true") await tutor.locator("[data-tree-toggle]").click(); await newMenu("/work/tutor/src"); const component = page.getByRole("menuitem", { name: "Svelte Component", exact: true }); await expect(component).toBeVisible(); await page.screenshot({ path: test.info().outputPath("svelte-new-menu.png"), animations: "disabled" }); await component.click(); const svelte = page.getByRole("dialog", { name: "New Svelte Component", exact: true }); const name = svelte.getByRole("textbox", { name: "Name", exact: true }); await name.fill("+page.svelte"); await name.press("Enter"); await expect(svelte).toBeHidden(); expect(await ipcCalls(page, "fs_create_file")).toEqual([{ path: "/work/tutor/src/+page.svelte" }]); await expect(page.getByRole("tab", { name: "+page.svelte" })).toHaveAttribute("aria-selected", "true"); await expect(page.locator(".cm-content")).toContainText("