From 4a563573e67b782cbbf5f3fc934fb17fb32a63c7 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Tue, 22 Jul 2025 17:55:49 +0000 Subject: [PATCH] fix: update Bedrock tests to handle mocked Select component properly --- .../providers/__tests__/Bedrock.spec.tsx | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/webview-ui/src/components/settings/providers/__tests__/Bedrock.spec.tsx b/webview-ui/src/components/settings/providers/__tests__/Bedrock.spec.tsx index a2f6774563..9b5e816bb7 100644 --- a/webview-ui/src/components/settings/providers/__tests__/Bedrock.spec.tsx +++ b/webview-ui/src/components/settings/providers/__tests__/Bedrock.spec.tsx @@ -59,17 +59,29 @@ vi.mock("@src/i18n/TranslationContext", () => ({ }), })) +// Store mock callbacks globally for test access +const mockSelectCallbacks: { [key: string]: any } = {} + // Mock the UI components vi.mock("@src/components/ui", () => ({ - Select: ({ children, onValueChange }: any) => { - // Store the onValueChange callback on the window for testing + Select: ({ children, onValueChange, value }: any) => { + // Store the onValueChange callback on the window for testing (for new tests) if (typeof window !== "undefined") { ;(window as any).__selectOnValueChange = onValueChange } - return
{children}
+ // Also store the callback for test access (for existing tests) + if (onValueChange) { + mockSelectCallbacks.onValueChange = onValueChange + } + + return ( +
+ {children} +
+ ) }, SelectContent: ({ children }: any) =>
{children}
, - SelectItem: () =>
Item
, + SelectItem: ({ value }: any) =>
Item
, SelectTrigger: ({ children }: any) =>
{children}
, SelectValue: () =>
Value
, StandardTooltip: ({ children }: any) =>
{children}
, @@ -451,13 +463,12 @@ describe("Bedrock Component", () => { // Custom region input should not be visible initially expect(screen.queryByTestId("custom-region-input")).not.toBeInTheDocument() - // Mock the Select component to simulate selecting "custom" - // Since we're mocking the Select component, we need to simulate the onValueChange call - const selectComponent = screen.getByRole("combobox", { hidden: true }) - if (selectComponent) { - // Simulate selecting "custom" region - const onValueChange = (selectComponent as any).onValueChange || (() => {}) - onValueChange("custom") + // Verify the Select component is rendered + expect(screen.getByTestId("select-component")).toBeInTheDocument() + + // Call the onValueChange callback directly + if (mockSelectCallbacks.onValueChange) { + mockSelectCallbacks.onValueChange("custom") } // Verify that setApiConfigurationField was called with "custom" @@ -482,11 +493,12 @@ describe("Bedrock Component", () => { expect(screen.getByTestId("custom-region-input")).toBeInTheDocument() expect(screen.getByTestId("custom-region-input")).toHaveValue("us-west-3") - // Mock selecting a standard region - const selectComponent = screen.getByRole("combobox", { hidden: true }) - if (selectComponent) { - const onValueChange = (selectComponent as any).onValueChange || (() => {}) - onValueChange("us-east-1") + // Verify the Select component is rendered + expect(screen.getByTestId("select-component")).toBeInTheDocument() + + // Call the onValueChange callback directly + if (mockSelectCallbacks.onValueChange) { + mockSelectCallbacks.onValueChange("us-east-1") } // Verify that both awsRegion and awsCustomRegion were updated