forked from RooCodeInc/Roo-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageGenerationSettings.spec.tsx
More file actions
90 lines (72 loc) · 3.09 KB
/
ImageGenerationSettings.spec.tsx
File metadata and controls
90 lines (72 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { render, fireEvent } from "@testing-library/react"
import { ImageGenerationSettings } from "../ImageGenerationSettings"
// Mock the translation context
vi.mock("@/i18n/TranslationContext", () => ({
useAppTranslation: () => ({
t: (key: string) => key,
}),
}))
describe("ImageGenerationSettings", () => {
const mockSetOpenRouterImageApiKey = vi.fn()
const mockSetImageGenerationSelectedModel = vi.fn()
const mockOnChange = vi.fn()
const defaultProps = {
enabled: false,
onChange: mockOnChange,
openRouterImageApiKey: undefined,
openRouterImageGenerationSelectedModel: undefined,
setOpenRouterImageApiKey: mockSetOpenRouterImageApiKey,
setImageGenerationSelectedModel: mockSetImageGenerationSelectedModel,
}
beforeEach(() => {
vi.clearAllMocks()
})
describe("Initial Mount Behavior", () => {
it("should not call setter functions on initial mount with empty configuration", () => {
render(<ImageGenerationSettings {...defaultProps} />)
// Should NOT call setter functions on initial mount to prevent dirty state
expect(mockSetOpenRouterImageApiKey).not.toHaveBeenCalled()
expect(mockSetImageGenerationSelectedModel).not.toHaveBeenCalled()
})
it("should not call setter functions on initial mount with existing configuration", () => {
render(
<ImageGenerationSettings
{...defaultProps}
openRouterImageApiKey="existing-key"
openRouterImageGenerationSelectedModel="google/gemini-2.5-flash-image"
/>,
)
// Should NOT call setter functions on initial mount to prevent dirty state
expect(mockSetOpenRouterImageApiKey).not.toHaveBeenCalled()
expect(mockSetImageGenerationSelectedModel).not.toHaveBeenCalled()
})
})
describe("User Interaction Behavior", () => {
it("should call setimageGenerationSettings when user changes API key", async () => {
const { getByPlaceholderText } = render(<ImageGenerationSettings {...defaultProps} enabled={true} />)
const apiKeyInput = getByPlaceholderText(
"settings:experimental.IMAGE_GENERATION.openRouterApiKeyPlaceholder",
)
// Simulate user typing
fireEvent.input(apiKeyInput, { target: { value: "new-api-key" } })
// Should call setimageGenerationSettings
expect(defaultProps.setOpenRouterImageApiKey).toHaveBeenCalledWith("new-api-key")
})
// Note: Testing VSCode dropdown components is complex due to their custom nature
// The key functionality (not marking as dirty on initial mount) is already tested above
})
describe("Conditional Rendering", () => {
it("should render input fields when enabled is true", () => {
const { getByPlaceholderText } = render(<ImageGenerationSettings {...defaultProps} enabled={true} />)
expect(
getByPlaceholderText("settings:experimental.IMAGE_GENERATION.openRouterApiKeyPlaceholder"),
).toBeInTheDocument()
})
it("should not render input fields when enabled is false", () => {
const { queryByPlaceholderText } = render(<ImageGenerationSettings {...defaultProps} enabled={false} />)
expect(
queryByPlaceholderText("settings:experimental.IMAGE_GENERATION.openRouterApiKeyPlaceholder"),
).not.toBeInTheDocument()
})
})
})