import type { Locator, Page } from "@playwright/test"; import { expect, test } from "./fixtures"; const source = "export function outer() {\n function inner() {\n return 1;\n }\n return inner();\n}\n"; const path = "/dev/acme-api/local-appearance.ts"; const initial = { lineNumbers: true, whitespaces: false, gutterIcons: true, indentGuides: true }; const local = { lineNumbers: false, whitespaces: true, gutterIcons: false, indentGuides: false }; const controls = [ { key: "lineNumbers", id: "editor.toggleLocalLineNumbers", alias: "EditorToggleShowLineNumbers" }, { key: "whitespaces", id: "editor.toggleLocalWhitespaces", alias: "EditorToggleShowWhitespaces" }, { key: "gutterIcons", id: "editor.toggleLocalGutterIcons", alias: "EditorToggleShowGutterIcons" }, { key: "indentGuides", id: "editor.toggleLocalIndentGuides", alias: "EditorToggleShowIndentLines" }, ] as const; type Appearance = typeof initial; async function setGlobalAppearance(page: Page, value: Appearance) { await page.evaluate(async (value) => { const projectPath = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ projectPath); const current = useProject.getState().settings; useProject.setState({ settings: { ...current, editor: { ...current?.editor, showWhitespace: value.whitespaces, showGutterIcons: value.gutterIcons, appearance: { ...current?.editor.appearance, lineNumbers: value.lineNumbers, indentGuides: value.indentGuides, }, }, }, }); }, value); } async function runIdeaAction(page: Page, alias: string) { const ran = await page.evaluate(async (alias) => { const actionsPath = "/src/platform/actions.ts"; const rcPath = "/src/features/vim/rc.ts"; const { executeAction } = await import(/* @vite-ignore */ actionsPath); const { resolveActionId } = await import(/* @vite-ignore */ rcPath); return executeAction(resolveActionId(alias)); }, alias); expect(ran).toBe(true); } async function toggled(page: Page, id: string) { return page.evaluate(async (id) => { const actionsPath = "/src/platform/actions.ts"; const { actionToggled, getAction } = await import(/* @vite-ignore */ actionsPath); return actionToggled(getAction(id)); }, id); } async function rendered(pane: Locator): Promise { return { lineNumbers: (await pane.locator(".cm-lineNumbers").count()) > 0, whitespaces: (await pane.locator(".cm-highlightSpace").count()) > 0, gutterIcons: await pane.locator(".cm-openidea-bookmark").isVisible(), indentGuides: (await pane.locator(".cm-openidea-guides").count()) > 0, }; } test("IDEA appearance actions toggle only the active split and survive settings reconfiguration", async ({ workbench: page, }) => { await setGlobalAppearance(page, initial); await page.evaluate( async ({ path, source }) => { const backendPath = "/src/editor/core/backend.ts"; const servicesPath = "/src/workbench/contributions.ts"; const { docBackend } = await import(/* @vite-ignore */ backendPath); const { editorService } = await import(/* @vite-ignore */ servicesPath); docBackend().files.set(path, source); await editorService().openFile(path); }, { path, source }, ); await expect(page.locator(".cm-content")).toBeVisible(); await page.evaluate(async () => { const actionsPath = "/src/platform/actions.ts"; const { executeAction } = await import(/* @vite-ignore */ actionsPath); await executeAction("editor.splitRight"); }); const panes = page.locator("[data-pane-id]"); await expect(panes).toHaveCount(2); const left = panes.first(); const right = panes.last(); await right.locator(".cm-content").focus(); await page.keyboard.press("F3"); await expect(left.locator(".cm-openidea-bookmark")).toBeVisible(); await expect(right.locator(".cm-openidea-bookmark")).toBeVisible(); expect(await rendered(left)).toEqual(initial); const settingsBefore = await page.evaluate(async () => { const projectPath = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ projectPath); return structuredClone(useProject.getState().settings); }); for (const control of controls) { await runIdeaAction(page, control.alias); expect(await toggled(page, control.id)).toBe(local[control.key]); } expect(await rendered(right)).toEqual(local); expect(await rendered(left)).toEqual(initial); expect( await page.evaluate(async () => { const projectPath = "/src/platform/project.ts"; const { useProject } = await import(/* @vite-ignore */ projectPath); return useProject.getState().settings; }), ).toEqual(settingsBefore); // Match the globals to the local values, then move them back: only the untouched split follows. for (const value of [local, initial]) { await setGlobalAppearance(page, value); await page.evaluate(async () => { const controllerPath = "/src/editor/core/controller.ts"; const { editorController } = await import(/* @vite-ignore */ controllerPath); editorController().manager.applySettings(); }); expect(await rendered(right)).toEqual(local); expect(await rendered(left)).toEqual(value); } await left.locator(".cm-content").focus(); for (const control of controls) await expect.poll(() => toggled(page, control.id)).toBe(initial[control.key]); await right.locator(".cm-content").focus(); for (const control of controls) await expect.poll(() => toggled(page, control.id)).toBe(local[control.key]); for (const control of controls) await runIdeaAction(page, control.alias); expect(await rendered(right)).toEqual(initial); expect(await rendered(left)).toEqual(initial); await setGlobalAppearance(page, { ...initial, gutterIcons: false }); await page.evaluate(async () => { const controllerPath = "/src/editor/core/controller.ts"; const { editorController } = await import(/* @vite-ignore */ controllerPath); editorController().manager.applySettings(); }); await expect(right.locator(".cm-openidea-bookmark")).toBeVisible(); await expect(left.locator(".cm-openidea-bookmark")).toBeHidden(); expect(await toggled(page, "editor.toggleLocalGutterIcons")).toBe(true); });