Skip to content

Commit a702a36

Browse files
committed
Fix tests
1 parent 7d933ca commit a702a36

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

webview-ui/src/components/settings/ModelPicker.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ export const ModelPicker = ({
130130
onValueChange={setSearchValue}
131131
placeholder="Search"
132132
className="h-9 mr-4"
133+
data-testid="model-input"
133134
/>
134135
{searchValue.length > 0 && (
135136
<div className="absolute right-2 top-0 bottom-0 flex items-center justify-center">

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// cd webview-ui && npx jest src/components/settings/__tests__/ModelPicker.test.ts
1+
// npx jest src/components/settings/__tests__/ModelPicker.test.ts
22

33
import { screen, fireEvent, render } from "@testing-library/react"
44
import { act } from "react"
5+
56
import { ModelPicker } from "../ModelPicker"
67

78
jest.mock("../../../context/ExtensionStateContext", () => ({
@@ -69,9 +70,16 @@ describe("ModelPicker", () => {
6970
})
7071

7172
await act(async () => {
72-
// Find and click the model item by its value.
73-
const modelItem = screen.getByTestId("model-input")
74-
fireEvent.input(modelItem, { target: { value: "model2" } })
73+
// Find and set the input value
74+
const modelInput = screen.getByTestId("model-input")
75+
fireEvent.input(modelInput, { target: { value: "model2" } })
76+
})
77+
78+
// Need to find and click the CommandItem to trigger onSelect
79+
await act(async () => {
80+
// Find the CommandItem for model2 and click it
81+
const modelItem = screen.getByText("model2")
82+
fireEvent.click(modelItem)
7583
})
7684

7785
// Verify the API config was updated.

0 commit comments

Comments
 (0)