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
+ import { DEFAULT_INSPECTOR_CONFIG } from "@/lib/constants" ;
5
+ import { InspectorConfig } from "@/lib/configurationTypes" ;
6
+ import { TooltipProvider } from "@/components/ui/tooltip" ;
6
7
7
8
// Mock theme hook
8
9
jest . mock ( "../../lib/useTheme" , ( ) => ( {
@@ -36,11 +37,15 @@ describe("Sidebar Environment Variables", () => {
36
37
} ;
37
38
38
39
const renderSidebar = ( props = { } ) => {
39
- return render ( < Sidebar { ...defaultProps } { ...props } /> ) ;
40
+ return render (
41
+ < TooltipProvider >
42
+ < Sidebar { ...defaultProps } { ...props } />
43
+ </ TooltipProvider > ,
44
+ ) ;
40
45
} ;
41
46
42
47
const openEnvVarsSection = ( ) => {
43
- const button = screen . getByText ( "Environment Variables ") ;
48
+ const button = screen . getByTestId ( "env-vars-button ") ;
44
49
fireEvent . click ( button ) ;
45
50
} ;
46
51
@@ -216,7 +221,11 @@ describe("Sidebar Environment Variables", () => {
216
221
const updatedEnv = setEnv . mock . calls [ 0 ] [ 0 ] as Record < string , string > ;
217
222
218
223
// Rerender with the updated env
219
- rerender ( < Sidebar { ...defaultProps } env = { updatedEnv } setEnv = { setEnv } /> ) ;
224
+ rerender (
225
+ < TooltipProvider >
226
+ < Sidebar { ...defaultProps } env = { updatedEnv } setEnv = { setEnv } />
227
+ </ TooltipProvider > ,
228
+ ) ;
220
229
221
230
// Second key edit
222
231
const secondKeyInput = screen . getByDisplayValue ( "SECOND_KEY" ) ;
@@ -247,7 +256,11 @@ describe("Sidebar Environment Variables", () => {
247
256
fireEvent . change ( keyInput , { target : { value : "NEW_KEY" } } ) ;
248
257
249
258
// Rerender with updated env
250
- rerender ( < Sidebar { ...defaultProps } env = { { NEW_KEY : "test_value" } } /> ) ;
259
+ rerender (
260
+ < TooltipProvider >
261
+ < Sidebar { ...defaultProps } env = { { NEW_KEY : "test_value" } } />
262
+ </ TooltipProvider > ,
263
+ ) ;
251
264
252
265
// Value should still be visible
253
266
const updatedValueInput = screen . getByDisplayValue ( "test_value" ) ;
@@ -312,7 +325,7 @@ describe("Sidebar Environment Variables", () => {
312
325
313
326
describe ( "Configuration Operations" , ( ) => {
314
327
const openConfigSection = ( ) => {
315
- const button = screen . getByText ( "Configuration ") ;
328
+ const button = screen . getByTestId ( "config-button ") ;
316
329
fireEvent . click ( button ) ;
317
330
} ;
318
331
@@ -327,12 +340,14 @@ describe("Sidebar Environment Variables", () => {
327
340
) ;
328
341
fireEvent . change ( timeoutInput , { target : { value : "5000" } } ) ;
329
342
330
- expect ( setConfig ) . toHaveBeenCalledWith ( {
331
- MCP_SERVER_REQUEST_TIMEOUT : {
332
- description : "Timeout for requests to the MCP server (ms)" ,
333
- value : 5000 ,
334
- } ,
335
- } ) ;
343
+ expect ( setConfig ) . toHaveBeenCalledWith (
344
+ expect . objectContaining ( {
345
+ MCP_SERVER_REQUEST_TIMEOUT : {
346
+ description : "Timeout for requests to the MCP server (ms)" ,
347
+ value : 5000 ,
348
+ } ,
349
+ } ) ,
350
+ ) ;
336
351
} ) ;
337
352
338
353
it ( "should handle invalid timeout values entered by user" , ( ) => {
@@ -346,12 +361,14 @@ describe("Sidebar Environment Variables", () => {
346
361
) ;
347
362
fireEvent . change ( timeoutInput , { target : { value : "abc1" } } ) ;
348
363
349
- expect ( setConfig ) . toHaveBeenCalledWith ( {
350
- MCP_SERVER_REQUEST_TIMEOUT : {
351
- description : "Timeout for requests to the MCP server (ms)" ,
352
- value : 0 ,
353
- } ,
354
- } ) ;
364
+ expect ( setConfig ) . toHaveBeenCalledWith (
365
+ expect . objectContaining ( {
366
+ MCP_SERVER_REQUEST_TIMEOUT : {
367
+ description : "Timeout for requests to the MCP server (ms)" ,
368
+ value : 0 ,
369
+ } ,
370
+ } ) ,
371
+ ) ;
355
372
} ) ;
356
373
357
374
it ( "should maintain configuration state after multiple updates" , ( ) => {
@@ -362,7 +379,6 @@ describe("Sidebar Environment Variables", () => {
362
379
} ) ;
363
380
364
381
openConfigSection ( ) ;
365
-
366
382
// First update
367
383
const timeoutInput = screen . getByTestId (
368
384
"MCP_SERVER_REQUEST_TIMEOUT-input" ,
@@ -374,11 +390,13 @@ describe("Sidebar Environment Variables", () => {
374
390
375
391
// Rerender with the updated config
376
392
rerender (
377
- < Sidebar
378
- { ...defaultProps }
379
- config = { updatedConfig }
380
- setConfig = { setConfig }
381
- /> ,
393
+ < TooltipProvider >
394
+ < Sidebar
395
+ { ...defaultProps }
396
+ config = { updatedConfig }
397
+ setConfig = { setConfig }
398
+ />
399
+ </ TooltipProvider > ,
382
400
) ;
383
401
384
402
// Second update
@@ -388,12 +406,14 @@ describe("Sidebar Environment Variables", () => {
388
406
fireEvent . change ( updatedTimeoutInput , { target : { value : "3000" } } ) ;
389
407
390
408
// Verify the final state matches what we expect
391
- expect ( setConfig ) . toHaveBeenLastCalledWith ( {
392
- MCP_SERVER_REQUEST_TIMEOUT : {
393
- description : "Timeout for requests to the MCP server (ms)" ,
394
- value : 3000 ,
395
- } ,
396
- } ) ;
409
+ expect ( setConfig ) . toHaveBeenLastCalledWith (
410
+ expect . objectContaining ( {
411
+ MCP_SERVER_REQUEST_TIMEOUT : {
412
+ description : "Timeout for requests to the MCP server (ms)" ,
413
+ value : 3000 ,
414
+ } ,
415
+ } ) ,
416
+ ) ;
397
417
} ) ;
398
418
} ) ;
399
419
} ) ;
0 commit comments