import React from 'react'; import { fireEvent } from '@testing-library/react'; import renderWithTheme from '../../../testUtils/renderWithTheme'; import Modal from '../index'; const { PopUp: PopUpModal } = Modal; describe('rendering', () => { it('renders modal contents', () => { const { getByText } = renderWithTheme( ); expect(getByText('A title')).toBeInTheDocument(); expect(getByText('A body')).toBeInTheDocument(); expect(getByText('A footer')).toBeInTheDocument(); }); it('allows to control the visibility', () => { const { getByText } = renderWithTheme( ); expect(getByText('A title')).not.toBeVisible(); expect(getByText('A body')).not.toBeVisible(); expect(getByText('A footer')).not.toBeVisible(); }); it('allows to customise modal contents using react elements', () => { const { getByText } = renderWithTheme( Customised title} body={
Customised body
} footer={
Customised footer
} /> ); expect(getByText('Customised title')).toBeInTheDocument(); expect(getByText('Customised body')).toBeInTheDocument(); expect(getByText('Customised footer')).toBeInTheDocument(); }); }); describe('interaction', () => { it('allows to click on customised footer', () => { const onClick = jest.fn(); const { getByText } = renderWithTheme( onClick()}> Footer button } /> ); fireEvent.click(getByText('Footer button')); expect(onClick).toHaveBeenCalledTimes(1); }); });