diff --git a/web/src/components/__tests__/Select.test.jsx b/web/src/components/__tests__/Select.test.jsx new file mode 100644 index 000000000..5425025cf --- /dev/null +++ b/web/src/components/__tests__/Select.test.jsx @@ -0,0 +1,34 @@ +import { h } from 'preact'; +import Select from '../Select'; +import { fireEvent, render, screen } from '@testing-library/preact'; + +describe('Select', () => { + test('on focus, shows a menu', async () => { + const handleChange = jest.fn(); + render(); + + expect(screen.queryByRole('listbox')).not.toBeInTheDocument(); + const input = screen.getByRole('textbox'); + fireEvent.focus(input); + fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' }); + expect(screen.queryByRole('listbox')).toBeInTheDocument(); + + fireEvent.keyDown(input, { key: 'ArrowDown', code: 'ArrowDown' }); + fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' }); + expect(handleChange).toHaveBeenCalledWith('burritos', 'burritos'); + }); +});