Skip to content

Commit f7f9e21

Browse files
test(web): migrate the last .ts browser tests and stop wrapping userEvent in act (#22424)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 6ab39ff commit f7f9e21

29 files changed

Lines changed: 469 additions & 294 deletions

‎apps/web/src/components/ChatMarkdown.browser.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ describe("ChatMarkdown math", () => {
14201420
});
14211421
const [preview, after] = container.querySelectorAll("button");
14221422
preview!.focus();
1423-
await act(() => userEvent.tab());
1423+
await userEvent.tab();
14241424
expect(document.activeElement).toBe(after);
14251425
if (formula.includes("notACommand")) {
14261426
expect(page.getByRole("button", { name: /notACommand/ }).element()).toBe(preview);
@@ -1439,7 +1439,7 @@ describe("ChatMarkdown math", () => {
14391439
);
14401440
const { container } = screen;
14411441
container.querySelector("button")!.focus();
1442-
await act(() => userEvent.tab());
1442+
await userEvent.tab();
14431443
expect(document.activeElement).toBe(
14441444
container.querySelector('[aria-label="Scroll inline equation"]'),
14451445
);

‎apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ describe("composer context undo lifetime", () => {
484484
const nextEditor = composer.editor();
485485
expect(nextEditor).not.toBe(previousEditor);
486486
expect(document.activeElement).toBe(nextEditor.view.dom);
487-
await act(async () => userEvent.keyboard("x"));
487+
await userEvent.keyboard("x");
488488
expect(composer.draft().value).toBe("xDraft B");
489489

490490
const button = document.createElement("button");

‎apps/web/src/components/ThreadStatusIndicators.subscriptions.browser.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ it("keeps a long PR hover list in the viewport and lets the last row be selected
200200
/>
201201
</div>,
202202
);
203-
await act(() => userEvent.hover(screen.container.querySelector("button")!));
203+
await userEvent.hover(screen.container.querySelector("button")!);
204204
const popup = () => document.querySelector<HTMLElement>('[data-slot="tooltip-popup"]')!;
205205
await expect.poll(() => popup()?.querySelectorAll("a").length).toBe(40);
206206
await expect.poll(() => popup().getBoundingClientRect().top).toBeGreaterThanOrEqual(0);
@@ -212,13 +212,13 @@ it("keeps a long PR hover list in the viewport and lets the last row be selected
212212
expect(lastRow.getBoundingClientRect().top).toBeGreaterThan(
213213
popup().getBoundingClientRect().bottom,
214214
);
215-
await act(() => userEvent.wheel(popup(), { delta: { y: 10_000 } }));
215+
await userEvent.wheel(popup(), { delta: { y: 10_000 } });
216216
await expect
217217
.poll(() => lastRow.getBoundingClientRect().bottom)
218218
.toBeLessThanOrEqual(popup().getBoundingClientRect().bottom);
219219
expect(lastRow.getBoundingClientRect().top).toBeGreaterThanOrEqual(
220220
popup().getBoundingClientRect().top,
221221
);
222-
await act(() => userEvent.click(lastRow));
222+
await userEvent.click(lastRow);
223223
expect(onOpenPullRequest).toHaveBeenCalledExactlyOnceWith(expect.anything(), lastRow.href);
224224
});

‎apps/web/src/components/chat/ComposerBannerStack.browser.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ it("keeps only the usage limit attached while an active goal waits in the collap
8484
"Usage limit reached",
8585
);
8686

87-
await act(async () => page.getByRole("button", { name: "Show other notices" }).click());
87+
await page.getByRole("button", { name: "Show other notices" }).click();
8888
await expect.element(goal).toBeVisible();
8989
await expect.element(limit).toBeVisible();
9090
await expect.poll(visibleBanners).toHaveLength(2);
9191

92-
await act(async () => userEvent.keyboard("{Escape}"));
92+
await userEvent.keyboard("{Escape}");
9393
await expect.element(goal).not.toBeVisible();
9494
await expect.element(limit).toBeVisible();
9595
expect(visibleBanners()).toHaveLength(1);

‎apps/web/src/components/chat/ComposerStashMenu.browser.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const editor = () => page.getByRole("textbox", { name: "Message" });
6666
const stash = () => page.getByRole("list", { name: "Stashed prompts" });
6767
const restore = (prompt: string) =>
6868
page.getByRole("button", { name: `Restore stashed prompt: ${prompt}` });
69-
const press = (keys: string) => act(async () => userEvent.keyboard(keys));
69+
const press = (keys: string) => userEvent.keyboard(keys);
7070
const focus = (element: Element) => act(async () => (element as HTMLElement).focus());
7171

7272
it("leaves dialog, unrelated input and question button shortcuts alone while the stash is open", async () => {
@@ -128,7 +128,7 @@ it("navigates, deletes and restores stashed prompts from the composer and drawer
128128
await press("{Escape}");
129129
await expect.element(stash()).not.toBeInTheDocument();
130130

131-
await act(async () => userEvent.click(page.getByRole("button", { name: "Open stash" })));
131+
await userEvent.click(page.getByRole("button", { name: "Open stash" }));
132132
await expect.element(restore("first prompt")).not.toBeInTheDocument();
133133
expect(stash().element().textContent).toContain("second prompt");
134134
await focus(editor().element());

‎apps/web/src/components/chat/MessagesTimeline.browser.test.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,8 @@ describe("MessagesTimeline work rows", () => {
215215
);
216216
const row = screen.container.querySelector<HTMLElement>('[data-v2-item-type="file_change"]')!;
217217
const press = async (target: HTMLElement) => {
218-
await act(async () => {
219-
target.focus();
220-
await userEvent.keyboard(key);
221-
});
218+
target.focus();
219+
await userEvent.keyboard(key);
222220
};
223221
expect(row.getAttribute("aria-expanded")).toBe("false");
224222
await press(row);

‎apps/web/src/components/chat/ProviderModelPicker.browser.test.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { page, userEvent } from "vite-plus/test/browser";
1212

1313
import "~/index.css";
1414

15-
import { act, render as renderUi } from "../../../test/render";
15+
import { render as renderUi } from "../../../test/render";
1616
import { deriveProviderInstanceEntries } from "../../providerInstances";
1717
import { ProviderModelPicker } from "./ProviderModelPicker";
1818
import type { ModelEsque } from "./providerIconUtils";
@@ -85,7 +85,7 @@ function renderPicker(input: {
8585
}
8686

8787
async function click(target: Parameters<typeof userEvent.click>[0]) {
88-
await act(async () => userEvent.click(target));
88+
await userEvent.click(target);
8989
}
9090

9191
async function openLegacyPicker(activeModel: string) {

‎apps/web/src/components/chat/QueuedRunsControl.browser.test.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ vi.mock(import("../../assets/assetUrls"), async (importOriginal) => ({
3030
resources.map((resource) => `https://assets.test/${resource.attachmentId}`)) as never,
3131
}));
3232

33-
import { act, render as renderUi } from "../../../test/render";
33+
import { render as renderUi } from "../../../test/render";
3434
import { QueuedRunsControl } from "./QueuedRunsControl";
3535

3636
function setup() {
@@ -204,9 +204,7 @@ it("previews assistant quotes as readable text and preserves the citation when e
204204
.element(page.getByText(`${quotedText} Why per worktree?`, { exact: true }))
205205
.toBeVisible();
206206

207-
await act(async () => {
208-
await page.getByRole("button", { name: "Edit queued message", exact: true }).nth(1).click();
209-
});
207+
await page.getByRole("button", { name: "Edit queued message", exact: true }).nth(1).click();
210208
expect(onEditQueuedRun).toHaveBeenCalledExactlyOnceWith(
211209
expect.objectContaining({ text: quoteAndText }),
212210
);

‎apps/web/src/components/chat/ThreadErrorBanner.browser.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { act, render as renderUi } from "../../../test/render";
1+
import { render as renderUi } from "../../../test/render";
22
import "../../index.css";
33

44
import { expect, it } from "vite-plus/test";
@@ -15,13 +15,13 @@ it("expands even a short JSON error to its exact diagnostics and collapses back
1515
await expect.element(page.getByText("Turn failed", { exact: true })).toBeVisible();
1616
expect(container.textContent).not.toContain("unsupported_value");
1717

18-
await act(async () => page.getByRole("button", { name: "Show full error" }).click());
18+
await page.getByRole("button", { name: "Show full error" }).click();
1919

2020
const diagnostics = page.getByText(error, { exact: true });
2121
await expect.element(diagnostics).toBeVisible();
2222
expect(diagnostics.element().textContent).toBe(error);
2323

24-
await act(async () => page.getByRole("button", { name: "Show less" }).click());
24+
await page.getByRole("button", { name: "Show less" }).click();
2525

2626
await expect.element(page.getByText("Turn failed", { exact: true })).toBeVisible();
2727
expect(container.textContent).not.toContain("unsupported_value");

‎apps/web/src/components/chat/composerFocusRedirect.browser.test.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, describe, expect, it } from "vite-plus/test";
1+
import { describe, expect, it } from "vite-plus/test";
22

33
import { shouldTypeToFocusComposer } from "./composerFocusRedirect";
44

@@ -15,14 +15,15 @@ function typeOn(target: Element, key: string): boolean {
1515
return redirected;
1616
}
1717

18-
afterEach(() => {
19-
document.body.replaceChildren();
20-
});
18+
function attach(element: Element): Disposable {
19+
document.body.append(element);
20+
return { [Symbol.dispose]: () => element.remove() };
21+
}
2122

2223
describe("shouldTypeToFocusComposer", () => {
2324
it("sends letters typed on the chat to the composer", () => {
2425
const chat = document.createElement("div");
25-
document.body.append(chat);
26+
using _chat = attach(chat);
2627

2728
expect(typeOn(chat, "a")).toBe(true);
2829
});
@@ -31,7 +32,7 @@ describe("shouldTypeToFocusComposer", () => {
3132
const deviceScreen = document.createElement("div");
3233
deviceScreen.setAttribute("role", "application");
3334
deviceScreen.tabIndex = 0;
34-
document.body.append(deviceScreen);
35+
using _deviceScreen = attach(deviceScreen);
3536

3637
expect(typeOn(deviceScreen, "a")).toBe(false);
3738
});

0 commit comments

Comments
 (0)