Skip to content

Commit c3d3cc7

Browse files
committed
Fix tests
1 parent 86a4a9c commit c3d3cc7

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
// npx jest src/components/settings/__tests__/ApiConfigManager.test.tsx
2+
3+
import React from "react"
14
import { render, screen, fireEvent, within } from "@testing-library/react"
5+
26
import ApiConfigManager from "../ApiConfigManager"
37

48
// Mock VSCode components
59
jest.mock("@vscode/webview-ui-toolkit/react", () => ({
6-
VSCodeButton: ({ children, onClick, title, disabled, "data-testid": dataTestId }: any) => (
7-
<button onClick={onClick} title={title} disabled={disabled} data-testid={dataTestId}>
8-
{children}
9-
</button>
10-
),
1110
VSCodeTextField: ({ value, onInput, placeholder, onKeyDown, "data-testid": dataTestId }: any) => (
1211
<input
1312
value={value}
@@ -20,33 +19,15 @@ jest.mock("@vscode/webview-ui-toolkit/react", () => ({
2019
),
2120
}))
2221

23-
jest.mock("vscrui", () => ({
24-
Dropdown: ({ id, value, onChange, options, role }: any) => (
25-
<div data-testid={`mock-dropdown-${id}`}>
26-
<select value={value} onChange={(e) => onChange({ value: e.target.value })} data-testid={id} role={role}>
27-
{options.map((opt: any) => (
28-
<option key={opt.value} value={opt.value}>
29-
{opt.label}
30-
</option>
31-
))}
32-
</select>
33-
</div>
34-
),
35-
}))
36-
37-
// Mock Dialog component
38-
jest.mock("@/components/ui/dialog", () => ({
22+
jest.mock("@/components/ui", () => ({
23+
...jest.requireActual("@/components/ui"),
3924
Dialog: ({ children, open, onOpenChange }: any) => (
4025
<div role="dialog" aria-modal="true" style={{ display: open ? "block" : "none" }} data-testid="dialog">
4126
{children}
4227
</div>
4328
),
4429
DialogContent: ({ children }: any) => <div data-testid="dialog-content">{children}</div>,
4530
DialogTitle: ({ children }: any) => <div data-testid="dialog-title">{children}</div>,
46-
}))
47-
48-
// Mock UI components
49-
jest.mock("@/components/ui", () => ({
5031
Button: ({ children, onClick, disabled, variant, "data-testid": dataTestId }: any) => (
5132
<button onClick={onClick} disabled={disabled} data-testid={dataTestId}>
5233
{children}
@@ -61,6 +42,25 @@ jest.mock("@/components/ui", () => ({
6142
data-testid={dataTestId}
6243
/>
6344
),
45+
Select: ({ children, value, onValueChange }: any) => (
46+
<select
47+
value={value}
48+
onChange={(e) => {
49+
if (onValueChange) onValueChange(e.target.value)
50+
}}
51+
data-testid="select-component">
52+
<option value="Default Config">Default Config</option>
53+
<option value="Another Config">Another Config</option>
54+
</select>
55+
),
56+
SelectTrigger: ({ children }: any) => <div className="select-trigger-mock">{children}</div>,
57+
SelectValue: ({ children }: any) => <div className="select-value-mock">{children}</div>,
58+
SelectContent: ({ children }: any) => <div className="select-content-mock">{children}</div>,
59+
SelectItem: ({ children, value }: any) => (
60+
<option value={value} className="select-item-mock">
61+
{children}
62+
</option>
63+
),
6464
}))
6565

6666
describe("ApiConfigManager", () => {
@@ -215,7 +215,7 @@ describe("ApiConfigManager", () => {
215215
it("allows selecting a different config", () => {
216216
render(<ApiConfigManager {...defaultProps} />)
217217

218-
const select = screen.getByRole("combobox")
218+
const select = screen.getByTestId("select-component")
219219
fireEvent.change(select, { target: { value: "Another Config" } })
220220

221221
expect(mockOnSelectConfig).toHaveBeenCalledWith("Another Config")

0 commit comments

Comments
 (0)