Файли
openidea/e2e/fileStructureLayout.spec.ts
T
Muuтаmuutot f47a83828c feat(structure): temporarily enable filters to find matches (#6934)
With Narrow down on typing on, a File Structure query that matches nothing now turns on the unchecked filters (Show fields, Show non-public, Show inherited members) one at a time until a match appears. Filters enabled this way are restored as the query gets shorter and when the popup closes, and are never saved; a checkbox the user changes by hand keeps its new state, and the cascade stops right after a backspace restores a filter.

Co-authored-by: muutot <[email protected]>
2026-11-30 19:58:05 +08:00

328 рядки
14 KiB
TypeScript

import { expect, openFromTree, stubDesktop, test } from "./fixtures";
test("the docked Structure tree starts under the header and keeps its commands available", async ({
workbench: page,
}) => {
await openFromTree(page, "build.gradle.kts");
await stubDesktop(page);
await page.evaluate(async () => {
const range = { start: { line: 0, col: 0 }, end: { line: 1, col: 1 } };
const field = {
name: "orderCount",
kind: "field",
visibility: "private",
range,
selection_range: range,
children: [],
};
window.__ipc.handlers.doc_outline = () => [
{ name: "OrderController", kind: "class", range, selection_range: range, children: [field] },
];
window.__ipc.handlers.lsp_type_hierarchy = () => [];
const path = "/src/workbench/toolwindows/store.ts";
const { moveToolWindow, setToolWindowSize, showToolWindow } = await import(/* @vite-ignore */ path);
moveToolWindow("structure", "right");
setToolWindowSize("right", 240);
showToolWindow("structure", true);
});
const panel = page.getByRole("region", { name: "Structure", exact: true });
const header = panel.locator("header").first();
const tree = panel.getByRole("tree", { name: "Structure" });
const field = tree.getByRole("treeitem", { name: "orderCount" });
await expect(field).toBeVisible();
await expect
.poll(async () => {
const h = (await header.boundingBox())!;
const t = (await tree.boundingBox())!;
return t.y - h.y - h.height;
})
.toBeLessThan(2);
const viewOptions = header.getByRole("button", { name: "View Options", exact: true });
await viewOptions.click();
const viewMenu = page.getByRole("menu", { name: "View Options", exact: true });
await expect(viewMenu.getByRole("menuitemcheckbox", { name: "Sort Alphabetically" })).toBeVisible();
await expect(viewMenu.getByRole("menuitemcheckbox", { name: "Show Inherited" })).toBeVisible();
await viewMenu.getByRole("menuitemcheckbox", { name: "Show Fields", checked: true }).click();
await expect(field).toBeHidden();
await viewOptions.click();
await viewMenu.getByRole("menuitemcheckbox", { name: "Show Fields", checked: false }).click();
await expect(field).toBeVisible();
const more = header.getByRole("button", { name: "Options", exact: true });
const menu = page.getByRole("menu", { name: "Structure options" });
await more.click();
await menu.getByRole("menuitem", { name: "Collapse All", exact: true }).click();
await expect(field).toBeHidden();
await more.click();
await menu.getByRole("menuitem", { name: "Expand All", exact: true }).click();
await expect(field).toBeVisible();
await more.click();
await menu.getByRole("menuitemcheckbox", { name: "Autoscroll from Source", checked: false }).click();
await more.click();
await expect(menu.getByRole("menuitemcheckbox", { name: "Autoscroll from Source", checked: true })).toBeVisible();
});
test("File Structure keeps symbol filters readable at desktop and minimum window widths", async ({
workbench: page,
}) => {
await openFromTree(page, "build.gradle.kts");
await stubDesktop(page);
await page.evaluate(async () => {
const range = { start: { line: 0, col: 0 }, end: { line: 1, col: 1 } };
const field = {
name: "orderCount",
kind: "field",
visibility: "private",
range,
selection_range: range,
children: [],
};
const methods = Array.from({ length: 36 }, (_, i) => ({
name: `method${String(i).padStart(2, "0")}`,
kind: "method",
range,
selection_range: range,
children: [],
})).reverse();
window.__ipc.handlers.doc_outline = () => [
{ name: "OrderController", kind: "class", range, selection_range: range, children: [field, ...methods] },
];
window.__ipc.handlers.lsp_type_hierarchy = () => [];
const path = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ path);
await executeAction("navigate.fileStructure");
});
const dialog = page.getByRole("dialog", { name: "File Structure" });
const filter = dialog.getByRole("textbox", { name: "Filter symbols" });
const options = dialog.getByRole("button", { name: "View Options" });
const tree = dialog.getByRole("tree", { name: "Symbols" });
const fields = dialog.getByRole("checkbox", { name: "Show fields" });
await expect(dialog.getByRole("checkbox", { name: "Show inherited members" })).toBeVisible();
await expect(filter).toBeFocused();
await expect(options).toBeVisible();
for (const width of [400, 1000]) {
await page.setViewportSize({ width, height: 420 });
const clipped = await dialog.evaluate((element) => {
const labels = [...element.querySelectorAll("label")].filter((label) =>
label.querySelector('input[type="checkbox"]'),
);
const row = labels[0]!.parentElement!.getBoundingClientRect();
return labels.flatMap((label) => {
const range = document.createRange();
range.selectNodeContents(label);
const box = range.getBoundingClientRect();
return box.top < row.top - 1 || box.right > row.right + 1 || box.bottom > row.bottom + 1
? [label.textContent]
: [];
});
});
expect(clipped).toEqual([]);
await expect(options).toBeInViewport({ ratio: 1 });
const filterTop = (await filter.boundingBox())!.y;
expect((await options.boundingBox())!.y).toBeLessThan(filterTop);
expect((await tree.boundingBox())!.y).toBeGreaterThan(filterTop);
}
// The dialog scales in when it opens: wait for its settled width.
await expect.poll(async () => Math.round((await dialog.boundingBox())!.width)).toBe(540);
const field = dialog.getByRole("treeitem", { name: "orderCount" });
await expect(field).toBeVisible();
await fields.uncheck();
await expect(field).toBeHidden();
await tree.evaluate((el) => (el.scrollTop = el.scrollHeight));
await expect(tree.getByRole("treeitem", { name: "method00", exact: true })).toBeInViewport();
await expect(options).toBeInViewport({ ratio: 1 });
await expect(filter).toBeInViewport({ ratio: 1 });
await options.click();
const menu = page.getByRole("menu", { name: "View Options" });
await expect(menu).toBeInViewport({ ratio: 1 });
const alphabetically = menu.getByRole("menuitemcheckbox", { name: "Sort Alphabetically" });
await expect(alphabetically).not.toBeChecked();
await alphabetically.click();
await expect(menu).toBeHidden();
await tree.evaluate((el) => (el.scrollTop = 0));
await expect(tree.getByRole("treeitem").nth(1)).toHaveAccessibleName("method00");
await filter.fill("method21");
await expect(tree.getByRole("treeitem", { name: "method21", selected: true })).toBeVisible();
await options.click();
await menu.getByRole("menuitemcheckbox", { name: "Narrow down on typing", checked: true }).click();
await expect(tree.getByRole("treeitem", { name: "method22", exact: true })).toBeVisible();
await options.click();
await page.keyboard.press("Escape");
await expect(menu).toBeHidden();
await expect(dialog).toBeVisible();
await expect(options).toBeFocused();
await filter.press("Escape");
await expect(filter).toHaveValue("");
});
test("File Structure prefers matches inside the caret symbol", async ({ workbench: page }) => {
await openFromTree(page, "build.gradle.kts");
await stubDesktop(page);
await page.evaluate(async () => {
const range = (start: number, end: number) => ({
start: { line: start, col: 0 },
end: { line: end, col: 1 },
});
const symbol = (name: string, kind: string, start: number, end: number, children: unknown[] = []) => ({
name,
kind,
range: range(start, end),
selection_range: range(start, end),
children,
});
window.__ipc.handlers.doc_outline = () => [
symbol("Container", "class", 0, 11, [
symbol("current", "method", 2, 7, [symbol("loadChild", "method", 3, 4), symbol("loadSibling", "method", 6, 7)]),
]),
symbol("load", "function", 10, 11),
];
window.__ipc.handlers.lsp_type_hierarchy = () => [];
const contributionsPath = "/src/workbench/contributions.ts";
const trackingPath = "/src/features/search/common/tracking.ts";
const actionsPath = "/src/platform/actions.ts";
const { maybeEditorService } = await import(/* @vite-ignore */ contributionsPath);
const path = maybeEditorService()?.activePath();
if (!path) throw new Error("No active editor path");
const { useTracking } = await import(/* @vite-ignore */ trackingPath);
useTracking.setState({ caret: { path, doc: 1, line: 2, col: 5, offset: 20 } });
const { executeAction } = await import(/* @vite-ignore */ actionsPath);
await executeAction("navigate.fileStructure");
});
const dialog = page.getByRole("dialog", { name: "File Structure" });
const tree = dialog.getByRole("tree", { name: "Symbols" });
await expect(tree.getByRole("treeitem", { name: "current", exact: true })).toBeVisible();
await dialog.getByRole("textbox", { name: "Filter symbols" }).fill("load");
await expect(tree.getByRole("treeitem", { name: "loadChild", selected: true })).toBeVisible();
await expect(tree.getByRole("treeitem", { name: "load", exact: true })).toHaveAttribute("aria-selected", "false");
});
test("File Structure auto-enables temporary filters without saving them", async ({ workbench: page }) => {
await openFromTree(page, "build.gradle.kts");
await stubDesktop(page);
await page.evaluate(async () => {
const optionsPath = "/src/features/search/structure/store.ts";
const { useStructureOptions } = await import(/* @vite-ignore */ optionsPath);
useStructureOptions.setState({ showFields: false, showNonPublic: false, showInherited: false, narrowDown: true });
const range = { start: { line: 0, col: 0 }, end: { line: 1, col: 1 } };
const symbol = (name: string, kind: string, visibility?: string) => ({
name,
kind,
visibility,
range,
selection_range: range,
children: [],
});
window.__ipc.handlers.doc_outline = () => [
{
...symbol("Container", "class"),
children: [
symbol("hiddenField", "field"),
symbol("hiddenMethod", "method", "private"),
symbol("visible", "method"),
],
},
];
window.__ipc.handlers.lsp_type_hierarchy = () => [];
const actionsPath = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsPath);
await executeAction("navigate.fileStructure");
});
const dialog = page.getByRole("dialog", { name: "File Structure" });
const filter = dialog.getByRole("textbox", { name: "Filter symbols" });
const tree = dialog.getByRole("tree", { name: "Symbols" });
const fields = dialog.getByRole("checkbox", { name: "Show fields" });
const nonPublic = dialog.getByRole("checkbox", { name: "Show non-public" });
const readOptions = () =>
page.evaluate(async () => {
const path = "/src/features/search/structure/store.ts";
const { useStructureOptions } = await import(/* @vite-ignore */ path);
const { showFields, showNonPublic, showInherited } = useStructureOptions.getState();
return { showFields, showNonPublic, showInherited };
});
await expect(fields).not.toBeChecked();
await expect(nonPublic).not.toBeChecked();
await filter.fill("hiddenField");
await expect(fields).toBeChecked();
await expect(nonPublic).not.toBeChecked();
await expect(tree.getByRole("treeitem", { name: "hiddenField", selected: true })).toBeVisible();
expect(await readOptions()).toEqual({ showFields: false, showNonPublic: false, showInherited: false });
await nonPublic.check();
expect(await readOptions()).toEqual({ showFields: false, showNonPublic: true, showInherited: false });
const saved = await page.evaluate(() => localStorage.getItem("openidea.structure.options.v1"));
await filter.press("End");
await filter.press("Backspace");
await expect(filter).toHaveValue("hiddenFiel");
await expect(fields).not.toBeChecked();
await expect(nonPublic).toBeChecked();
await expect(tree.getByRole("treeitem", { name: "hiddenField", exact: true })).toBeHidden();
expect(await readOptions()).toEqual({ showFields: false, showNonPublic: true, showInherited: false });
await filter.fill("hiddenField");
await expect(fields).toBeChecked();
await fields.uncheck();
await expect(fields).not.toBeChecked();
await filter.press("Escape");
await expect(filter).toHaveValue("");
await expect(fields).not.toBeChecked();
await filter.press("Escape");
await expect(dialog).toBeHidden();
expect(await readOptions()).toEqual({ showFields: false, showNonPublic: true, showInherited: false });
expect(await page.evaluate(() => localStorage.getItem("openidea.structure.options.v1"))).toBe(saved);
await page.evaluate(async () => {
const path = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ path);
await executeAction("navigate.fileStructure");
});
await expect(dialog).toBeVisible();
await expect(dialog.getByRole("checkbox", { name: "Show fields" })).not.toBeChecked();
await expect(dialog.getByRole("checkbox", { name: "Show non-public" })).toBeChecked();
expect(await page.evaluate(() => localStorage.getItem("openidea.structure.options.v1"))).toBe(saved);
});
test("F4 jumps to the filtered File Structure symbol", async ({ workbench: page }) => {
await openFromTree(page, "build.gradle.kts");
await stubDesktop(page);
await page.evaluate(async () => {
const range = { start: { line: 6, col: 4 }, end: { line: 6, col: 13 } };
window.__ipc.handlers.doc_outline = () => [
{
name: "separate",
kind: "method",
range,
selection_range: range,
children: [],
},
];
window.__ipc.handlers.lsp_type_hierarchy = () => [];
const path = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ path);
await executeAction("navigate.fileStructure");
});
const dialog = page.getByRole("dialog", { name: "File Structure" });
const filter = dialog.getByRole("textbox", { name: "Filter symbols" });
await filter.fill("separate");
await expect(dialog.getByRole("treeitem", { name: "separate", selected: true })).toBeVisible();
await filter.press("F4");
await expect(dialog).toBeHidden();
await expect
.poll(async () =>
page.evaluate(async () => {
const path = "/src/features/search/common/tracking.ts";
const { useTracking } = await import(/* @vite-ignore */ path);
return useTracking.getState().caret;
}),
)
.toMatchObject({ line: 6, col: 4 });
});