Skip to content

Commit c799239

Browse files
committed
test: use data-testid for querying
1 parent 1edefd4 commit c799239

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface ApiErrorMessageProps {
66
}
77

88
export const ApiErrorMessage = ({ errorMessage, children }: ApiErrorMessageProps) => (
9-
<div className="flex flex-col gap-2 text-vscode-errorForeground text-sm">
9+
<div className="flex flex-col gap-2 text-vscode-errorForeground text-sm" data-testid="api-error-message">
1010
<div className="flex flex-row items-center gap-1">
1111
<div className="codicon codicon-close" />
1212
<div>{errorMessage}</div>

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ export const ModelPicker = ({
122122
variant="combobox"
123123
role="combobox"
124124
aria-expanded={open}
125-
className="w-full justify-between">
125+
className="w-full justify-between"
126+
data-testid="model-picker-button">
126127
<div>{selectedModelId ?? t("settings:common.select")}</div>
127128
<ChevronsUpDown className="opacity-50" />
128129
</Button>
@@ -157,7 +158,11 @@ export const ModelPicker = ({
157158
</CommandEmpty>
158159
<CommandGroup>
159160
{modelIds.map((model) => (
160-
<CommandItem key={model} value={model} onSelect={onSelect}>
161+
<CommandItem
162+
key={model}
163+
value={model}
164+
onSelect={onSelect}
165+
data-testid={`model-option-${model}`}>
161166
{model}
162167
<Check
163168
className={cn(

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe("ModelPicker", () => {
7373

7474
await act(async () => {
7575
// Open the popover by clicking the button.
76-
const button = screen.getByRole("combobox")
76+
const button = screen.getByTestId("model-picker-button")
7777
fireEvent.click(button)
7878
})
7979

@@ -91,7 +91,7 @@ describe("ModelPicker", () => {
9191
// Need to find and click the CommandItem to trigger onSelect
9292
await act(async () => {
9393
// Find the CommandItem for model2 and click it
94-
const modelItem = screen.getByText("model2")
94+
const modelItem = screen.getByTestId("model-option-model2")
9595
fireEvent.click(modelItem)
9696
})
9797

@@ -104,7 +104,7 @@ describe("ModelPicker", () => {
104104

105105
await act(async () => {
106106
// Open the popover by clicking the button.
107-
const button = screen.getByRole("combobox")
107+
const button = screen.getByTestId("model-picker-button")
108108
fireEvent.click(button)
109109
})
110110

@@ -154,6 +154,7 @@ describe("ModelPicker", () => {
154154
})
155155

156156
// Check that the error message is displayed
157+
expect(screen.getByTestId("api-error-message")).toBeInTheDocument()
157158
expect(screen.getByText(errorMessage)).toBeInTheDocument()
158159
})
159160

@@ -180,13 +181,13 @@ describe("ModelPicker", () => {
180181
})
181182

182183
// Check that both the model selector and error message are present
183-
const modelSelector = screen.getByRole("combobox")
184+
const modelSelector = screen.getByTestId("model-picker-button")
185+
const errorContainer = screen.getByTestId("api-error-message")
184186
const errorElement = screen.getByText(errorMessage)
185187

186188
expect(modelSelector).toBeInTheDocument()
189+
expect(errorContainer).toBeInTheDocument()
187190
expect(errorElement).toBeInTheDocument()
188-
189-
// Verify the error message is rendered (positioning is handled by CSS)
190191
expect(errorElement).toBeVisible()
191192
})
192193

@@ -201,6 +202,7 @@ describe("ModelPicker", () => {
201202
)
202203

203204
// Check initial error is displayed
205+
expect(screen.getByTestId("api-error-message")).toBeInTheDocument()
204206
expect(screen.getByText(initialError)).toBeInTheDocument()
205207

206208
// Update the error message
@@ -211,6 +213,7 @@ describe("ModelPicker", () => {
211213
)
212214

213215
// Check that the error message has been updated
216+
expect(screen.getByTestId("api-error-message")).toBeInTheDocument()
214217
expect(screen.queryByText(initialError)).not.toBeInTheDocument()
215218
expect(screen.getByText(updatedError)).toBeInTheDocument()
216219
})
@@ -225,6 +228,7 @@ describe("ModelPicker", () => {
225228
)
226229

227230
// Check error is initially displayed
231+
expect(screen.getByTestId("api-error-message")).toBeInTheDocument()
228232
expect(screen.getByText(errorMessage)).toBeInTheDocument()
229233

230234
// Remove the error message
@@ -235,6 +239,7 @@ describe("ModelPicker", () => {
235239
)
236240

237241
// Check that the error message has been removed
242+
expect(screen.queryByTestId("api-error-message")).not.toBeInTheDocument()
238243
expect(screen.queryByText(errorMessage)).not.toBeInTheDocument()
239244
})
240245
})

0 commit comments

Comments
 (0)