File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -648,5 +648,31 @@ describe('Keyboard interactions', () => {
648648 // Subtree should no longer be visible
649649 expect ( queryByRole ( 'group' ) ) . not . toBeInTheDocument ( )
650650 } )
651+
652+ it ( 'navigates to href if provided' , ( ) => {
653+ const windowSpy = jest . spyOn ( window , 'open' )
654+ const onSelect = jest . fn ( )
655+ const { getByRole} = renderWithTheme (
656+ < TreeView aria-label = "Test tree" >
657+ < TreeView . LinkItem href = "#" onSelect = { onSelect } >
658+ Item
659+ </ TreeView . LinkItem >
660+ </ TreeView >
661+ )
662+
663+ const root = getByRole ( 'tree' )
664+
665+ // Focus tree
666+ root . focus ( )
667+
668+ // Press Enter
669+ fireEvent . keyDown ( document . activeElement || document . body , { key : 'Enter' } )
670+
671+ // window.open should have been called
672+ expect ( windowSpy ) . toHaveBeenCalledWith ( '#' , '_self' )
673+
674+ // onSelect should have been called
675+ expect ( onSelect ) . toHaveBeenCalledTimes ( 1 )
676+ } )
651677 } )
652678} )
You can’t perform that action at this time.
0 commit comments