Skip to content

Commit 13473b2

Browse files
committed
Add test for link item
1 parent d1f2945 commit 13473b2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/TreeView/TreeView.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)