11import { render , fireEvent } from "@testing-library/react"
2-
2+ import { vi } from "vitest"
33import { ImageGenerationSettings } from "../ImageGenerationSettings"
4+ import type { ProviderSettings } from "@roo-code/types"
45
56// Mock the translation context
67vi . mock ( "@/i18n/TranslationContext" , ( ) => ( {
@@ -10,49 +11,45 @@ vi.mock("@/i18n/TranslationContext", () => ({
1011} ) )
1112
1213describe ( "ImageGenerationSettings" , ( ) => {
13- const mockSetOpenRouterImageApiKey = vi . fn ( )
14- const mockSetImageGenerationSelectedModel = vi . fn ( )
14+ const mockSetApiConfigurationField = vi . fn ( )
1515 const mockOnChange = vi . fn ( )
1616
1717 const defaultProps = {
1818 enabled : false ,
1919 onChange : mockOnChange ,
20- openRouterImageApiKey : undefined ,
21- openRouterImageGenerationSelectedModel : undefined ,
22- setOpenRouterImageApiKey : mockSetOpenRouterImageApiKey ,
23- setImageGenerationSelectedModel : mockSetImageGenerationSelectedModel ,
20+ apiConfiguration : { } as ProviderSettings ,
21+ setApiConfigurationField : mockSetApiConfigurationField ,
2422 }
2523
2624 beforeEach ( ( ) => {
2725 vi . clearAllMocks ( )
2826 } )
2927
3028 describe ( "Initial Mount Behavior" , ( ) => {
31- it ( "should not call setter functions on initial mount with empty configuration" , ( ) => {
29+ it ( "should not call setApiConfigurationField on initial mount with empty configuration" , ( ) => {
3230 render ( < ImageGenerationSettings { ...defaultProps } /> )
3331
34- // Should NOT call setter functions on initial mount to prevent dirty state
35- expect ( mockSetOpenRouterImageApiKey ) . not . toHaveBeenCalled ( )
36- expect ( mockSetImageGenerationSelectedModel ) . not . toHaveBeenCalled ( )
32+ // Should NOT call setApiConfigurationField on initial mount to prevent dirty state
33+ expect ( mockSetApiConfigurationField ) . not . toHaveBeenCalled ( )
3734 } )
3835
39- it ( "should not call setter functions on initial mount with existing configuration" , ( ) => {
40- render (
41- < ImageGenerationSettings
42- { ...defaultProps }
43- openRouterImageApiKey = "existing-key"
44- openRouterImageGenerationSelectedModel = "google/gemini-2.5-flash-image-preview:free"
45- /> ,
46- )
36+ it ( "should not call setApiConfigurationField on initial mount with existing configuration" , ( ) => {
37+ const apiConfiguration = {
38+ openRouterImageGenerationSettings : {
39+ openRouterApiKey : "existing-key" ,
40+ selectedModel : "google/gemini-2.5-flash-image-preview:free" ,
41+ } ,
42+ } as ProviderSettings
4743
48- // Should NOT call setter functions on initial mount to prevent dirty state
49- expect ( mockSetOpenRouterImageApiKey ) . not . toHaveBeenCalled ( )
50- expect ( mockSetImageGenerationSelectedModel ) . not . toHaveBeenCalled ( )
44+ render ( < ImageGenerationSettings { ...defaultProps } apiConfiguration = { apiConfiguration } /> )
45+
46+ // Should NOT call setApiConfigurationField on initial mount to prevent dirty state
47+ expect ( mockSetApiConfigurationField ) . not . toHaveBeenCalled ( )
5148 } )
5249 } )
5350
5451 describe ( "User Interaction Behavior" , ( ) => {
55- it ( "should call setimageGenerationSettings when user changes API key" , async ( ) => {
52+ it ( "should call setApiConfigurationField when user changes API key" , async ( ) => {
5653 const { getByPlaceholderText } = render ( < ImageGenerationSettings { ...defaultProps } enabled = { true } /> )
5754
5855 const apiKeyInput = getByPlaceholderText (
@@ -62,8 +59,15 @@ describe("ImageGenerationSettings", () => {
6259 // Simulate user typing
6360 fireEvent . input ( apiKeyInput , { target : { value : "new-api-key" } } )
6461
65- // Should call setimageGenerationSettings
66- expect ( defaultProps . setOpenRouterImageApiKey ) . toHaveBeenCalledWith ( "new-api-key" )
62+ // Should call setApiConfigurationField with isUserAction=true
63+ expect ( mockSetApiConfigurationField ) . toHaveBeenCalledWith (
64+ "openRouterImageGenerationSettings" ,
65+ {
66+ openRouterApiKey : "new-api-key" ,
67+ selectedModel : "google/gemini-2.5-flash-image-preview" ,
68+ } ,
69+ true , // This should be true for user actions
70+ )
6771 } )
6872
6973 // Note: Testing VSCode dropdown components is complex due to their custom nature
0 commit comments