From 374434f85dab2b2b84b1e9ae1107f60b85aef277 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 4 Dec 2025 05:53:00 +0000 Subject: [PATCH] fix: make focus grabbing test more robust by waiting for debounce effects --- .../src/components/chat/__tests__/ChatView.spec.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/webview-ui/src/components/chat/__tests__/ChatView.spec.tsx b/webview-ui/src/components/chat/__tests__/ChatView.spec.tsx index 7a6d0a0bc1..3947018af0 100644 --- a/webview-ui/src/components/chat/__tests__/ChatView.spec.tsx +++ b/webview-ui/src/components/chat/__tests__/ChatView.spec.tsx @@ -468,7 +468,12 @@ describe("ChatView - Focus Grabbing Tests", () => { expect(getByTestId("chat-textarea")).toBeInTheDocument() }) - // Clear any initial calls after state has settled + // Wait for debounced focus effect to settle (useDebounceEffect has 50ms delay) + await act(async () => { + await new Promise((resolve) => setTimeout(resolve, 100)) + }) + + // Clear any initial calls after state and debounce effects have settled mockFocus.mockClear() // Add follow-up question @@ -494,7 +499,13 @@ describe("ChatView - Focus Grabbing Tests", () => { expect(getByTestId("chat-textarea")).toBeInTheDocument() }) + // Wait for any debounced effects to settle after the follow-up message + await act(async () => { + await new Promise((resolve) => setTimeout(resolve, 100)) + }) + // Should not grab focus for follow-up questions + // (enableButtons is set to true for followup to prevent focus grab) expect(mockFocus).not.toHaveBeenCalled() }) })