This repository was archived by the owner on May 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathChatTextArea.lockApiConfig.spec.tsx
More file actions
156 lines (127 loc) · 4.66 KB
/
Copy pathChatTextArea.lockApiConfig.spec.tsx
File metadata and controls
156 lines (127 loc) · 4.66 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { defaultModeSlug } from "@roo/modes"
import { render, fireEvent, screen } from "@src/utils/test-utils"
import { useExtensionState } from "@src/context/ExtensionStateContext"
import { vscode } from "@src/utils/vscode"
import { ChatTextArea } from "../ChatTextArea"
vi.mock("@src/utils/vscode", () => ({
vscode: {
postMessage: vi.fn(),
},
}))
vi.mock("@src/components/common/CodeBlock")
vi.mock("@src/components/common/MarkdownBlock")
vi.mock("@src/utils/path-mentions", () => ({
convertToMentionPath: vi.fn((path: string) => path),
}))
// Mock ExtensionStateContext
vi.mock("@src/context/ExtensionStateContext")
const mockPostMessage = vscode.postMessage as ReturnType<typeof vi.fn>
describe("ChatTextArea - lockApiConfigAcrossModes toggle", () => {
const defaultProps = {
inputValue: "",
setInputValue: vi.fn(),
onSend: vi.fn(),
sendingDisabled: false,
selectApiConfigDisabled: false,
onSelectImages: vi.fn(),
shouldDisableImages: false,
placeholderText: "Type a message...",
selectedImages: [] as string[],
setSelectedImages: vi.fn(),
onHeightChange: vi.fn(),
mode: defaultModeSlug,
setMode: vi.fn(),
modeShortcutText: "(⌘. for next mode)",
}
const defaultState = {
filePaths: [],
openedTabs: [],
apiConfiguration: { apiProvider: "anthropic" },
taskHistory: [],
cwd: "/test/workspace",
listApiConfigMeta: [{ id: "default", name: "Default", modelId: "claude-3" }],
currentApiConfigName: "Default",
pinnedApiConfigs: {},
togglePinnedApiConfig: vi.fn(),
}
beforeEach(() => {
vi.clearAllMocks()
})
/**
* Helper: Opens the ApiConfigSelector popover by clicking the trigger,
* then returns the lock toggle button by its aria-label.
*/
const openPopoverAndGetLockToggle = (ariaLabel: string) => {
const trigger = screen.getByTestId("dropdown-trigger")
fireEvent.click(trigger)
return screen.getByRole("button", { name: ariaLabel })
}
describe("rendering", () => {
it("renders with muted opacity when lockApiConfigAcrossModes is false", () => {
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
...defaultState,
lockApiConfigAcrossModes: false,
})
render(<ChatTextArea {...defaultProps} />)
const button = openPopoverAndGetLockToggle("chat:lockApiConfigAcrossModes")
expect(button).toBeInTheDocument()
// Unlocked state has visible but muted style
expect(button.className).toContain("text-vscode-descriptionForeground")
expect(button.className).not.toContain("text-vscode-focusBorder")
})
it("renders with highlight color when lockApiConfigAcrossModes is true", () => {
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
...defaultState,
lockApiConfigAcrossModes: true,
})
render(<ChatTextArea {...defaultProps} />)
const button = openPopoverAndGetLockToggle("chat:unlockApiConfigAcrossModes")
expect(button).toBeInTheDocument()
// Locked state has the focus border highlight color
expect(button.className).toContain("text-vscode-focusBorder")
expect(button.className).not.toContain("text-vscode-descriptionForeground")
})
it("renders in unlocked state when lockApiConfigAcrossModes is undefined (default)", () => {
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
...defaultState,
})
render(<ChatTextArea {...defaultProps} />)
const button = openPopoverAndGetLockToggle("chat:lockApiConfigAcrossModes")
expect(button).toBeInTheDocument()
// Default (undefined/falsy) renders in unlocked style
expect(button.className).toContain("text-vscode-descriptionForeground")
})
})
describe("interaction", () => {
it("posts lockApiConfigAcrossModes=true message when locking", () => {
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
...defaultState,
lockApiConfigAcrossModes: false,
})
render(<ChatTextArea {...defaultProps} />)
// Clear any initialization messages
mockPostMessage.mockClear()
const button = openPopoverAndGetLockToggle("chat:lockApiConfigAcrossModes")
fireEvent.click(button)
expect(mockPostMessage).toHaveBeenCalledWith({
type: "lockApiConfigAcrossModes",
bool: true,
})
})
it("posts lockApiConfigAcrossModes=false message when unlocking", () => {
;(useExtensionState as ReturnType<typeof vi.fn>).mockReturnValue({
...defaultState,
lockApiConfigAcrossModes: true,
})
render(<ChatTextArea {...defaultProps} />)
// Clear any initialization messages
mockPostMessage.mockClear()
const button = openPopoverAndGetLockToggle("chat:unlockApiConfigAcrossModes")
fireEvent.click(button)
expect(mockPostMessage).toHaveBeenCalledWith({
type: "lockApiConfigAcrossModes",
bool: false,
})
})
})
})