test(ui): await handleSearch completion in SearchToolTester tests

Wait for the async search operation to fully settle before ending
tests that fire handleSearch without checking downstream results. The
finally block's setIsLoading(false) was racing with test-file JSDOM
teardown, leaking a 'window is not defined' error from React's
requestUpdateLane after the environment was gone and failing the
whole UI Unit Tests job.

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-08-15 01:38:18 +00:00
parent 40a418440c
commit 8d139fe706
No known key found for this signature in database

View file

@ -93,6 +93,7 @@ describe("SearchToolTester", () => {
const searchButton = screen.getByRole("button", { name: /search/i });
await user.click(searchButton);
expect(networking.searchToolQueryCall).toHaveBeenCalledWith("test-token", "test-search-tool", "test query");
await waitFor(() => expect(searchButton).not.toBeDisabled());
});
it("should call searchToolQueryCall when Enter is pressed in input", async () => {
@ -101,6 +102,7 @@ describe("SearchToolTester", () => {
const input = screen.getByPlaceholderText("Enter your search query...");
await user.type(input, "test query{Enter}");
expect(networking.searchToolQueryCall).toHaveBeenCalledWith("test-token", "test-search-tool", "test query");
await waitFor(() => expect(input).not.toBeDisabled());
});
it("should not call searchToolQueryCall when Shift+Enter is pressed", async () => {
@ -123,6 +125,7 @@ describe("SearchToolTester", () => {
const searchButton = screen.getByRole("button", { name: /search/i });
await user.click(searchButton);
expect(screen.getByText("Searching...")).toBeInTheDocument();
await waitFor(() => expect(screen.queryByText("Searching...")).not.toBeInTheDocument());
});
it("should display search results after successful search", async () => {
@ -407,6 +410,7 @@ describe("SearchToolTester", () => {
await user.click(searchButton);
expect(input).toBeDisabled();
expect(searchButton).toBeDisabled();
await waitFor(() => expect(input).not.toBeDisabled());
});
it("should display result links that open in new tab", async () => {