@@ -6,7 +6,7 @@ import { providerIdentifiers } from "@roo-code/types"
66import { fireEvent , renderWithExtensionState , screen } from "@/utils/test-utils"
77import { useOpenRouterModelProviders } from "@src/components/ui/hooks/useOpenRouterModelProviders"
88
9- import { CodeIndexPopover , createValidationSchema , shouldAutoPopulateBedrockSettings } from "../CodeIndexPopover"
9+ import { CodeIndexPopover , createValidationSchema } from "../CodeIndexPopover"
1010
1111vi . 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 } < / d i v > ,
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-
109116describe ( "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