дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
The Show Usages filename column had a fixed cap, so widening the popup did not reveal more of a truncated filename. The column now takes the width of the longest filename among all results (measured off-screen, so virtualized rows, speed search and filters keep the columns aligned), capped at 176px (38% when narrow) or a fifth of a wider popup; the code column gets the rest. It is remeasured when results or font metrics change. Same-named files keep their directory captions. Co-authored-by: chiyanking <[email protected]>
296 рядки
14 KiB
TypeScript
296 рядки
14 KiB
TypeScript
import { expect, test } from "./fixtures";
|
|
|
|
test.use({ video: "on" });
|
|
|
|
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);
|
|
const 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.poll(async () => (await popup.boundingBox())!.x).toBeCloseTo(moved.x, 0);
|
|
await expect.poll(async () => (await popup.boundingBox())!.y).toBeCloseTo(moved.y, 0);
|
|
|
|
const resizeBefore = (await popup.boundingBox())!;
|
|
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 + 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 });
|
|
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;
|
|
});
|
|
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");
|
|
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 row.boundingBox())!.width * 0.2)
|
|
.toBeCloseTo(0, 0);
|
|
expect(await label.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeGreaterThan(0);
|
|
expect((await code.boundingBox())!.width).toBeGreaterThan(500);
|
|
await page.setViewportSize({ width: 480, height: 620 });
|
|
await expect.poll(async () => (await popup.boundingBox())!.width).toBeLessThanOrEqual(468);
|
|
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 resizes from its corner, the list fills it, and it reopens at that size", async ({
|
|
workbench: page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 1200, height: 800 });
|
|
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" });
|
|
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.keyboard.press("Escape");
|
|
await expect(popup).toHaveCount(0);
|
|
await show();
|
|
const reopened = (await popup.boundingBox())!;
|
|
expect(Math.abs(reopened.width - after.width)).toBeLessThanOrEqual(1);
|
|
expect(Math.abs(reopened.height - after.height)).toBeLessThanOrEqual(1);
|
|
});
|