Файли
openidea/e2e/navigationBarPopupLayout.spec.ts
T
Isaac Gallartтаigallart ac9f745dcf feat(navigation-bar): reveal folders in Project on double-click (#7545)
Double-clicking a folder in the navigation bar or in its dropdown now selects it in the Project
view, closes the popup and focuses the tree. A single click still opens the dropdown; a folder
row in the dropdown waits briefly before browsing so a double-click can land on it.

Closes #7555

Co-authored-by: igallart <[email protected]>
2026-12-02 23:18:59 +08:00

328 рядки
15 KiB
TypeScript

import { expect, stubDesktop, test } from "./fixtures";
test("the floating navigation list stays beside the visible segment and scrolls to keyboard selection", async ({
workbench: page,
}) => {
await page.setViewportSize({ width: 600, height: 560 });
const folder = "billing";
const parent =
"/dev/acme-api/quarterly-settlement-and-reconciliation/merchant-accounts-with-exchange-rate-adjustments";
const directory = `${parent}/${folder}`;
const filename = "SettlementSummary.ts";
const path = `${directory}/${filename}`;
const long = "QuarterlyReconciliationForPendingSettlementAndCrossBorderMerchantAdjustments.ts";
const last = "YearEndTotals.ts";
await page.evaluate(async (path) => {
const backend = "/src/editor/core/backend.ts";
(await import(/* @vite-ignore */ backend)).docBackend().files.set(path, "export const pending = 1;\n");
const service = "/src/workbench/contributions.ts";
await (await import(/* @vite-ignore */ service)).editorService().openFile(path);
}, path);
await expect(page.locator(".cm-content")).toContainText("pending");
await stubDesktop(page);
await page.evaluate(
async ({ directory, filename, long, last }) => {
window.__ipc.handlers.fs_read_dir = ({ path }) =>
path === directory
? ["archive", long, ...Array.from({ length: 24 }, (_, i) => `Report-${i + 1}.ts`), filename, last].map(
(name) => ({
name,
path: `${directory}/${name}`,
kind: name === "archive" ? "dir" : "file",
size: name === "archive" ? 0 : 1,
}),
)
: [];
const actions = "/src/platform/actions.ts";
await (await import(/* @vite-ignore */ actions)).executeAction("navigate.navigationBar");
},
{ directory, filename, long, last },
);
const bar = page.getByRole("toolbar", { name: "Navigation bar" });
await expect(bar).toBeVisible();
await page.keyboard.press("ArrowLeft");
const segment = bar.getByRole("button", { name: folder, exact: true });
await expect(segment).toHaveAttribute("aria-current", "location");
const barBounds = (await bar.boundingBox())!;
await page.keyboard.press("ArrowDown");
const list = page.getByRole("listbox", { name: "Children" });
await expect(list).toBeVisible();
await expect(list.getByRole("option", { name: filename, exact: true })).toHaveAttribute("aria-selected", "true");
await expect
.poll(async () => {
const bounds = (await list.boundingBox())!;
return bounds.x >= 5 && bounds.x + bounds.width <= 595;
})
.toBe(true);
expect((await list.boundingBox())!.y).toBeGreaterThanOrEqual(barBounds.y + barBounds.height - 4);
expect((await bar.boundingBox())!.height).toBeCloseTo(barBounds.height);
await page.keyboard.press("Home");
const folderRow = list.getByRole("option", { name: "archive" });
await expect(folderRow).toHaveAttribute("aria-selected", "true");
await expect(folderRow).toBeInViewport({ ratio: 1 });
await expect(folderRow).toHaveCSS("height", "18px");
await expect(folderRow).toHaveCSS("font-size", "13px");
await expect(list.getByRole("option", { name: long, exact: true }).getByTitle(long)).toBeVisible();
expect(await list.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
await page.setViewportSize({ width: 1120, height: 820 });
await expect
.poll(() =>
list.evaluate((el) => {
const bounds = el.getBoundingClientRect();
return [...el.querySelectorAll('[role="option"]')].filter((row) => {
const box = row.getBoundingClientRect();
return box.top >= bounds.top && box.bottom <= bounds.bottom;
}).length;
}),
)
.toBe(20);
await page.setViewportSize({ width: 600, height: 560 });
await page.keyboard.press("End");
const lastRow = list.getByRole("option", { name: last, exact: true });
await expect(lastRow).toHaveAttribute("aria-selected", "true");
await expect(lastRow).toBeInViewport({ ratio: 1 });
await page.keyboard.press("Escape");
await expect(list).toBeHidden();
await expect(bar).toBeFocused();
await page.keyboard.press("Escape");
await expect(bar).toBeHidden();
});
test("the floating navigation list speed-searches children and clears a miss before closing", async ({
workbench: page,
}) => {
const directory = "/dev/acme-api/src";
const initialPath = `${directory}/Overview.ts`;
const filename = "SettlementSummary.ts";
const path = `${directory}/${filename}`;
await page.evaluate(
async ({ initialPath, path }) => {
const backend = "/src/editor/core/backend.ts";
(await import(/* @vite-ignore */ backend)).docBackend().files.set(initialPath, "export const overview = 1;\n");
(await import(/* @vite-ignore */ backend)).docBackend().files.set(path, "export const settlement = 1;\n");
const service = "/src/workbench/contributions.ts";
await (await import(/* @vite-ignore */ service)).editorService().openFile(initialPath);
},
{ initialPath, path },
);
await expect(page.locator(".cm-content")).toContainText("overview");
await stubDesktop(page);
await page.evaluate(
async ({ directory }) => {
window.__ipc.handlers.fs_read_dir = ({ path }) =>
path === directory
? ["archive", "Overview.ts", "YearEndTotals.ts", "SettlementSummary.ts"].map((name) => ({
name,
path: `${directory}/${name}`,
kind: name === "archive" ? "dir" : "file",
size: name === "archive" ? 0 : 1,
}))
: [];
const actions = "/src/platform/actions.ts";
await (await import(/* @vite-ignore */ actions)).executeAction("navigate.navigationBar");
},
{ directory },
);
const bar = page.getByRole("toolbar", { name: "Navigation bar" });
await page.keyboard.press("ArrowLeft");
await expect(bar.getByRole("button", { name: "src", exact: true })).toHaveAttribute("aria-current", "location");
await page.keyboard.press("ArrowDown");
const list = page.getByRole("listbox", { name: "Children" });
await expect(list.getByRole("option", { name: filename, exact: true })).toBeVisible();
await page.keyboard.type("zzz");
await expect(list.getByText("Nothing here")).toBeVisible();
const query = page.getByRole("status").filter({ hasText: "zzz" });
await expect(query).toBeVisible();
await expect(list.getByRole("option")).toHaveCount(0);
await expect(list).toBeFocused();
expect(await list.getAttribute("aria-activedescendant")).toBeNull();
await page.keyboard.press("Escape");
await expect(list.getByRole("option")).toHaveCount(4);
await expect(query).toHaveCount(0);
await expect(list).toBeFocused();
await page.keyboard.type("suz");
await expect(list.getByText("Nothing here")).toBeVisible();
await page.keyboard.press("Backspace");
const target = list.getByRole("option", { name: filename, exact: true });
await expect(target).toHaveAttribute("aria-selected", "true");
expect(await list.getAttribute("aria-activedescendant")).toBe(await target.getAttribute("id"));
await expect(target.locator("mark")).toHaveText("Su");
await page.keyboard.press("Enter");
await expect(page.locator(".cm-content")).toContainText("settlement");
await expect(list).toBeHidden();
await expect(bar).toBeHidden();
await page.evaluate(async () => {
const actions = "/src/platform/actions.ts";
await (await import(/* @vite-ignore */ actions)).executeAction("navigate.navigationBar");
});
await bar.getByRole("button", { name: "src", exact: true }).dblclick();
await expect(bar).toBeHidden();
const tree = page.getByRole("tree", { name: "Project" });
await expect(tree.getByRole("treeitem", { name: "src", exact: true })).toHaveAttribute("aria-selected", "true");
await expect(tree).toBeFocused();
});
test("the status-bar navigation list resets speed search across folders and activates a filtered child", async ({
workbench: page,
}) => {
const directory = "/dev/acme-api/src";
const archive = `${directory}/archive`;
const initialPath = `${directory}/Overview.ts`;
const filename = "SettlementSummary.ts";
const path = `${directory}/${filename}`;
await page.evaluate(
async ({ initialPath, path }) => {
const backend = "/src/editor/core/backend.ts";
(await import(/* @vite-ignore */ backend)).docBackend().files.set(initialPath, "export const overview = 1;\n");
(await import(/* @vite-ignore */ backend)).docBackend().files.set(path, "export const settlement = 1;\n");
const service = "/src/workbench/contributions.ts";
await (await import(/* @vite-ignore */ service)).editorService().openFile(initialPath);
},
{ initialPath, path },
);
await expect(page.locator(".cm-content")).toContainText("overview");
await stubDesktop(page);
await page.evaluate(
async ({ directory, archive, filename }) => {
window.__ipc.handlers.fs_read_dir = ({ path }) =>
path === directory
? ["archive", "Overview.ts", "YearEndTotals.ts", filename].map((name) => ({
name,
path: `${directory}/${name}`,
kind: name === "archive" ? "dir" : "file",
size: name === "archive" ? 0 : 1,
}))
: path === archive
? [{ name: "Previous.ts", path: `${archive}/Previous.ts`, kind: "file", size: 1 }]
: [];
const source = await (await fetch("/src/workbench/Workbench.tsx")).text();
const project = source.match(/["'](\/src\/platform\/project\.ts(?:\?[^"']+)?)["']/)?.[1];
if (!project) throw new Error("Missing project store");
const { useProject } = await import(/* @vite-ignore */ project);
const settings = useProject.getState().settings;
useProject.setState({
settings: { ...settings, appearance: { ...settings?.appearance, navigationBar: "statusBar" } },
});
},
{ directory, archive, filename },
);
const anchor = page
.getByRole("navigation", { name: "Breadcrumbs" })
.getByRole("button", { name: "src", exact: true });
await anchor.click();
const list = page.getByRole("listbox", { name: "src", exact: true });
await page.keyboard.type("zzz");
await expect(list.getByText("Nothing here")).toBeVisible();
await expect(list).toBeFocused();
await page.keyboard.press("Escape");
await expect(list.getByRole("option")).toHaveCount(4);
await page.keyboard.type("arc");
await expect(list.getByRole("option", { name: "archive" })).toHaveAttribute("aria-selected", "true");
await page.keyboard.press("ArrowRight");
const nested = page.getByRole("listbox", { name: "archive", exact: true });
await expect(nested.getByRole("option", { name: "Previous.ts" })).toHaveAttribute("aria-selected", "true");
await page.keyboard.press("ArrowLeft");
await expect(list.getByRole("option")).toHaveCount(4);
await page.keyboard.type("sett");
const target = list.getByRole("option", { name: filename, exact: true });
await expect(target).toHaveAttribute("aria-selected", "true");
expect(await list.getAttribute("aria-activedescendant")).toBe(await target.getAttribute("id"));
await page.keyboard.press("Enter");
await expect(page.locator(".cm-content")).toContainText("settlement");
await expect(list).toBeHidden();
});
for (const position of ["top", "statusBar"] as const) {
test(`the ${position} navigation list opens toward the editor and keeps folder navigation`, async ({
workbench: page,
}) => {
const directory = "/dev/acme-api/src";
const path = `${directory}/Overview.ts`;
await page.evaluate(async (path) => {
const backend = "/src/editor/core/backend.ts";
(await import(/* @vite-ignore */ backend)).docBackend().files.set(path, "export const overview = 1;\n");
const service = "/src/workbench/contributions.ts";
await (await import(/* @vite-ignore */ service)).editorService().openFile(path);
}, path);
await expect(page.locator(".cm-content")).toContainText("overview");
await stubDesktop(page);
await page.evaluate(
async ({ directory, position }) => {
const archive = `${directory}/archive`;
window.__ipc.handlers.fs_read_dir = ({ path }) =>
path === directory
? [
{ path: archive, name: "archive", kind: "dir", size: 0 },
{ path: `${directory}/Overview.ts`, name: "Overview.ts", kind: "file", size: 1 },
]
: path === archive
? [{ path: `${archive}/Previous.ts`, name: "Previous.ts", kind: "file", size: 1 }]
: [];
const source = await (await fetch("/src/workbench/Workbench.tsx")).text();
const project = source.match(/["'](\/src\/platform\/project\.ts(?:\?[^"']+)?)["']/)?.[1];
if (!project) throw new Error("Missing project store");
const { useProject } = await import(/* @vite-ignore */ project);
const settings = useProject.getState().settings;
useProject.setState({
settings: { ...settings, appearance: { ...settings?.appearance, navigationBar: position } },
});
},
{ directory, position },
);
const anchor = page
.getByRole("navigation", { name: "Breadcrumbs" })
.getByRole("button", { name: "src", exact: true });
await anchor.click();
const list = page.getByRole("listbox", { name: "src", exact: true });
const archive = list.getByRole("option", { name: "archive" });
await expect(archive).toHaveAttribute("aria-selected", "true");
await expect(list).toBeFocused();
expect((await list.boundingBox())!.width).toBeLessThan(140);
await expect(archive).toHaveCSS("height", "18px");
await expect
.poll(async () => {
const bounds = (await anchor.boundingBox())!;
const popup = (await list.boundingBox())!;
return position === "top" ? popup.y >= bounds.y + bounds.height : popup.y + popup.height <= bounds.y;
})
.toBe(true);
await page.keyboard.press("ArrowRight");
const nested = page.getByRole("listbox", { name: "archive" });
await expect(nested.getByRole("option", { name: "Previous.ts" })).toHaveAttribute("aria-selected", "true");
await page.keyboard.press("ArrowLeft");
await expect(archive).toHaveAttribute("aria-selected", "true");
await page.keyboard.press("Escape");
await expect(list).toBeHidden();
await expect(anchor).toBeFocused();
await anchor.click();
await archive.click();
await expect(nested.getByRole("option", { name: "Previous.ts" })).toBeVisible();
await page.keyboard.press("ArrowLeft");
await archive.dblclick();
await expect(list).toBeHidden();
await expect(nested).toBeHidden();
const tree = page.getByRole("tree", { name: "Project" });
const revealed = tree.getByRole("treeitem", { name: "archive", exact: true });
await expect(revealed).toHaveAttribute("aria-selected", "true");
await expect(revealed).toBeInViewport();
await expect(tree).toBeFocused();
await anchor.dblclick();
await expect(list).toBeHidden();
const folder = tree.getByRole("treeitem", { name: "src", exact: true });
await expect(folder).toHaveAttribute("aria-selected", "true");
await expect(folder).toBeInViewport();
await expect(tree).toBeFocused();
});
}