/* eslint-disable jest/require-top-level-describe */ import { render } from '@testing-library/react'; import React from 'react'; import { ModalFocus } from './modal-focus'; describe('ModalFocus', () => { it('should render with children inside the ModalFocus', () => { const { getByText } = render(
modal focus
, ); expect(getByText('modal focus')).toBeDefined(); }); it('should render with the initial element focused', () => { const { getByTestId } = render( , ); expect(getByTestId('input')).toHaveFocus(); }); it('should render with focused with autoFocus is set to false', () => { const { getByTestId } = render( , ); expect(getByTestId('input')).not.toHaveFocus(); }); it('should focus initialFocusRef on render', () => { const ref: React.RefObject = React.createRef(); const { getByTestId } = render( , ); expect(getByTestId('input')).toHaveFocus(); }); it('should focus final focus ref when closed', () => { const finalRef: React.RefObject = React.createRef(); const { rerender, getByRole } = render( <>
modal focus
, ); expect(finalRef.current).not.toHaveFocus(); rerender(); expect(getByRole('button')).toHaveFocus(); }); });