Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions apps/server/src/preview/ThreadLinkNavigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ it("keeps clicked thread navigations in the app, including hosted new windows",
const browserCdp = await browser.newBrowserCDPSession();
const { targetInfo: sourceTarget } = await cdp.send("Target.getTargetInfo");
let closeProtocolPopup = false;
let created = Promise.withResolvers<string>();
browserCdp.on("Target.targetCreated", ({ targetInfo }) => {
if (
closeProtocolPopup &&
targetInfo.type === "page" &&
targetInfo.targetId !== sourceTarget.targetId
)
void browserCdp.send("Target.closeTarget", { targetId: targetInfo.targetId });
created.resolve(targetInfo.targetId);
});
await browserCdp.send("Target.setDiscoverTargets", { discover: true });
await context.route(hosted, (route) =>
Expand Down Expand Up @@ -76,13 +77,17 @@ it("keeps clicked thread navigations in the app, including hosted new windows",
["#hostedPopup", hosted],
]) {
opened = Promise.withResolvers<string>();
created = Promise.withResolvers<string>();
// A custom-protocol target has no document to finish initialising. Close
// the real Chromium target to exercise its uncommitted, already-closed popup event.
closeProtocolPopup = selector === "#popup" || selector === "#customPopup";
const detached = ["#popup", "#customPopup", "#hostedPopup"].includes(selector!)
? new Promise<Page>((resolve) => page.once("popup", resolve))
: undefined;
await page.locator(selector!).click();
// Closing during window.open can strand Chromium's source input dispatch.
if (closeProtocolPopup)
await browserCdp.send("Target.closeTarget", { targetId: await created.promise });
expect(await opened.promise).toBe(expected);
if (detached) {
const popup = await detached;
Expand Down Expand Up @@ -201,7 +206,7 @@ it("preserves HTTP caching and lets typed or agent-loaded hosted documents load"
}
});

it("continues dropped opens and expires announcements before a later typed navigation", async () => {
it("handles closed thread popups, dropped opens, and expired announcements", async () => {
const events = new NodeEvents.EventEmitter();
const send = vi.fn(async (method: string) =>
method === "Page.getFrameTree" ? { frameTree: { frame: { id: "main" } } } : {},
Expand Down Expand Up @@ -250,6 +255,14 @@ it("continues dropped opens and expires announcements before a later typed navig
pause("dropped-open");
expect(navigation.isThreadNavigation(hosted)).toBe(false);
open.mockReturnValue(true);
const closedPopup = { url: () => ":", isClosed: () => true, close: vi.fn(async () => {}) };
blockPopup.mockImplementationOnce((received: Page) => {
expect(received.isClosed()).toBe(true);
});
events.emit("Page.windowOpen", { url: href, userGesture: true });
page.emit("popup", closedPopup);
expect(blockPopup).toHaveBeenCalledWith(closedPopup);
expect(closedPopup.close).toHaveBeenCalledOnce();
announce();
expect(navigation.isThreadNavigation(hosted)).toBe(true);
gesture("inactive");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ describe("MessagesTimeline messages", () => {
</>
);
await using screen = await renderElement(conversation([]));
// Keep the conversation and composer visible so input does not scroll the test document.
screen.container.style.height = "min(600px, 100vh)";
const focus = createWorkspaceFocusController(document);
using cleanup = new DisposableStack();
cleanup.defer(focus.dispose);
Expand All @@ -370,6 +372,9 @@ describe("MessagesTimeline messages", () => {
expect(document.activeElement?.getAttribute("data-workspace-area")).toBe("conversation");
await screen.rerender(conversation(entries));
const viewport = props.listRef.current!.getScrollableNode()!;
// Reserve viewport padding that cannot hit a virtual row or one of its controls.
viewport.style.paddingRight = "32px";
await expect.element(screen.getByText("Turn 39:")).toHaveStyle({ pointerEvents: "auto" });
await vi.waitFor(() => expect(viewport.scrollTop).toBeGreaterThan(0));
const atEnd = viewport.scrollTop;
await userEvent.keyboard("{ArrowUp}");
Expand All @@ -379,8 +384,8 @@ describe("MessagesTimeline messages", () => {
focus.move(-1);
expect(document.activeElement).toBe(viewport);
screen.button("Send").focus();
// Click the blank lane between the minimap and the right-aligned message controls.
await userEvent.click(viewport, { position: { x: 100, y: 1 } });
await userEvent.click(viewport, { position: { x: viewport.clientWidth - 16, y: 1 } });
await vi.waitFor(() => expect(document.activeElement).toBe(viewport));
await userEvent.keyboard("{Home}");
await vi.waitFor(() => expect(viewport.scrollTop).toBe(0));
await userEvent.keyboard("{ArrowDown}");
Expand Down