From d2696e48a58eac69ed32515fb36ed5bae0bc4beb Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Mon, 31 Mar 2025 07:32:55 -0700 Subject: [PATCH 1/6] Add failing test for integer input --- .../components/__tests__/ToolsTab.test.tsx | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/client/src/components/__tests__/ToolsTab.test.tsx b/client/src/components/__tests__/ToolsTab.test.tsx index 2a45065..f75c8f9 100644 --- a/client/src/components/__tests__/ToolsTab.test.tsx +++ b/client/src/components/__tests__/ToolsTab.test.tsx @@ -16,6 +16,16 @@ describe("ToolsTab", () => { }, }, }, + { + name: "tool3", + description: "Integer tool", + inputSchema: { + type: "object" as const, + properties: { + count: { type: "integer" as const }, + }, + }, + }, { name: "tool2", description: "Second tool", @@ -69,4 +79,28 @@ describe("ToolsTab", () => { const newInput = screen.getByRole("spinbutton") as HTMLInputElement; expect(newInput.value).toBe(""); }); + + it("should handle integer type inputs", () => { + renderToolsTab({ + selectedTool: mockTools[2], + }); + + // Verify input is rendered as a number input + const input = screen.getByRole("spinbutton") as HTMLInputElement; + expect(input.type).toBe("text"); // This will fail - should be "number" + + // Enter an integer value + fireEvent.change(input, { target: { value: "42" } }); + expect(input.value).toBe("42"); + + // Verify the callTool function receives the value as a number + const submitButton = screen.getByRole("button", { name: /submit/i }); + fireEvent.click(submitButton); + + expect(defaultProps.callTool).toHaveBeenCalledWith( + mockTools[2].name, + { count: 42 }, // Should be number 42, not string "42" + expect.any(Function) + ); + }); }); From 7ac1e40c9dcd1866445baede30a8fe459d9104b9 Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Mon, 31 Mar 2025 07:51:28 -0700 Subject: [PATCH 2/6] Update tests --- client/src/components/__tests__/ToolsTab.test.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/components/__tests__/ToolsTab.test.tsx b/client/src/components/__tests__/ToolsTab.test.tsx index f75c8f9..b36085e 100644 --- a/client/src/components/__tests__/ToolsTab.test.tsx +++ b/client/src/components/__tests__/ToolsTab.test.tsx @@ -71,7 +71,7 @@ describe("ToolsTab", () => { // Switch to second tool rerender( - + , ); @@ -82,25 +82,24 @@ describe("ToolsTab", () => { it("should handle integer type inputs", () => { renderToolsTab({ - selectedTool: mockTools[2], + selectedTool: mockTools[1], // Use the tool with integer type }); // Verify input is rendered as a number input const input = screen.getByRole("spinbutton") as HTMLInputElement; - expect(input.type).toBe("text"); // This will fail - should be "number" + expect(input.type).toBe("number"); // Integer type should be treated as number // Enter an integer value fireEvent.change(input, { target: { value: "42" } }); expect(input.value).toBe("42"); // Verify the callTool function receives the value as a number - const submitButton = screen.getByRole("button", { name: /submit/i }); + const submitButton = screen.getByRole("button", { name: /run tool/i }); fireEvent.click(submitButton); expect(defaultProps.callTool).toHaveBeenCalledWith( - mockTools[2].name, - { count: 42 }, // Should be number 42, not string "42" - expect.any(Function) + mockTools[1].name, + { count: 42 } ); }); }); From 7753b275e57987b62b4fe1b791b49e8848f2986b Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Mon, 31 Mar 2025 08:04:53 -0700 Subject: [PATCH 3/6] Update test to fail more explicitly --- client/src/components/__tests__/ToolsTab.test.tsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/client/src/components/__tests__/ToolsTab.test.tsx b/client/src/components/__tests__/ToolsTab.test.tsx index b36085e..624a72e 100644 --- a/client/src/components/__tests__/ToolsTab.test.tsx +++ b/client/src/components/__tests__/ToolsTab.test.tsx @@ -85,15 +85,11 @@ describe("ToolsTab", () => { selectedTool: mockTools[1], // Use the tool with integer type }); - // Verify input is rendered as a number input - const input = screen.getByRole("spinbutton") as HTMLInputElement; - expect(input.type).toBe("number"); // Integer type should be treated as number - - // Enter an integer value + const input = screen.getByRole("textbox", { name: /count/i }) as HTMLInputElement; + expect(input).toHaveProperty("type", "number"); fireEvent.change(input, { target: { value: "42" } }); expect(input.value).toBe("42"); - // Verify the callTool function receives the value as a number const submitButton = screen.getByRole("button", { name: /run tool/i }); fireEvent.click(submitButton); From 180760c4db647b5c4ad8dc53af5f95d297b5c1f9 Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Mon, 31 Mar 2025 09:16:25 -0700 Subject: [PATCH 4/6] Fix formatting --- client/src/components/__tests__/ToolsTab.test.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/src/components/__tests__/ToolsTab.test.tsx b/client/src/components/__tests__/ToolsTab.test.tsx index 624a72e..27e273c 100644 --- a/client/src/components/__tests__/ToolsTab.test.tsx +++ b/client/src/components/__tests__/ToolsTab.test.tsx @@ -85,17 +85,18 @@ describe("ToolsTab", () => { selectedTool: mockTools[1], // Use the tool with integer type }); - const input = screen.getByRole("textbox", { name: /count/i }) as HTMLInputElement; + const input = screen.getByRole("textbox", { + name: /count/i, + }) as HTMLInputElement; expect(input).toHaveProperty("type", "number"); fireEvent.change(input, { target: { value: "42" } }); expect(input.value).toBe("42"); const submitButton = screen.getByRole("button", { name: /run tool/i }); fireEvent.click(submitButton); - - expect(defaultProps.callTool).toHaveBeenCalledWith( - mockTools[1].name, - { count: 42 } - ); + + expect(defaultProps.callTool).toHaveBeenCalledWith(mockTools[1].name, { + count: 42, + }); }); }); From b82c74458357ada6f927ecf1d7385f61cd6e3be0 Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Tue, 1 Apr 2025 06:50:23 -0700 Subject: [PATCH 5/6] Use actual rendered element spinbutton in test --- client/src/components/__tests__/ToolsTab.test.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/src/components/__tests__/ToolsTab.test.tsx b/client/src/components/__tests__/ToolsTab.test.tsx index 27e273c..07aa52d 100644 --- a/client/src/components/__tests__/ToolsTab.test.tsx +++ b/client/src/components/__tests__/ToolsTab.test.tsx @@ -85,9 +85,7 @@ describe("ToolsTab", () => { selectedTool: mockTools[1], // Use the tool with integer type }); - const input = screen.getByRole("textbox", { - name: /count/i, - }) as HTMLInputElement; + const input = screen.getByRole("spinbutton", { name: /count/i }) as HTMLInputElement; expect(input).toHaveProperty("type", "number"); fireEvent.change(input, { target: { value: "42" } }); expect(input.value).toBe("42"); From 93c9c74dc95b859f18360f3efcaae82a08e647ea Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Tue, 1 Apr 2025 06:59:50 -0700 Subject: [PATCH 6/6] Fix formatting --- client/src/components/__tests__/ToolsTab.test.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/components/__tests__/ToolsTab.test.tsx b/client/src/components/__tests__/ToolsTab.test.tsx index 07aa52d..89ad603 100644 --- a/client/src/components/__tests__/ToolsTab.test.tsx +++ b/client/src/components/__tests__/ToolsTab.test.tsx @@ -85,7 +85,9 @@ describe("ToolsTab", () => { selectedTool: mockTools[1], // Use the tool with integer type }); - const input = screen.getByRole("spinbutton", { name: /count/i }) as HTMLInputElement; + const input = screen.getByRole("spinbutton", { + name: /count/i, + }) as HTMLInputElement; expect(input).toHaveProperty("type", "number"); fireEvent.change(input, { target: { value: "42" } }); expect(input.value).toBe("42");