Skip to content

Commit a7f2515

Browse files
committed
Add failing ToolsTab test that should get fixed with pull/198
1 parent fa3e286 commit a7f2515

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { render, screen, fireEvent } from "@testing-library/react";
2+
import { describe, it, expect, jest } from "@jest/globals";
3+
import ToolsTab from "../ToolsTab";
4+
import { Tool } from "@modelcontextprotocol/sdk/types.js";
5+
import { Tabs } from "@/components/ui/tabs";
6+
7+
describe("ToolsTab", () => {
8+
const mockTools: Tool[] = [
9+
{
10+
name: "tool1",
11+
description: "First tool",
12+
inputSchema: {
13+
type: "object" as const,
14+
properties: {
15+
num: { type: "number" as const }
16+
}
17+
}
18+
},
19+
{
20+
name: "tool2",
21+
description: "Second tool",
22+
inputSchema: {
23+
type: "object" as const,
24+
properties: {
25+
num: { type: "number" as const }
26+
}
27+
}
28+
}
29+
];
30+
31+
const defaultProps = {
32+
tools: mockTools,
33+
listTools: jest.fn(),
34+
clearTools: jest.fn(),
35+
callTool: jest.fn(),
36+
selectedTool: null,
37+
setSelectedTool: jest.fn(),
38+
toolResult: null,
39+
nextCursor: "",
40+
error: null
41+
};
42+
43+
const renderToolsTab = (props = {}) => {
44+
return render(
45+
<Tabs defaultValue="tools">
46+
<ToolsTab {...defaultProps} {...props} />
47+
</Tabs>
48+
);
49+
};
50+
51+
it("should reset input values when switching tools", () => {
52+
const { rerender } = renderToolsTab({
53+
selectedTool: mockTools[0]
54+
});
55+
56+
// Enter a value in the first tool's input
57+
const input = screen.getByRole("spinbutton") as HTMLInputElement;
58+
fireEvent.change(input, { target: { value: "42" } });
59+
expect(input.value).toBe("42");
60+
61+
// Switch to second tool
62+
rerender(
63+
<Tabs defaultValue="tools">
64+
<ToolsTab {...defaultProps} selectedTool={mockTools[1]} />
65+
</Tabs>
66+
);
67+
68+
// Verify input is reset
69+
const newInput = screen.getByRole("spinbutton") as HTMLInputElement;
70+
expect(newInput.value).toBe("");
71+
});
72+
});

0 commit comments

Comments
 (0)