UNPKG

@wonderflow/react-components

Version:

UI components from Wonderflow's Wanda design system

28 lines (27 loc) 1.5 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { fireEvent, render, waitFor } from '@testing-library/react'; import { Autocomplete } from './autocomplete'; describe('<Autocomplete>', () => { test(' it should render properly', () => { const { container } = render(_jsx(Autocomplete, {})); expect(container).not.toBeNull(); }); test(' it should change properly', async () => { const { container, getByTestId } = render(_jsxs(Autocomplete, { children: [_jsx(Autocomplete.Option, { value: "1", children: "Option 1" }), _jsx(Autocomplete.Option, { value: "2", children: "Option 2" }), _jsx(Autocomplete.Option, { value: "3", children: "Option 3" })] })); const el = getByTestId('Autocomplete'); fireEvent.focus(el); fireEvent.change(el, { target: { value: 'Option 3' } }); fireEvent.blur(el); expect(container).not.toBeNull(); }); test(' it should render properly with props', async () => { const { container, getByTestId } = render(_jsx(Autocomplete, { children: _jsx(Autocomplete.Option, { value: "1", children: "Option 1" }) })); const el = getByTestId('Autocomplete'); fireEvent.focus(el); await waitFor(() => expect(getByTestId('AutocompleteOption')).toBeDefined()); const elOpt = getByTestId('AutocompleteOption'); fireEvent.click(elOpt); fireEvent.keyPress(el, { key: 'esc' }); expect(container).not.toBeNull(); }); });