import { fireEvent } from '@testing-library/react'
import { act, renderHook } from '@testing-library/react-hooks'

import { useHotkey } from '../Hotkey'

describe('useHotkey', () => {
  it('binds key handlers', () => {
    const onSubmit = jest.fn()

    renderHook(() => useHotkey({ key: 'Enter', handler: onSubmit }))

    act(() => {
      fireEvent.keyDown(window, { key: 'Enter' })
      fireEvent.keyDown(window, { key: 'Enter' })
      expect(onSubmit).toHaveBeenCalledTimes(2)
    })
  })
})
