Skip to content

Commit bcc7e8d

Browse files
committed
Fix tests
1 parent b4ebacc commit bcc7e8d

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

src/core/config/__tests__/ProviderSettingsManager.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,21 @@ describe("ProviderSettingsManager", () => {
4141
expect(mockSecrets.store).not.toHaveBeenCalled()
4242
})
4343

44-
it("should not initialize config if it exists", async () => {
44+
it("should not initialize config if it exists and migrations are complete", async () => {
4545
mockSecrets.get.mockResolvedValue(
4646
JSON.stringify({
4747
currentApiConfigName: "default",
4848
apiConfigs: {
4949
default: {
5050
config: {},
5151
id: "default",
52+
diffEnabled: true,
53+
fuzzyMatchThreshold: 1.0,
5254
},
5355
},
5456
migrations: {
5557
rateLimitSecondsMigrated: true,
58+
diffSettingsMigrated: true,
5659
},
5760
}),
5861
)
@@ -75,14 +78,19 @@ describe("ProviderSettingsManager", () => {
7578
apiProvider: "anthropic",
7679
},
7780
},
81+
migrations: {
82+
rateLimitSecondsMigrated: true,
83+
diffSettingsMigrated: true,
84+
},
7885
}),
7986
)
8087

8188
await providerSettingsManager.initialize()
8289

8390
// Should have written the config with new IDs
8491
expect(mockSecrets.store).toHaveBeenCalled()
85-
const storedConfig = JSON.parse(mockSecrets.store.mock.calls[0][1])
92+
const calls = mockSecrets.store.mock.calls
93+
const storedConfig = JSON.parse(calls[calls.length - 1][1]) // Get the latest call
8694
expect(storedConfig.apiConfigs.default.id).toBeTruthy()
8795
expect(storedConfig.apiConfigs.test.id).toBeTruthy()
8896
})

webview-ui/src/components/settings/__tests__/ApiOptions.test.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,33 @@ jest.mock("../ThinkingBudget", () => ({
9696
) : null,
9797
}))
9898

99+
// Mock DiffSettingsControl for tests
100+
jest.mock("../DiffSettingsControl", () => ({
101+
DiffSettingsControl: ({ diffEnabled, fuzzyMatchThreshold, onChange }: any) => (
102+
<div data-testid="diff-settings-control">
103+
<label>
104+
Enable editing through diffs
105+
<input
106+
type="checkbox"
107+
checked={diffEnabled}
108+
onChange={(e) => onChange("diffEnabled", e.target.checked)}
109+
/>
110+
</label>
111+
<div>
112+
Fuzzy match threshold
113+
<input
114+
type="range"
115+
value={fuzzyMatchThreshold || 1.0}
116+
onChange={(e) => onChange("fuzzyMatchThreshold", parseFloat(e.target.value))}
117+
min={0.8}
118+
max={1}
119+
step={0.005}
120+
/>
121+
</div>
122+
</div>
123+
),
124+
}))
125+
99126
const renderApiOptions = (props = {}) => {
100127
const queryClient = new QueryClient()
101128

@@ -116,14 +143,23 @@ const renderApiOptions = (props = {}) => {
116143
}
117144

118145
describe("ApiOptions", () => {
119-
it("shows temperature and rate limit controls by default", () => {
120-
renderApiOptions()
146+
it("shows diff settings, temperature and rate limit controls by default", () => {
147+
renderApiOptions({
148+
apiConfiguration: {
149+
diffEnabled: true,
150+
fuzzyMatchThreshold: 0.95,
151+
},
152+
})
153+
// Check for DiffSettingsControl by looking for text content
154+
expect(screen.getByText(/enable editing through diffs/i)).toBeInTheDocument()
121155
expect(screen.getByTestId("temperature-control")).toBeInTheDocument()
122156
expect(screen.getByTestId("rate-limit-seconds-control")).toBeInTheDocument()
123157
})
124158

125-
it("hides temperature and rate limit controls when fromWelcomeView is true", () => {
159+
it("hides all controls when fromWelcomeView is true", () => {
126160
renderApiOptions({ fromWelcomeView: true })
161+
// Check for absence of DiffSettingsControl text
162+
expect(screen.queryByText(/enable editing through diffs/i)).not.toBeInTheDocument()
127163
expect(screen.queryByTestId("temperature-control")).not.toBeInTheDocument()
128164
expect(screen.queryByTestId("rate-limit-seconds-control")).not.toBeInTheDocument()
129165
})

0 commit comments

Comments
 (0)