Файли
openidea/e2e/bookmarkTreeLayout.spec.ts
T
solhovoy 4016c410db feat(bookmarks): add toolbar actions and embedded editor preview (#7102)
The Bookmarks tool window gets Rename, Select in Project View, Expand All, Collapse All and an Editor Preview toggle in its header. The preview shows the selected bookmark's or file's code with the bookmark gutter, below the tree when the window is docked at a side and beside it when docked at the bottom; the toggle is remembered. Remove All Bookmarks now asks first, and the bookmark and list rename dialogs get a labelled form with Create/Rename buttons.

Co-authored-by: solhovoy <[email protected]>

Co-authored-by: solhovoy <[email protected]>
2026-12-01 05:44:33 +08:00

91 рядки
4.5 KiB
TypeScript

import { expect, test } from "./fixtures";
test("line bookmarks keep their code or description readable in the dock", async ({ workbench: page }) => {
await page.setViewportSize({ width: 880, height: 640 });
const name = "QuarterlySettlementReconciliationCoordinator.ts";
const path = `/dev/acme-api/${name}`;
const code = "reconcileCheckoutOrders();";
const description = "Review settlement totals";
await page.evaluate(
async ({ path, code }) => {
const backendModule = "/src/editor/core/backend.ts";
const { docBackend } = await import(/* @vite-ignore */ backendModule);
docBackend().files.set(path, [...Array(27).fill("// Settlement rules"), code, "verifyTotals();", ""].join("\n"));
const services = "/src/workbench/contributions.ts";
const { editorService } = await import(/* @vite-ignore */ services);
await editorService().openFile(path);
},
{ path, code },
);
await expect(page.locator(".cm-content")).toContainText(code);
await page.evaluate(
async ({ path, description }) => {
const actionsModule = "/src/platform/actions.ts";
const { executeAction } = await import(/* @vite-ignore */ actionsModule);
await executeAction("navigate.toggleBookmark", { path, line: 27 });
await executeAction("navigate.toggleBookmark", { path, line: 29 });
const bookmarkModule = "/src/features/search/bookmarks/store.ts";
const { assignMnemonic, updateBookmarks } = await import(/* @vite-ignore */ bookmarkModule);
updateBookmarks((items: unknown[]) => assignMnemonic(items, path, 28, "verifyTotals();", "4", description));
await executeAction("toolwindow.bookmarks");
const layoutModule = "/src/workbench/toolwindows/store.ts";
const { setToolWindowSize } = await import(/* @vite-ignore */ layoutModule);
setToolWindowSize("left", 240);
},
{ path, description },
);
const tree = page.getByRole("tree", { name: "Bookmarks" });
await expect(tree.getByText(name, { exact: true })).toBeVisible();
const snippet = tree.getByText(code, { exact: true });
await expect.poll(() => snippet.evaluate((el) => el.clientWidth)).toBeGreaterThanOrEqual(105);
await expect(tree.getByText("28:", { exact: true })).toBeVisible();
await expect(tree.getByText("29:", { exact: true })).toBeVisible();
await expect(tree.getByText(description, { exact: true })).toBeVisible();
await expect(tree.getByText("(empty line)", { exact: true })).toBeVisible();
expect(await tree.evaluate((el) => el.scrollWidth - el.clientWidth)).toBe(0);
const row = tree.getByRole("treeitem").filter({ hasText: code });
await row.click();
await page.keyboard.press("Enter");
await expect
.poll(() =>
page.evaluate(async () => {
const module = "/src/workbench/contributions.ts";
const { editorService } = await import(/* @vite-ignore */ module);
const cursor = editorService().activeCursor();
return { path: cursor?.path, line: cursor?.line };
}),
)
.toEqual({ path, line: 27 });
});
test("selecting a bookmark shows its code in the preview below the side-docked Bookmarks tree", async ({
workbench: page,
}) => {
const path = "/dev/acme-api/PreviewBookmark.ts";
await page.evaluate(async (path) => {
const backend = "/src/editor/core/backend.ts";
const { docBackend } = await import(/* @vite-ignore */ backend);
docBackend().files.set(path, "const previewBookmark = true;");
const store = "/src/features/search/bookmarks/store.ts";
const { updateBookmarks, toggleBookmark } = await import(/* @vite-ignore */ store);
updateBookmarks((items: unknown[]) => toggleBookmark(items, path, 0, "const previewBookmark = true;"));
const actions = "/src/platform/actions.ts";
await (await import(/* @vite-ignore */ actions)).executeAction("toolwindow.bookmarks");
}, path);
const previewButton = page.getByRole("button", { name: "Editor Preview" });
if ((await previewButton.getAttribute("aria-pressed")) !== "true") await previewButton.click();
const tree = page.getByRole("tree", { name: "Bookmarks" });
await tree.getByRole("treeitem", { name: /const previewBookmark/ }).click();
const preview = page.locator("#bookmarks-preview");
await expect(preview).toBeVisible();
const treeBounds = await tree.boundingBox();
const previewBounds = await preview.boundingBox();
expect(treeBounds).not.toBeNull();
expect(previewBounds).not.toBeNull();
expect(previewBounds!.y).toBeGreaterThanOrEqual(treeBounds!.y + treeBounds!.height);
await expect(preview.locator(".cm-content")).toContainText("const previewBookmark = true;");
});