Browse Source

fix: Mock dropdown in tests correctly

Prathmesh Vhatkar 11 months ago
parent
commit
7e38e50d79

+ 1 - 0
webview-ui/src/components/settings/ApiConfigManager.tsx

@@ -144,6 +144,7 @@ const ApiConfigManager = ({
 								style={{
 								style={{
 									minWidth: 130,
 									minWidth: 130,
 								}}
 								}}
+								role="combobox"
 								options={listApiConfigMeta.map((config) => ({
 								options={listApiConfigMeta.map((config) => ({
 									value: config.name,
 									value: config.name,
 									label: config.name,
 									label: config.name,

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

@@ -19,6 +19,20 @@ jest.mock("@vscode/webview-ui-toolkit/react", () => ({
 	),
 	),
 }))
 }))
 
 
+jest.mock("vscrui", () => ({
+	Dropdown: ({ id, value, onChange, options, role }: any) => (
+		<div data-testid={`mock-dropdown-${id}`}>
+			<select value={value} onChange={(e) => onChange({ value: e.target.value })} data-testid={id} role={role}>
+				{options.map((opt: any) => (
+					<option key={opt.value} value={opt.value}>
+						{opt.label}
+					</option>
+				))}
+			</select>
+		</div>
+	),
+}))
+
 describe("ApiConfigManager", () => {
 describe("ApiConfigManager", () => {
 	const mockOnSelectConfig = jest.fn()
 	const mockOnSelectConfig = jest.fn()
 	const mockOnDeleteConfig = jest.fn()
 	const mockOnDeleteConfig = jest.fn()