import { render } from '~/src/utils/test' import { AutoFocus } from './AutoFocus' import { type AutoFocusProps } from './AutoFocus.types' describe('AutoFocus', () => { const renderComponent = ({ children, ...rest }: AutoFocusProps) => render({children}) it('should focus on the child element - HTMLDivElement', () => { const { getByText } = renderComponent({ children:
Close
, }) const rendered = getByText('Close') expect(rendered).toHaveFocus() }) it('should focus on the child element - HTMLButtonElement', () => { const { getByRole } = renderComponent({ children: , }) const rendered = getByRole('button') expect(rendered).toHaveFocus() }) it('should focus on the child element - HTMLInputElement', () => { const { getByRole } = renderComponent({ children: , }) const rendered = getByRole('textbox') expect(rendered).toHaveFocus() }) it('should focus on the child element when the `when` condition prop is true', () => { const { getByText } = renderComponent({ when: true, children: , }) const rendered = getByText('Close') expect(rendered).toHaveFocus() }) it('should not focus on the child element when the `when` condition prop is false', () => { const { getByText } = renderComponent({ when: false, children: , }) const rendered = getByText('Close') expect(rendered).not.toHaveFocus() }) })