Skip to content

Commit

Permalink
Add some missing tests for useKeyboardFocus hook
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpens committed Sep 25, 2024
1 parent 9fa43ed commit 18f0fc5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/react/src/common/useKeyboardFocus.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,30 @@ describe('use focus with arrows', () => {

expect(onFocusOneMock).toHaveBeenCalledTimes(6)
})

it('sets focus to first element when using "Home" key', () => {
const Component = getComponent()
const { container } = render(<Component />)

const firstChild = container.firstChild as HTMLElement

fireEvent.keyDown(firstChild, {
key: KeyboardKeys.Home,
})

expect(onFocusOneMock).toHaveBeenCalledTimes(1)
})

it('sets focus to last element when using "End" key', () => {
const Component = getComponent()
const { container } = render(<Component />)

const firstChild = container.firstChild as HTMLElement

fireEvent.keyDown(firstChild, {
key: KeyboardKeys.End,
})

expect(onFocusThreeMock).toHaveBeenCalledTimes(1)
})
})

0 comments on commit 18f0fc5

Please sign in to comment.