Skip to content

Commit 834eb0c

Browse files
add Sidebar tests
1 parent 9e1186f commit 834eb0c

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

client/src/components/Sidebar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ const Sidebar = ({
318318
{typeof configItem.value === "number" ? (
319319
<Input
320320
type="number"
321+
data-testid={`${configKey}-input`}
321322
value={configItem.value}
322323
onChange={(e) => {
323324
const newConfig = { ...config };
@@ -331,6 +332,7 @@ const Sidebar = ({
331332
/>
332333
) : typeof configItem.value === "boolean" ? (
333334
<Select
335+
data-testid={`${configKey}-select`}
334336
value={configItem.value.toString()}
335337
onValueChange={(val) => {
336338
const newConfig = { ...config };
@@ -351,6 +353,7 @@ const Sidebar = ({
351353
</Select>
352354
) : (
353355
<Input
356+
data-testid={`${configKey}-input`}
354357
value={configItem.value}
355358
onChange={(e) => {
356359
const newConfig = { ...config };

client/src/components/__tests__/Sidebar.test.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { render, screen, fireEvent } from "@testing-library/react";
22
import { describe, it, beforeEach, jest } from "@jest/globals";
33
import Sidebar from "../Sidebar";
4+
import { DEFAULT_INSPECTOR_CONFIG } from "../../lib/constants";
5+
import { InspectorConfig } from "../../lib/configurationTypes";
46

57
// Mock theme hook
68
jest.mock("../../lib/useTheme", () => ({
@@ -28,6 +30,8 @@ describe("Sidebar Environment Variables", () => {
2830
logLevel: "info" as const,
2931
sendLogLevelRequest: jest.fn(),
3032
loggingSupported: true,
33+
config: DEFAULT_INSPECTOR_CONFIG,
34+
setConfig: jest.fn(),
3135
};
3236

3337
const renderSidebar = (props = {}) => {
@@ -304,4 +308,74 @@ describe("Sidebar Environment Variables", () => {
304308
expect(setEnv).toHaveBeenCalledWith({ [longKey]: "test_value" });
305309
});
306310
});
311+
312+
describe("Configuration Operations", () => {
313+
const openConfigSection = () => {
314+
const button = screen.getByText("Configuration");
315+
fireEvent.click(button);
316+
};
317+
318+
it("should update MCP server request timeout", () => {
319+
const setConfig = jest.fn();
320+
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
321+
322+
openConfigSection();
323+
324+
const timeoutInput = screen.getByTestId("MCP_SERVER_REQUEST_TIMEOUT-input");
325+
fireEvent.change(timeoutInput, { target: { value: "5000" } });
326+
327+
expect(setConfig).toHaveBeenCalledWith({
328+
MCP_SERVER_REQUEST_TIMEOUT: {
329+
description: "Timeout for requests to the MCP server (ms)",
330+
value: 5000,
331+
},
332+
});
333+
});
334+
335+
it("should handle invalid timeout values entered by user", () => {
336+
const setConfig = jest.fn();
337+
renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
338+
339+
openConfigSection();
340+
341+
const timeoutInput = screen.getByTestId("MCP_SERVER_REQUEST_TIMEOUT-input");
342+
fireEvent.change(timeoutInput, { target: { value: "abc1" } });
343+
344+
expect(setConfig).toHaveBeenCalledWith({
345+
MCP_SERVER_REQUEST_TIMEOUT: {
346+
description: "Timeout for requests to the MCP server (ms)",
347+
value: 0,
348+
},
349+
});
350+
});
351+
352+
it("should maintain configuration state after multiple updates", () => {
353+
const setConfig = jest.fn();
354+
const { rerender } = renderSidebar({ config: DEFAULT_INSPECTOR_CONFIG, setConfig });
355+
356+
openConfigSection();
357+
358+
// First update
359+
const timeoutInput = screen.getByTestId("MCP_SERVER_REQUEST_TIMEOUT-input");
360+
fireEvent.change(timeoutInput, { target: { value: "5000" } });
361+
362+
// Get the updated config from the first setConfig call
363+
const updatedConfig = setConfig.mock.calls[0][0] as InspectorConfig;
364+
365+
// Rerender with the updated config
366+
rerender(<Sidebar {...defaultProps} config={updatedConfig} setConfig={setConfig} />);
367+
368+
// Second update
369+
const updatedTimeoutInput = screen.getByTestId("MCP_SERVER_REQUEST_TIMEOUT-input");
370+
fireEvent.change(updatedTimeoutInput, { target: { value: "3000" } });
371+
372+
// Verify the final state matches what we expect
373+
expect(setConfig).toHaveBeenLastCalledWith({
374+
MCP_SERVER_REQUEST_TIMEOUT: {
375+
description: "Timeout for requests to the MCP server (ms)",
376+
value: 3000,
377+
},
378+
});
379+
});
380+
});
307381
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"scripts": {
2424
"dev": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev\"",
2525
"dev:windows": "concurrently \"cd client && npm run dev\" \"cd server && npm run dev:windows",
26+
"test": "cd client && npm test",
2627
"build-server": "cd server && npm run build",
2728
"build-client": "cd client && npm run build",
2829
"build": "npm run build-server && npm run build-client",

0 commit comments

Comments
 (0)