import { render, screen, fireEvent } from "@testing-library/react"; import { describe, it, expect, jest } from "@jest/globals"; import ToolsTab from "../ToolsTab"; import { Tool } from "@modelcontextprotocol/sdk/types.js"; import { Tabs } from "@/components/ui/tabs"; describe("ToolsTab", () => { const mockTools: Tool[] = [ { name: "tool1", description: "First tool", inputSchema: { type: "object" as const, properties: { num: { type: "number" as const }, }, }, }, { name: "tool2", description: "Second tool", inputSchema: { type: "object" as const, properties: { num: { type: "number" as const }, }, }, }, ]; const defaultProps = { tools: mockTools, listTools: jest.fn(), clearTools: jest.fn(), callTool: jest.fn(), selectedTool: null, setSelectedTool: jest.fn(), toolResult: null, nextCursor: "", error: null, }; const renderToolsTab = (props = {}) => { return render( , ); }; it("should reset input values when switching tools", () => { const { rerender } = renderToolsTab({ selectedTool: mockTools[0], }); // Enter a value in the first tool's input const input = screen.getByRole("spinbutton") as HTMLInputElement; fireEvent.change(input, { target: { value: "42" } }); expect(input.value).toBe("42"); // Switch to second tool rerender( , ); // Verify input is reset const newInput = screen.getByRole("spinbutton") as HTMLInputElement; expect(newInput.value).toBe(""); }); });