mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
The shared Popup decided where it fit using the max-height cap from its previous placement, so a popup clipped below its anchor still looked as if it fit there: the agent Composer's @ list stayed clipped after erasing the filter or when file results arrived after it opened. A middleware now clears the old cap before flip, and the size step only caps a popup that is taller than the space available. Co-authored-by: Mr0Bread <55754540+Mr0Bread@users.noreply.github.com>
118 lines
4.7 KiB
TypeScript
118 lines
4.7 KiB
TypeScript
import type { Locator, Page } from "@playwright/test";
|
|
import type { AgentTask } from "../src/bindings";
|
|
import { expect, test } from "./fixtures";
|
|
|
|
const task: AgentTask = {
|
|
id: "composer-popup",
|
|
title: "Composer popup task",
|
|
provider: "codex",
|
|
status: "ready",
|
|
isolation: "local",
|
|
model: null,
|
|
cwd: "/dev/acme-api",
|
|
branch: null,
|
|
base: null,
|
|
baseCommit: null,
|
|
error: null,
|
|
createdMs: 0,
|
|
updatedMs: 0,
|
|
config: [],
|
|
commands: [],
|
|
usage: null,
|
|
queue: [],
|
|
};
|
|
|
|
async function openTask(page: Page, delayFiles = false) {
|
|
await page.evaluate(
|
|
async ({ task, delayFiles }) => {
|
|
// Load the workbench modules in Vite's browser realm, not the Playwright runner.
|
|
const storePath = "/src/features/agents/store.ts";
|
|
const ipcPath = "/src/platform/ipc.ts";
|
|
const store = await import(storePath);
|
|
const { commands } = await import(ipcPath);
|
|
const { promise: filesReady, resolve } = Promise.withResolvers<void>();
|
|
if (delayFiles) window.addEventListener("test:release-composer-files", () => resolve(), { once: true });
|
|
else resolve();
|
|
const file = (name: string) => ({ path: `${task.cwd}/${name}`, relPath: name, score: 1, indices: [] });
|
|
commands.agentChanges = async () => ({ status: "ok", data: [] });
|
|
commands.findFiles = async (query: string) => {
|
|
if (!query) await filesReady;
|
|
return {
|
|
status: "ok",
|
|
data: query ? [file("a.ts")] : Array.from({ length: 12 }, (_, i) => file(`file${i}.ts`)),
|
|
};
|
|
};
|
|
commands.findDirs = async () => ({ status: "ok", data: [] });
|
|
store.useAgents.setState({
|
|
loaded: true,
|
|
error: null,
|
|
providers: [],
|
|
tasks: new Map([[task.id, task]]),
|
|
entries: new Map([[task.id, [{ type: "agent", text: "Reply" }]]]),
|
|
composers: new Map(),
|
|
unread: new Set(),
|
|
docked: null,
|
|
homeOpen: false,
|
|
sessionLocation: "editor",
|
|
});
|
|
store.openTask(task.id);
|
|
},
|
|
{ task, delayFiles },
|
|
);
|
|
const editor = page.getByRole("textbox", { name: "Message", exact: true });
|
|
await editor.click();
|
|
return { editor, list: page.getByRole("listbox", { name: "Files", exact: true }) };
|
|
}
|
|
|
|
function geometry(list: Locator) {
|
|
return list.evaluate((list) => {
|
|
const popup = list.closest<HTMLElement>("[data-popup]")!;
|
|
const rect = popup.getBoundingClientRect();
|
|
const caret = getSelection()!.getRangeAt(0).getBoundingClientRect();
|
|
const footer = popup.querySelector("span:last-child > kbd")!.getBoundingClientRect();
|
|
return {
|
|
side: rect.bottom <= caret.top ? "above" : rect.top >= caret.bottom ? "below" : "overlap",
|
|
height: popup.offsetHeight,
|
|
listHeight: list.clientHeight,
|
|
inViewport: rect.top >= 0 && rect.bottom <= innerHeight && rect.left >= 0 && rect.right <= innerWidth,
|
|
footerVisible: footer.height > 0 && footer.top >= rect.top && footer.bottom <= rect.bottom,
|
|
};
|
|
});
|
|
}
|
|
|
|
const fullList = { side: "above", listHeight: 300, inViewport: true, footerVisible: true };
|
|
|
|
test("erasing the @ filter restores the popup's fitting side and height", async ({ workbench: page }) => {
|
|
const { editor, list } = await openTask(page);
|
|
await editor.pressSequentially("@");
|
|
await expect(list.getByText("file0.ts", { exact: true })).toBeVisible();
|
|
await expect.poll(() => geometry(list)).toMatchObject(fullList);
|
|
const initial = await geometry(list);
|
|
|
|
await editor.pressSequentially("a");
|
|
await expect(list.getByText("a.ts", { exact: true })).toBeVisible();
|
|
await expect.poll(() => geometry(list)).toMatchObject({ side: "below", footerVisible: true });
|
|
await editor.press("Backspace");
|
|
await expect(list.getByText("file0.ts", { exact: true })).toBeVisible();
|
|
await expect.poll(() => geometry(list)).toEqual(initial);
|
|
await expect(editor).toBeFocused();
|
|
await expect(editor).toHaveText("@");
|
|
});
|
|
|
|
test("first-open @ results can grow and flip after asynchronous file search", async ({ workbench: page }) => {
|
|
const { editor, list } = await openTask(page, true);
|
|
for (let i = 0; i < 3; i++) await editor.press("Shift+Enter");
|
|
await editor.press("ArrowUp");
|
|
await editor.press("ArrowUp");
|
|
await editor.press("ArrowUp");
|
|
await editor.pressSequentially("@");
|
|
await expect(list.getByRole("option").first()).toBeVisible();
|
|
await expect.poll(() => geometry(list)).toMatchObject({ side: "below", footerVisible: true });
|
|
await expect(list.getByText("file0.ts", { exact: true })).toHaveCount(0);
|
|
|
|
await page.evaluate(() => window.dispatchEvent(new Event("test:release-composer-files")));
|
|
await expect(list.getByText("file0.ts", { exact: true })).toBeVisible();
|
|
await expect.poll(() => geometry(list)).toMatchObject(fullList);
|
|
await expect(editor).toBeFocused();
|
|
});
|