|
1 | 1 | import { render, screen, fireEvent } from "@testing-library/react";
|
2 | 2 | import { describe, it, beforeEach, jest } from "@jest/globals";
|
3 | 3 | import Sidebar from "../Sidebar";
|
| 4 | +import { DEFAULT_INSPECTOR_CONFIG } from "../../lib/constants"; |
| 5 | +import { InspectorConfig } from "../../lib/configurationTypes"; |
4 | 6 |
|
5 | 7 | // Mock theme hook
|
6 | 8 | jest.mock("../../lib/useTheme", () => ({
|
@@ -28,6 +30,8 @@ describe("Sidebar Environment Variables", () => {
|
28 | 30 | logLevel: "info" as const,
|
29 | 31 | sendLogLevelRequest: jest.fn(),
|
30 | 32 | loggingSupported: true,
|
| 33 | + config: DEFAULT_INSPECTOR_CONFIG, |
| 34 | + setConfig: jest.fn(), |
31 | 35 | };
|
32 | 36 |
|
33 | 37 | const renderSidebar = (props = {}) => {
|
@@ -304,4 +308,74 @@ describe("Sidebar Environment Variables", () => {
|
304 | 308 | expect(setEnv).toHaveBeenCalledWith({ [longKey]: "test_value" });
|
305 | 309 | });
|
306 | 310 | });
|
| 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 | + }); |
307 | 381 | });
|
0 commit comments