diff --git a/tests/components/McpFormModal.test.tsx b/tests/components/McpFormModal.test.tsx new file mode 100644 index 0000000..d27c47b --- /dev/null +++ b/tests/components/McpFormModal.test.tsx @@ -0,0 +1,227 @@ +import React from "react"; +import { render, screen, fireEvent, waitFor } from "@testing-library/react"; +import { beforeEach, describe, expect, it, vi } from "vitest"; +import McpFormModal from "@/components/mcp/McpFormModal"; + +const toastErrorMock = vi.hoisted(() => vi.fn()); +const toastSuccessMock = vi.hoisted(() => vi.fn()); +const getConfigMock = vi.hoisted(() => vi.fn().mockResolvedValue({ servers: {} })); + +vi.mock("sonner", () => ({ + toast: { + error: (...args: unknown[]) => toastErrorMock(...args), + success: (...args: unknown[]) => toastSuccessMock(...args), + }, +})); + +vi.mock("react-i18next", () => ({ + useTranslation: () => ({ + t: (key: string, params?: Record) => + params ? `${key}:${JSON.stringify(params)}` : key, + }), +})); + +vi.mock("@/config/mcpPresets", () => ({ + mcpPresets: [ + { + id: "preset-stdio", + server: { type: "stdio", command: "preset-cmd" }, + }, + ], + getMcpPresetWithDescription: (preset: any) => ({ + ...preset, + description: "Preset description", + tags: ["preset"], + }), +})); + +vi.mock("@/components/ui/button", () => ({ + Button: ({ children, onClick, type = "button", ...rest }: any) => ( + + ), +})); + +vi.mock("@/components/ui/input", () => ({ + Input: ({ value, onChange, ...rest }: any) => ( + onChange?.({ target: { value: event.target.value } })} + {...rest} + /> + ), +})); + +vi.mock("@/components/ui/textarea", () => ({ + Textarea: ({ value, onChange, ...rest }: any) => ( +