дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
* fix(code-insight): stabilize Show Usages popup sizing and placement The popup used a fixed 680px width and 14-row limit. Restoring a saved size also prevented it from adapting to incoming results. Follow the IntelliJ popup sizing and placement flow while limiting the filename column to 25% of the popup width to leave space for code. Sizing and columns: - Restore both saved dimensions while waiting for results. Once results arrive, cap the natural width at the saved width and calculate the height from content. Only preview mode also uses the saved height. - Measure filenames, line numbers and code with the actual fonts, with a 500px natural width limit per column. Fit short filenames to their content and ellipsize long names at 25% of the row width. Reserve 5ch for line numbers and at least 8em for code, which fills the remaining space. - Include the filename cap, code minimum width, header, controls, borders and gaps in the natural popup width. Do not widen the popup for text that the filename column will clip. - Cache maximum natural widths during streaming and filtering. After a manual resize, keep updating filename measurements but stop resizing the popup automatically until it is reopened or preview is toggled. - Show up to 30 rows normally or 20 with preview. Leave half a row when the list scrolls, and let the list fill the available height. - Preserve the 360x160 minimum size and existing storage keys. Fit the viewport when it is smaller, and save the actual size on close. Placement and preview: - Open below the caret. When it is outside the visible editor, use a point one third across and halfway down the visible editing area. - Add optional fitToScreen placement to Popup. Keep the fitted position when content shrinks, and move only when necessary to stay visible. Reset placement when the anchor changes or preview rebuilds the popup. - Reuse the shared split panels with a default 60/40 list/preview split, persisted proportions, mouse dragging and keyboard adjustment. Set the preview minimum to five actual editor lines and update it after font or editor geometry changes. - Preserve the preview's pixel height while manually resizing the outer popup. Wait for the splitter's final measurement before restoring it. - Add onResizeStart on the first pointer movement. Clicking the resize handle alone does not lock preview height. Toggling preview clears saved dimensions, measurements, manual size and drag position, and cancels pending resize callbacks. - Add a translated accessible label to the preview divider and preserve its keyboard controls alongside usage-list navigation. Verification: - 17 Playwright layout and demo tests passed in local Google Chrome, covering both themes, the 25% cap, narrow windows, filtering, saved dimensions, position stability, preview, keyboard controls and resize. Both filename-cap regression cases failed before the fix and passed afterward. - Wait for fonts and entry animations before dragging the one-pixel divider or measuring dimensions. Account for popup growth when the search caption changes while checking the filename cap. - 49 Popup and Show Usages unit tests passed on the final version. - pnpm typecheck and pnpm build passed, including Safari 15.4 checks. Changed-file oxlint, oxfmt and git diff --check passed. - An earlier full test run had 20,483 passed, 65 skipped and two existing translation-check failures in color-preview/varColors.ts and vcs/rebase.tsx. Earlier full lint and knip checks passed. Full format checking failed on an existing untracked .workbuddy memory file. - Before/after screenshots for both themes and narrow windows, plus interaction recordings, are retained in temporary verification folders. Tests used browser fixtures; the native Tauri webview was not tested because no Tauri MCP bridge was available. * fix(code-insight): restore focus across preview toggle, avoid width ratchet, and clean up cancelled resizes --------- Co-authored-by: l0ng-ai <[email protected]>
753 рядки
36 KiB
TypeScript
753 рядки
36 KiB
TypeScript
import { expect, stubDesktop, test } from "./fixtures";
|
|
import type { Page } from "@playwright/test";
|
|
|
|
async function resizePopupWidth(page: Page, width: number) {
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((animation) => animation.finished)));
|
|
const box = (await popup.boundingBox())!;
|
|
const corner = (await popup.getByRole("separator", { name: "Resize", exact: true }).boundingBox())!;
|
|
const x = corner.x + corner.width / 2;
|
|
const y = corner.y + corner.height / 2;
|
|
await page.mouse.move(x, y);
|
|
await page.mouse.down();
|
|
await page.mouse.move(x + width - box.width, y, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeCloseTo(width, 0);
|
|
}
|
|
|
|
test.use({ video: "on" });
|
|
|
|
for (const theme of ["light", "dark"] as const) {
|
|
test(`Show Usages keeps its fitted position when results shrink in ${theme} theme`, async ({ workbench: page }) => {
|
|
await page.evaluate(async (theme) => {
|
|
const themeModule = "/src/workbench/theme.ts";
|
|
await (await import(/* @vite-ignore */ themeModule)).setTheme(theme);
|
|
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 900, h: 700 }));
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const preview = "/src/features/code-insight/UsagesPopup.tsx";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
(await import(/* @vite-ignore */ preview)).setUsagesPopupPreview(false);
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 1200, y: 700 },
|
|
symbol: "run",
|
|
loading: true,
|
|
groups: [],
|
|
note: null,
|
|
scope: null,
|
|
});
|
|
}, theme);
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await expect.poll(async () => (await popup.boundingBox())?.height).toBeCloseTo(700, 0);
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((a) => a.finished)));
|
|
const before = (await popup.boundingBox())!;
|
|
await page.screenshot({ path: test.info().outputPath("1-loading.png"), animations: "disabled" });
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/A.ts";
|
|
useUsagesPopup.setState({
|
|
loading: false,
|
|
groups: [{ path, usages: [0, 1].map((line) => ({ path, line, col: 0, endCol: 3, text: "run();" })) }],
|
|
});
|
|
});
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(160, 0);
|
|
await page.screenshot({ path: test.info().outputPath("2-results.png"), animations: "disabled" });
|
|
await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(before.x, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(before.y, 0);
|
|
});
|
|
|
|
test(`Show Usages caps filename width at a quarter of the popup in ${theme} theme`, async ({ workbench: page }) => {
|
|
await page.evaluate(async (theme) => {
|
|
const themeModule = "/src/workbench/theme.ts";
|
|
await (await import(/* @vite-ignore */ themeModule)).setTheme(theme);
|
|
localStorage.removeItem("openidea.usages.popupSize.v1");
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const preview = "/src/features/code-insight/UsagesPopup.tsx";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
(await import(/* @vite-ignore */ preview)).setUsagesPopupPreview(false);
|
|
const path = "/dev/app/TransportPlanConfigurationServiceForOrderApprovalQueries.ts";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 40, y: 60 },
|
|
symbol: "run",
|
|
loading: false,
|
|
note: null,
|
|
scope: null,
|
|
groups: [{ path, usages: [0, 1].map((line) => ({ path, line, col: 0, endCol: 3, text: "run();" })) }],
|
|
});
|
|
}, theme);
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
const file = popup.getByTestId("usage-row").first().locator(":scope > span:first-child");
|
|
const label = popup.getByTestId("usage-row").first().locator(":scope > span:first-child > span");
|
|
await expect(label).toBeVisible();
|
|
await popup.evaluate(async (el) => {
|
|
await document.fonts.ready;
|
|
await Promise.all(el.getAnimations().map((a) => a.finished));
|
|
});
|
|
await page.screenshot({ path: test.info().outputPath("natural-filename.png"), animations: "disabled" });
|
|
await expect
|
|
.poll(async () => (await file.boundingBox())!.width / (await popup.boundingBox())!.width)
|
|
.toBeLessThanOrEqual(0.25);
|
|
expect(await label.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeGreaterThan(0);
|
|
await page.setViewportSize({ width: 480, height: 620 });
|
|
const code = popup.getByTestId("usage-row").first().locator(":scope > span:last-child");
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeLessThanOrEqual(468);
|
|
await expect
|
|
.poll(async () => (await file.boundingBox())!.width / (await popup.boundingBox())!.width)
|
|
.toBeLessThanOrEqual(0.25);
|
|
expect((await code.boundingBox())!.width).toBeGreaterThanOrEqual(100);
|
|
await page.screenshot({ path: test.info().outputPath("narrow-filename.png"), animations: "disabled" });
|
|
});
|
|
}
|
|
|
|
test("Show Usages splits preview at 40%, preserves its pixel height on window resize and remembers divider changes", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1400, height: 1100 });
|
|
await stubDesktop(page);
|
|
await page.evaluate(() => {
|
|
window.__ipc.handlers.fs_read_text = () => Array.from({ length: 80 }, (_, line) => `run(${line});`).join("\n");
|
|
});
|
|
const show = () =>
|
|
page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const preview = "/src/features/code-insight/UsagesPopup.tsx";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const { setUsagesPopupPreview } = await import(/* @vite-ignore */ preview);
|
|
setUsagesPopupPreview(true);
|
|
const path = "/dev/app/A.ts";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 40, y: 60 },
|
|
symbol: "run",
|
|
loading: false,
|
|
note: null,
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: Array.from({ length: 40 }, (_, line) => ({ path, line, col: 0, endCol: 3, text: "run();" })),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
await page.evaluate(() => localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 900, h: 750 })));
|
|
await show();
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
const preview = popup.getByRole("region", { name: "Preview", exact: true });
|
|
const divider = popup.getByRole("separator", { name: "Resize usages preview", exact: true });
|
|
const list = popup.getByRole("listbox", { name: "Usages" });
|
|
await expect(divider).toBeVisible();
|
|
await expect(preview.locator(".cm-content")).toBeVisible();
|
|
await expect(preview.locator(".cm-content")).toContainText("run(0)");
|
|
await page.evaluate(async () => {
|
|
await document.fonts.ready;
|
|
await new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
});
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((animation) => animation.finished)));
|
|
await expect
|
|
.poll(async () => {
|
|
const groupHeight = await preview.evaluate((el) => el.closest("[data-group]")!.getBoundingClientRect().height);
|
|
return (await preview.boundingBox())!.height / (groupHeight - 1);
|
|
})
|
|
.toBeCloseTo(0.4, 2);
|
|
const before = (await preview.boundingBox())!.height;
|
|
const listBefore = (await list.boundingBox())!.height;
|
|
const groupBefore = await preview.evaluate((el) => el.closest("[data-group]")!.getBoundingClientRect().height);
|
|
const corner = (await popup.getByRole("separator", { name: "Resize", exact: true }).boundingBox())!;
|
|
await page.mouse.move(corner.x + 4, corner.y + 4);
|
|
await page.mouse.down();
|
|
await page.mouse.move(corner.x + 84, corner.y + 104, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await preview.boundingBox())!.height).toBeCloseTo(before, 0);
|
|
const groupAfter = await preview.evaluate((el) => el.closest("[data-group]")!.getBoundingClientRect().height);
|
|
await expect
|
|
.poll(async () => (await list.boundingBox())!.height)
|
|
.toBeCloseTo(listBefore + groupAfter - groupBefore, 0);
|
|
const boundary = (await divider.boundingBox())!;
|
|
// A click on the outer resize handle must not keep anchoring later divider drags.
|
|
await popup.getByRole("separator", { name: "Resize", exact: true }).click();
|
|
await page.mouse.move(boundary.x + boundary.width / 2, boundary.y + 0.5);
|
|
await page.mouse.down();
|
|
await page.mouse.move(boundary.x + boundary.width / 2, boundary.y - 79.5, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await preview.boundingBox())!.height).toBeCloseTo(before + 80, 0);
|
|
const layout = await page.evaluate(() => JSON.parse(localStorage.getItem("openidea.usages.popupSplit.v1")!));
|
|
expect(layout.preview).toBeGreaterThan(40);
|
|
await divider.focus();
|
|
await page.keyboard.press("ArrowUp");
|
|
await expect.poll(async () => (await preview.boundingBox())!.height).toBeGreaterThan(before + 80);
|
|
const savedLayout = await page.evaluate(() => JSON.parse(localStorage.getItem("openidea.usages.popupSplit.v1")!));
|
|
await page.screenshot({ path: test.info().outputPath("usages-preview-divider.png"), animations: "disabled" });
|
|
await page.evaluate(async () => {
|
|
const path = "/src/workbench/theme.ts";
|
|
await (await import(/* @vite-ignore */ path)).setTheme("dark");
|
|
});
|
|
await page.screenshot({ path: test.info().outputPath("usages-preview-divider-dark.png"), animations: "disabled" });
|
|
await page.keyboard.press("Escape");
|
|
await expect(popup).toHaveCount(0);
|
|
await show();
|
|
await expect(divider).toBeVisible();
|
|
await expect
|
|
.poll(async () => {
|
|
const groupHeight = await preview.evaluate((el) => el.closest("[data-group]")!.getBoundingClientRect().height);
|
|
return ((await preview.boundingBox())!.height / (groupHeight - 1)) * 100;
|
|
})
|
|
.toBeCloseTo(savedLayout.preview, 0);
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((animation) => animation.finished)));
|
|
const reopened = (await divider.boundingBox())!;
|
|
await page.mouse.move(reopened.x + reopened.width / 2, reopened.y + 0.5);
|
|
await page.mouse.down();
|
|
await page.mouse.move(reopened.x + reopened.width / 2, 1090, { steps: 5 });
|
|
await page.mouse.up();
|
|
const minimum = await preview
|
|
.locator(".cm-content")
|
|
.evaluate((el) => parseFloat(getComputedStyle(el).lineHeight) * 5);
|
|
await expect.poll(async () => (await preview.boundingBox())!.height).toBeCloseTo(minimum, 0);
|
|
});
|
|
|
|
test("Show Usages restores the initial window, then smart-sizes results and resets dimensions on preview changes", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.evaluate(async () => {
|
|
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 900, h: 700 }));
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const preview = "/src/features/code-insight/UsagesPopup.tsx";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const { setUsagesPopupPreview } = await import(/* @vite-ignore */ preview);
|
|
setUsagesPopupPreview(true);
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 400, y: 100 },
|
|
symbol: "QueryWrapper",
|
|
groups: [],
|
|
loading: true,
|
|
note: null,
|
|
scope: null,
|
|
});
|
|
});
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await expect(popup.getByText("Searching for usages…", { exact: true })).toBeVisible();
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeCloseTo(900, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(700, 0);
|
|
await page.screenshot({ path: test.info().outputPath("usages-initial-restore.png"), animations: "disabled" });
|
|
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/A.ts";
|
|
useUsagesPopup.setState({
|
|
groups: [{ path, usages: [0, 1].map((line) => ({ path, line, col: 0, endCol: 3, text: "run();" })) }],
|
|
});
|
|
});
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeLessThan(900);
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(700, 0);
|
|
const shortWidth = (await popup.boundingBox())!.width;
|
|
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/TransportPlanConfigurationServiceForOrderApprovalQueries.ts";
|
|
useUsagesPopup.setState({
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: [0, 1].map((line) => ({
|
|
path,
|
|
line,
|
|
col: 0,
|
|
endCol: 3,
|
|
text: "run(configuration, currentUser, transportPlan, approvalStatus);".repeat(4),
|
|
})),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeGreaterThan(shortWidth);
|
|
expect((await popup.boundingBox())!.width).toBeLessThan(900);
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(700, 0);
|
|
await page.screenshot({ path: test.info().outputPath("usages-smart-size.png"), animations: "disabled" });
|
|
await popup.getByRole("button", { name: "Show Preview", exact: true }).click();
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(160, 0);
|
|
expect(await page.evaluate(() => localStorage.getItem("openidea.usages.popupSize.v1"))).toBeNull();
|
|
await popup.getByRole("button", { name: "Show Preview", exact: true }).click();
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeLessThan(300);
|
|
await expect(popup.getByRole("region", { name: "Preview", exact: true }).locator(".cm-content")).toBeVisible();
|
|
await page.evaluate(async () => {
|
|
await document.fonts.ready;
|
|
await new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
});
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((animation) => animation.finished)));
|
|
const finalSize = (await popup.boundingBox())!;
|
|
await page.keyboard.press("Escape");
|
|
await expect(popup).toHaveCount(0);
|
|
const saved = await page.evaluate(() => JSON.parse(localStorage.getItem("openidea.usages.popupSize.v1")!));
|
|
expect(saved.w).toBeCloseTo(finalSize.width, 0);
|
|
expect(saved.h).toBeCloseTo(finalSize.height, 0);
|
|
});
|
|
|
|
test("Show Usages sizes to arriving content and fits the screen without flipping away from the caret", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1600, height: 1200 });
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/A.ts";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 40, y: 50 },
|
|
symbol: "run",
|
|
loading: true,
|
|
groups: [{ path, usages: [{ path, line: 0, col: 0, endCol: 3, text: "run();" }] }],
|
|
});
|
|
});
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await expect(popup).toBeVisible();
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((a) => a.finished)));
|
|
const short = (await popup.boundingBox())!;
|
|
expect(short.width).toBeLessThan(680);
|
|
expect(short.x).toBeCloseTo(40, 0);
|
|
expect(short.y).toBeCloseTo(50, 0);
|
|
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/TransportPlanConfigurationService.ts";
|
|
useUsagesPopup.setState({
|
|
loading: false,
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: Array.from({ length: 40 }, (_, line) => ({
|
|
path,
|
|
line,
|
|
col: 0,
|
|
endCol: 3,
|
|
text: "run(configuration, currentUser, transportPlan, approvalStatus);",
|
|
})),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeGreaterThan(short.width + 100);
|
|
const list = popup.getByRole("listbox", { name: "Usages" });
|
|
await expect.poll(async () => (await list.boundingBox())!.height).toBeCloseTo(30 * 24 + 8, 0);
|
|
const wide = (await popup.boundingBox())!.width;
|
|
await popup.getByTestId("usages-popup").focus();
|
|
await page.keyboard.type("zzzz");
|
|
await expect(popup.getByText("Nothing matches 'zzzz'", { exact: true })).toBeVisible();
|
|
expect((await popup.boundingBox())!.width).toBeCloseTo(wide, 0);
|
|
await page.keyboard.press("Escape");
|
|
await popup.getByRole("button", { name: "Show Preview", exact: true }).click();
|
|
const preview = popup.getByRole("region", { name: "Preview", exact: true });
|
|
await expect
|
|
.poll(async () => {
|
|
const groupHeight = await preview.evaluate((el) => el.closest("[data-group]")!.getBoundingClientRect().height);
|
|
return (await preview.boundingBox())!.height / (groupHeight - 1);
|
|
})
|
|
.toBeCloseTo(0.4, 2);
|
|
expect((await list.boundingBox())!.height).toBeLessThan(20 * 24 + 8);
|
|
await page.keyboard.press("Escape");
|
|
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
useUsagesPopup.setState({ open: true, anchor: { x: 1590, y: 1190 } });
|
|
});
|
|
await expect
|
|
.poll(async () => {
|
|
const box = (await popup.boundingBox())!;
|
|
return box.x + box.width;
|
|
})
|
|
.toBeCloseTo(1594, 0);
|
|
await expect
|
|
.poll(async () => {
|
|
const box = (await popup.boundingBox())!;
|
|
return box.y + box.height;
|
|
})
|
|
.toBeLessThanOrEqual(1194);
|
|
await page.setViewportSize({ width: 480, height: 360 });
|
|
await expect
|
|
.poll(async () => {
|
|
const box = (await popup.boundingBox())!;
|
|
return Math.max(box.x + box.width - 474, box.y + box.height - 354);
|
|
})
|
|
.toBeLessThanOrEqual(1);
|
|
await expect(popup.getByRole("button", { name: "Show Preview", exact: true })).toBeVisible();
|
|
expect(await list.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true);
|
|
});
|
|
|
|
test("Show Usages drags by the title bar, keeps its controls usable and stays inside the viewport", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/src/Main.ts";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 100, y: 100 },
|
|
symbol: "run",
|
|
scope: "project",
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: Array.from({ length: 4 }, (_, line) => ({ path, line, col: 0, endCol: 3, text: "run();" })),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
const title = popup.getByText("Usages of run", { exact: true });
|
|
await expect(popup).toBeVisible();
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((a) => a.finished)));
|
|
const before = (await popup.boundingBox())!;
|
|
await page.screenshot({ path: test.info().outputPath("usages-before-drag.png") });
|
|
|
|
// The empty space after the caption, where the reported drag failed.
|
|
const caption = (await title.locator("..").boundingBox())!;
|
|
const start = { x: caption.x + caption.width - 4, y: caption.y + caption.height / 2 };
|
|
await page.mouse.move(start.x, start.y);
|
|
await page.mouse.down();
|
|
await page.mouse.move(start.x + 120, start.y + 100, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(before.x + 120, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(before.y + 100, 0);
|
|
let moved = (await popup.boundingBox())!;
|
|
expect(moved.width).toBeCloseTo(before.width, 0);
|
|
expect(moved.height).toBeCloseTo(before.height, 0);
|
|
await page.screenshot({ path: test.info().outputPath("usages-after-drag.png") });
|
|
|
|
await popup.getByRole("button", { name: "Scope", exact: true }).click();
|
|
await expect(page.getByRole("option", { name: "Project and Libraries", exact: true })).toBeVisible();
|
|
await page.keyboard.press("Escape");
|
|
await popup.getByRole("button", { name: "Show Preview", exact: true }).click();
|
|
await expect(popup.getByRole("region", { name: "Preview", exact: true })).toBeVisible();
|
|
await expect(popup.getByRole("region", { name: "Preview", exact: true }).locator(".cm-content")).toBeVisible();
|
|
await page.evaluate(async () => {
|
|
await document.fonts.ready;
|
|
await new Promise<void>((resolve) => requestAnimationFrame(() => requestAnimationFrame(() => resolve())));
|
|
});
|
|
await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(before.x, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(before.y, 0);
|
|
moved = (await popup.boundingBox())!;
|
|
|
|
const resizeBefore = (await popup.boundingBox())!;
|
|
const corner = (await popup.getByRole("separator", { name: "Resize", exact: true }).boundingBox())!;
|
|
await page.mouse.move(corner.x + 4, corner.y + 4);
|
|
await page.mouse.down();
|
|
await page.mouse.move(corner.x + 84, corner.y + 64, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeCloseTo(resizeBefore.width + 80, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(resizeBefore.height + 60, 0);
|
|
expect((await popup.boundingBox())!.x).toBeCloseTo(moved.x, 0);
|
|
expect((await popup.boundingBox())!.y).toBeCloseTo(moved.y, 0);
|
|
|
|
// Cancelling a press must release the drag before the next pointer move.
|
|
const cancelAt = (await title.boundingBox())!;
|
|
await page.mouse.move(cancelAt.x + 5, cancelAt.y + 5);
|
|
await page.mouse.down();
|
|
await page.evaluate(() => window.dispatchEvent(new PointerEvent("pointercancel")));
|
|
await page.mouse.move(cancelAt.x + 45, cancelAt.y + 25);
|
|
await page.mouse.up();
|
|
expect((await popup.boundingBox())!.x).toBeCloseTo(moved.x, 0);
|
|
expect((await popup.boundingBox())!.y).toBeCloseTo(moved.y, 0);
|
|
|
|
// A later drag starts at the new position and clamps at both sides of the viewport.
|
|
let handle = (await title.boundingBox())!;
|
|
await page.mouse.move(handle.x + 5, handle.y + 5);
|
|
await page.mouse.down();
|
|
await page.mouse.move(-1000, -1000, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(6, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(6, 0);
|
|
|
|
handle = (await title.boundingBox())!;
|
|
await page.mouse.move(handle.x + 5, handle.y + 5);
|
|
await page.mouse.down();
|
|
await page.mouse.move(2400, 1600, { steps: 5 });
|
|
await page.mouse.up();
|
|
const viewport = page.viewportSize()!;
|
|
await expect
|
|
.poll(async () => {
|
|
const box = (await popup.boundingBox())!;
|
|
return box.x + box.width;
|
|
})
|
|
.toBeCloseTo(viewport.width - 6, 0);
|
|
await expect
|
|
.poll(async () => {
|
|
const box = (await popup.boundingBox())!;
|
|
return box.y + box.height;
|
|
})
|
|
.toBeCloseTo(viewport.height - 6, 0);
|
|
handle = (await title.boundingBox())!;
|
|
await page.mouse.move(handle.x + 5, handle.y + 5);
|
|
await page.mouse.down();
|
|
await page.keyboard.press("Escape");
|
|
await expect(popup).toHaveCount(0);
|
|
await expect(page.locator("[data-drag-cursor-surface]")).toHaveCount(0);
|
|
await page.mouse.up();
|
|
});
|
|
|
|
test("Show Usages distinguishes same-named files without losing the line or snippet", async ({ workbench: page }) => {
|
|
await page.setViewportSize({ width: 480, height: 620 });
|
|
await page.evaluate(async () => {
|
|
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 900, h: 240 }));
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const symbol = "submitOrder";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 30, y: 90 },
|
|
symbol,
|
|
groups: (
|
|
[
|
|
["/dev/acme-api/packages/billing/src/Routes.ts", "return submitOrder(invoice);"],
|
|
["/dev/acme-api/packages/checkout/src/Routes.ts", "return submitOrder(cart);"],
|
|
["/dev/acme-api/src/Worker.ts", "await submitOrder(job);"],
|
|
] as const
|
|
).map(([path, text]) => {
|
|
const col = text.indexOf(symbol);
|
|
return { path, usages: [{ path, line: 6, col, endCol: col + symbol.length, text }] };
|
|
}),
|
|
});
|
|
});
|
|
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
const rows = popup.getByRole("option");
|
|
const billing = rows.filter({ hasText: "invoice" });
|
|
const checkout = rows.filter({ hasText: "cart" });
|
|
await expect(rows).toHaveCount(3);
|
|
for (const [row, directory] of [
|
|
[billing, "billing"],
|
|
[checkout, "checkout"],
|
|
] as const) {
|
|
await expect(row.getByText("Routes.ts", { exact: true })).toBeVisible();
|
|
const caption = row.getByText(directory, { exact: true });
|
|
await expect(caption).toBeVisible();
|
|
// Narrow windows may ellipsize the directory under the filename column's cap.
|
|
await expect(caption).toHaveCSS("text-overflow", "ellipsis");
|
|
await expect(row.getByTitle(`/dev/acme-api/packages/${directory}/src/Routes.ts`, { exact: true })).toBeVisible();
|
|
await expect(row.getByText("7", { exact: true })).toBeVisible();
|
|
await expect(row.locator("mark")).toHaveText("submitOrder");
|
|
}
|
|
|
|
await expect(checkout.getByTitle("/dev/acme-api/packages/checkout/src/Routes.ts", { exact: true })).toBeVisible();
|
|
await expect(rows.filter({ hasText: "Worker.ts" }).getByText("src", { exact: true })).toHaveCount(0);
|
|
|
|
// Once there is enough room, both directory labels are shown in full again.
|
|
await page.setViewportSize({ width: 1400, height: 900 });
|
|
await resizePopupWidth(page, 900);
|
|
for (const [row, directory] of [
|
|
[billing, "billing"],
|
|
[checkout, "checkout"],
|
|
] as const) {
|
|
await expect
|
|
.poll(() => row.getByText(directory, { exact: true }).evaluate((el) => el.scrollWidth - el.clientWidth))
|
|
.toBeLessThanOrEqual(1);
|
|
}
|
|
});
|
|
|
|
test("Show Usages fits the filename column to its content and gives added width to code", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1800, height: 900 });
|
|
await page.evaluate(async () => {
|
|
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 1200, h: 240 }));
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 30, y: 70 },
|
|
symbol: "getNoOrderApproveDetail",
|
|
groups: ["LmsTransportPlanController.java", "NoOrderApprovalDetailTest.java"].map((file, line) => {
|
|
const path = `/dev/app/src/${file}`;
|
|
return {
|
|
path,
|
|
usages: [{ path, line, col: 0, endCol: 22, text: "getNoOrderApproveDetail(query);" }],
|
|
};
|
|
}),
|
|
});
|
|
});
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await expect(popup).toBeVisible();
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((a) => a.finished)));
|
|
await page.evaluate(async () => {
|
|
await document.fonts.ready;
|
|
});
|
|
await resizePopupWidth(page, 1200);
|
|
const file = popup.getByTitle("/dev/app/src/LmsTransportPlanController.java", { exact: true });
|
|
const before = (await file.boundingBox())!.width;
|
|
const code = popup.getByTestId("usage-row").first().locator(":scope > span:last-child");
|
|
const codeBefore = (await code.boundingBox())!.width;
|
|
const corner = (await popup.getByRole("separator", { name: "Resize" }).boundingBox())!;
|
|
await page.mouse.move(corner.x + 4, corner.y + 4);
|
|
await page.mouse.down();
|
|
await page.mouse.move(corner.x + 304, corner.y + 84, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect.poll(async () => (await file.boundingBox())!.width).toBeCloseTo(before, 0);
|
|
await expect.poll(async () => (await code.boundingBox())!.width).toBeGreaterThan(codeBefore + 290);
|
|
for (const name of ["LmsTransportPlanController.java", "NoOrderApprovalDetailTest.java"]) {
|
|
const label = popup.getByTestId("usage-row").getByText(name, { exact: true });
|
|
await expect(label).toBeVisible();
|
|
expect(await label.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
|
}
|
|
await expect(popup.locator("mark")).toHaveCount(2);
|
|
await page.screenshot({ path: test.info().outputPath("usages-wide-filenames.png") });
|
|
});
|
|
|
|
test("Show Usages caps exceptionally long filenames to preserve code in wide and narrow windows", async ({
|
|
workbench: page,
|
|
}) => {
|
|
const name = "LmsCarrierWaterCarrierRatingApprovalTransportPlanConfigurationServiceImpl.java";
|
|
const path = `/dev/app/src/${name}`;
|
|
await page.evaluate(async (path) => {
|
|
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 1000, h: 240 }));
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 30, y: 70 },
|
|
symbol: "run",
|
|
groups: [{ path, usages: [{ path, line: 123, col: 0, endCol: 3, text: "run(query);" }] }],
|
|
});
|
|
}, path);
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
const row = popup.getByTestId("usage-row");
|
|
await resizePopupWidth(page, 1000);
|
|
const file = row.getByTitle(path, { exact: true });
|
|
const label = row.getByText(name, { exact: true });
|
|
const code = row.locator(":scope > span:last-child");
|
|
await expect(popup).toBeVisible();
|
|
await expect
|
|
.poll(async () => (await file.boundingBox())!.width / (await popup.boundingBox())!.width)
|
|
.toBeLessThanOrEqual(0.25);
|
|
expect((await file.boundingBox())!.width).toBeGreaterThan(200);
|
|
expect(await label.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeGreaterThan(0);
|
|
expect((await code.boundingBox())!.width).toBeGreaterThan(300);
|
|
await page.setViewportSize({ width: 480, height: 620 });
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeLessThanOrEqual(468);
|
|
await expect
|
|
.poll(async () => (await file.boundingBox())!.width / (await popup.boundingBox())!.width)
|
|
.toBeLessThanOrEqual(0.25);
|
|
expect(await label.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeGreaterThan(0);
|
|
expect((await code.boundingBox())!.width).toBeGreaterThanOrEqual(100);
|
|
await expect(row.getByText("124", { exact: true })).toBeVisible();
|
|
await expect(row.locator("mark")).toHaveText("run");
|
|
});
|
|
|
|
test("Show Usages stops smart sizing after a manual resize and resumes it when reopened", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1200, height: 1200 });
|
|
const show = () =>
|
|
page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/src/Main.ts";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 30, y: 60 },
|
|
symbol: "run",
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: Array.from({ length: 40 }, (_, line) => ({ path, line, col: 0, endCol: 3, text: "run();" })),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
await show();
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
const list = popup.getByRole("listbox", { name: "Usages" });
|
|
await popup.evaluate(async (el) => {
|
|
await document.fonts.ready;
|
|
await Promise.all(el.getAnimations().map((animation) => animation.finished));
|
|
});
|
|
const before = (await popup.boundingBox())!;
|
|
const listBefore = (await list.boundingBox())!;
|
|
const corner = (await popup.getByRole("separator", { name: "Resize" }).boundingBox())!;
|
|
await page.mouse.move(corner.x + corner.width / 2, corner.y + corner.height / 2);
|
|
await page.mouse.down();
|
|
await page.mouse.move(corner.x + 200, corner.y + 150, { steps: 5 });
|
|
await page.mouse.up();
|
|
const after = (await popup.boundingBox())!;
|
|
expect(after.width).toBeGreaterThan(before.width + 150);
|
|
expect(after.height).toBeGreaterThan(before.height + 100);
|
|
// The list, not empty space, takes the added height.
|
|
expect((await list.boundingBox())!.height).toBeGreaterThan(listBefore.height + 100);
|
|
await page.screenshot({ path: test.info().outputPath("usages-resized.png") });
|
|
|
|
await page.evaluate(async () => {
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/src/TransportPlanConfigurationService.ts";
|
|
useUsagesPopup.setState({
|
|
groups: [
|
|
{
|
|
path,
|
|
usages: Array.from({ length: 80 }, (_, line) => ({
|
|
path,
|
|
line,
|
|
col: 0,
|
|
endCol: 3,
|
|
text: "run(configuration, currentUser, transportPlan, approvalStatus);",
|
|
})),
|
|
},
|
|
],
|
|
});
|
|
});
|
|
await expect(popup.getByTestId("usages-popup")).toHaveAttribute("data-total", "80");
|
|
expect((await popup.boundingBox())!.width).toBeCloseTo(after.width, 0);
|
|
expect((await popup.boundingBox())!.height).toBeCloseTo(after.height, 0);
|
|
|
|
await page.keyboard.press("Escape");
|
|
await expect(popup).toHaveCount(0);
|
|
await show();
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((animation) => animation.finished)));
|
|
const reopened = (await popup.boundingBox())!;
|
|
expect(reopened.width).toBeCloseTo(before.width, 0);
|
|
expect(reopened.height).toBeCloseTo(before.height, 0);
|
|
await popup.getByRole("button", { name: "Show Preview", exact: true }).click();
|
|
await expect(popup.getByRole("region", { name: "Preview", exact: true })).toBeVisible();
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeLessThan(before.height);
|
|
expect(await page.evaluate(() => localStorage.getItem("openidea.usages.popupSize.v1"))).toBeNull();
|
|
await popup.getByRole("button", { name: "Show Preview", exact: true }).click();
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeCloseTo(before.height, 0);
|
|
});
|
|
|
|
test("Show Usages preserves minimum dimensions for saved sizes and manual resizing while fitting the viewport", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.evaluate(async () => {
|
|
localStorage.setItem("openidea.usages.popupSize.v1", JSON.stringify({ w: 250, h: 80 }));
|
|
const usages = "/src/features/code-insight/usages.ts";
|
|
const { useUsagesPopup } = await import(/* @vite-ignore */ usages);
|
|
const path = "/dev/app/A.ts";
|
|
useUsagesPopup.setState({
|
|
open: true,
|
|
anchor: { x: 40, y: 50 },
|
|
symbol: "run",
|
|
groups: [{ path, usages: [0, 1].map((line) => ({ path, line, col: 0, endCol: 3, text: "run();" })) }],
|
|
});
|
|
});
|
|
const popup = page.getByRole("dialog", { name: "Usages", exact: true });
|
|
await expect(popup).toBeVisible();
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeCloseTo(360, 0);
|
|
expect((await popup.boundingBox())!.height).toBeCloseTo(160, 0);
|
|
await expect(popup).not.toHaveAttribute("data-resized");
|
|
await popup.evaluate((el) => Promise.all(el.getAnimations().map((animation) => animation.finished)));
|
|
const corner = (await popup.getByRole("separator", { name: "Resize" }).boundingBox())!;
|
|
await page.mouse.move(corner.x + 4, corner.y + 4);
|
|
await page.mouse.down();
|
|
await page.mouse.move(corner.x - 200, corner.y - 100, { steps: 5 });
|
|
await page.mouse.up();
|
|
await expect(popup).toHaveAttribute("data-resized");
|
|
expect((await popup.boundingBox())!.width).toBeCloseTo(360, 0);
|
|
expect((await popup.boundingBox())!.height).toBeCloseTo(160, 0);
|
|
await page.setViewportSize({ width: 320, height: 140 });
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeLessThanOrEqual(308);
|
|
await expect.poll(async () => (await popup.boundingBox())!.height).toBeLessThanOrEqual(128);
|
|
});
|