Skip to content

Commit d334815

Browse files
committed
test(webview): cover Bedrock select binding
1 parent 04cba4f commit d334815

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

webview-ui/src/components/chat/CodeIndexPopover.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ interface LocalCodeIndexSettings {
8888
codebaseIndexOpenRouterSpecificProvider?: string
8989
}
9090

91-
export const shouldAutoPopulateBedrockSettings = (
92-
embedderProvider: EmbedderProvider,
93-
apiProvider: string | undefined,
94-
): boolean => embedderProvider === providerIdentifiers.bedrock && apiProvider === providerIdentifiers.bedrock
95-
9691
type TranslationCallback = (key: string) => string
9792

9893
// Validation schema for codebase index settings
@@ -732,10 +727,8 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
732727
// Auto-populate Region and Profile when switching to Bedrock
733728
// if the main API provider is also configured for Bedrock
734729
if (
735-
shouldAutoPopulateBedrockSettings(
736-
value,
737-
apiConfiguration?.apiProvider,
738-
)
730+
value === providerIdentifiers.bedrock &&
731+
apiConfiguration?.apiProvider === providerIdentifiers.bedrock
739732
) {
740733
// Only populate if currently empty
741734
if (

webview-ui/src/components/chat/__tests__/CodeIndexPopover.test.tsx

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { providerIdentifiers } from "@roo-code/types"
66
import { fireEvent, renderWithExtensionState, screen } from "@/utils/test-utils"
77
import { useOpenRouterModelProviders } from "@src/components/ui/hooks/useOpenRouterModelProviders"
88

9-
import { CodeIndexPopover, createValidationSchema, shouldAutoPopulateBedrockSettings } from "../CodeIndexPopover"
9+
import { CodeIndexPopover, createValidationSchema } from "../CodeIndexPopover"
1010

1111
vi.mock("@src/components/ui/hooks/useOpenRouterModelProviders", () => ({
1212
OPENROUTER_DEFAULT_PROVIDER_NAME: "Auto",
@@ -22,6 +22,24 @@ vi.mock("@src/components/ui", async (importOriginal) => {
2222
return <>{children}</>
2323
},
2424
PopoverContent: ({ children }: React.PropsWithChildren) => <div>{children}</div>,
25+
Select: ({
26+
children,
27+
value,
28+
onValueChange,
29+
}: React.PropsWithChildren<{
30+
value?: string
31+
onValueChange?: (value: string) => void
32+
}>) => (
33+
<select value={value} onChange={(event) => onValueChange?.(event.target.value)}>
34+
{children}
35+
</select>
36+
),
37+
SelectTrigger: () => null,
38+
SelectValue: () => null,
39+
SelectContent: ({ children }: React.PropsWithChildren) => <>{children}</>,
40+
SelectItem: ({ children, value }: React.PropsWithChildren<{ value: string }>) => (
41+
<option value={value}>{children}</option>
42+
),
2543
}
2644
})
2745

@@ -95,21 +113,14 @@ describe("CodeIndexPopover validation", () => {
95113
})
96114
})
97115

98-
describe("shouldAutoPopulateBedrockSettings", () => {
99-
it("only enables Bedrock defaults when both providers are Bedrock", () => {
100-
expect(shouldAutoPopulateBedrockSettings(providerIdentifiers.bedrock, providerIdentifiers.bedrock)).toBe(true)
101-
expect(shouldAutoPopulateBedrockSettings(providerIdentifiers.bedrock, providerIdentifiers.anthropic)).toBe(
102-
false,
103-
)
104-
expect(shouldAutoPopulateBedrockSettings(providerIdentifiers.openai, providerIdentifiers.bedrock)).toBe(false)
105-
expect(shouldAutoPopulateBedrockSettings(providerIdentifiers.bedrock, undefined)).toBe(false)
106-
})
107-
})
108-
109116
describe("CodeIndexPopover OpenRouter provider lookup", () => {
110117
const mockedUseOpenRouterModelProviders = vi.mocked(useOpenRouterModelProviders)
111118

112-
const renderPopover = (provider: EmbedderProvider, modelId: string) =>
119+
const renderPopover = (
120+
provider: EmbedderProvider,
121+
modelId: string,
122+
apiProvider?: ExtensionState["apiConfiguration"],
123+
) =>
113124
renderWithExtensionState(
114125
<CodeIndexPopover indexingStatus={indexingStatus}>
115126
<button>Open code index settings</button>
@@ -122,6 +133,7 @@ describe("CodeIndexPopover OpenRouter provider lookup", () => {
122133
codebaseIndexEmbedderModelId: modelId,
123134
},
124135
codebaseIndexModels: {},
136+
apiConfiguration: apiProvider,
125137
platform: "darwin",
126138
arch: "arm64",
127139
} as Partial<ExtensionState>,
@@ -169,4 +181,41 @@ describe("CodeIndexPopover OpenRouter provider lookup", () => {
169181

170182
expect(screen.getByText(label)).toBeInTheDocument()
171183
})
184+
185+
it.each([
186+
{
187+
name: "matching Bedrock API provider",
188+
apiConfiguration: {
189+
apiProvider: providerIdentifiers.bedrock,
190+
awsRegion: "us-west-2",
191+
awsProfile: "development",
192+
},
193+
expectedRegion: "us-west-2",
194+
expectedProfile: "development",
195+
},
196+
{
197+
name: "mismatched API provider",
198+
apiConfiguration: {
199+
apiProvider: providerIdentifiers.anthropic,
200+
awsRegion: "us-west-2",
201+
awsProfile: "development",
202+
},
203+
expectedRegion: "",
204+
expectedProfile: "",
205+
},
206+
{
207+
name: "unset API provider",
208+
apiConfiguration: undefined,
209+
expectedRegion: "",
210+
expectedProfile: "",
211+
},
212+
] as const)("populates Bedrock fields for $name", ({ apiConfiguration, expectedRegion, expectedProfile }) => {
213+
renderPopover(providerIdentifiers.openai, "embedding-model", apiConfiguration)
214+
fireEvent.click(screen.getByText("settings:codeIndex.setupConfigLabel"))
215+
216+
fireEvent.change(screen.getAllByRole("combobox")[0], { target: { value: providerIdentifiers.bedrock } })
217+
218+
expect(screen.getByPlaceholderText("settings:codeIndex.bedrockRegionPlaceholder")).toHaveValue(expectedRegion)
219+
expect(screen.getByPlaceholderText("settings:codeIndex.bedrockProfilePlaceholder")).toHaveValue(expectedProfile)
220+
})
172221
})

0 commit comments

Comments
 (0)