@@ -55,6 +55,8 @@ describe("ToolsTab", () => {
5555 toolResult : null ,
5656 nextCursor : "" ,
5757 error : null ,
58+ resourceContent : { } ,
59+ onReadResource : jest . fn ( ) ,
5860 } ;
5961
6062 const renderToolsTab = ( props = { } ) => {
@@ -383,27 +385,101 @@ describe("ToolsTab", () => {
383385 } ) ;
384386
385387 describe ( "Resource Link Content Type" , ( ) => {
386- it ( "should render resource_link content type" , ( ) => {
388+ it ( "should render resource_link content type and handle expansion" , async ( ) => {
389+ const mockOnReadResource = jest . fn ( ) ;
390+ const resourceContent = {
391+ "test://static/resource/1" : JSON . stringify ( {
392+ contents : [
393+ {
394+ uri : "test://static/resource/1" ,
395+ name : "Resource 1" ,
396+ mimeType : "text/plain" ,
397+ text : "Resource 1: This is a plaintext resource" ,
398+ } ,
399+ ] ,
400+ } ) ,
401+ } ;
402+
387403 const result = {
388404 content : [
389405 {
390406 type : "resource_link" ,
391- uri : "https://example.com/resource" ,
392- name : "Test Resource" ,
393- description : "A test resource" ,
394- mimeType : "application/json" ,
407+ uri : "test://static/resource/1" ,
408+ name : "Resource 1" ,
409+ description : "Resource 1: plaintext resource" ,
410+ mimeType : "text/plain" ,
411+ } ,
412+ {
413+ type : "resource_link" ,
414+ uri : "test://static/resource/2" ,
415+ name : "Resource 2" ,
416+ description : "Resource 2: binary blob resource" ,
417+ mimeType : "application/octet-stream" ,
418+ } ,
419+ {
420+ type : "resource_link" ,
421+ uri : "test://static/resource/3" ,
422+ name : "Resource 3" ,
423+ description : "Resource 3: plaintext resource" ,
424+ mimeType : "text/plain" ,
395425 } ,
396426 ] ,
397427 } ;
398428
399- renderToolsTab ( { selectedTool : mockTools [ 0 ] , toolResult : result } ) ;
429+ renderToolsTab ( {
430+ selectedTool : mockTools [ 0 ] ,
431+ toolResult : result ,
432+ resourceContent,
433+ onReadResource : mockOnReadResource ,
434+ } ) ;
400435
401- expect (
402- screen . getByText ( "https://example.com/resource" ) ,
403- ) . toBeInTheDocument ( ) ;
404- expect ( screen . getByText ( "Test Resource" ) ) . toBeInTheDocument ( ) ;
405- expect ( screen . getByText ( "A test resource" ) ) . toBeInTheDocument ( ) ;
406- expect ( screen . getByText ( "application/json" ) ) . toBeInTheDocument ( ) ;
436+ [ "1" , "2" , "3" ] . forEach ( ( id ) => {
437+ expect (
438+ screen . getByText ( `test://static/resource/${ id } ` ) ,
439+ ) . toBeInTheDocument ( ) ;
440+ expect ( screen . getByText ( `Resource ${ id } ` ) ) . toBeInTheDocument ( ) ;
441+ } ) ;
442+
443+ expect ( screen . getAllByText ( "text/plain" ) ) . toHaveLength ( 2 ) ;
444+ expect ( screen . getByText ( "application/octet-stream" ) ) . toBeInTheDocument ( ) ;
445+
446+ const expandButtons = screen . getAllByRole ( "button" , {
447+ name : / e x p a n d r e s o u r c e / i,
448+ } ) ;
449+ expect ( expandButtons ) . toHaveLength ( 3 ) ;
450+ expect ( screen . queryByText ( "Resource:" ) ) . not . toBeInTheDocument ( ) ;
451+
452+ expandButtons . forEach ( ( button ) => {
453+ expect ( button ) . toHaveAttribute ( "aria-expanded" , "false" ) ;
454+ } ) ;
455+
456+ const resource1Button = screen . getByRole ( "button" , {
457+ name : / e x p a n d r e s o u r c e t e s t : \/ \/ s t a t i c \/ r e s o u r c e \/ 1 / i,
458+ } ) ;
459+
460+ await act ( async ( ) => {
461+ fireEvent . click ( resource1Button ) ;
462+ } ) ;
463+
464+ expect ( mockOnReadResource ) . toHaveBeenCalledWith (
465+ "test://static/resource/1" ,
466+ ) ;
467+ expect ( screen . getByText ( "Resource:" ) ) . toBeInTheDocument ( ) ;
468+ expect ( document . body ) . toHaveTextContent ( "contents:" ) ;
469+ expect ( document . body ) . toHaveTextContent ( 'uri:"test://static/resource/1"' ) ;
470+ expect ( resource1Button ) . toHaveAttribute ( "aria-expanded" , "true" ) ;
471+
472+ await act ( async ( ) => {
473+ fireEvent . click ( resource1Button ) ;
474+ } ) ;
475+
476+ expect ( screen . queryByText ( "Resource:" ) ) . not . toBeInTheDocument ( ) ;
477+ expect ( document . body ) . not . toHaveTextContent ( "contents:" ) ;
478+ expect ( document . body ) . not . toHaveTextContent (
479+ 'uri:"test://static/resource/1"' ,
480+ ) ;
481+ expect ( resource1Button ) . toHaveAttribute ( "aria-expanded" , "false" ) ;
482+ expect ( mockOnReadResource ) . toHaveBeenCalledTimes ( 1 ) ;
407483 } ) ;
408484 } ) ;
409485} ) ;
0 commit comments