дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
The Show Usages popup could be resized but not moved: its header had no move handler, so it could not be dragged off the code it covers. Popup gains an opt-in `draggable` mode that moves it by descendants marked `data-popup-drag` (the same pattern Dialog uses with `data-dialog-drag`), skipping interactive controls; once moved the popup is positioned at its new place without flipping back to the anchor and stays 6 px inside the viewport. Show Usages marks its header as the drag handle. Covered by e2e/usagesPopupLayout.spec.ts. Co-authored-by: chiyanking <[email protected]>
200 рядки
8.8 KiB
TypeScript
200 рядки
8.8 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 () => {
|
|
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();
|
|
expect(await caption.evaluate((el) => el.scrollWidth - el.clientWidth)).toBeLessThanOrEqual(1);
|
|
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);
|
|
});
|
|
|
|
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);
|
|
});
|