/** @jest-environment jsdom */ import { h } from 'preact'; import { fireEvent, render, screen } from '@testing-library/preact'; import { Modal, ModalContent, ModalFooter, } from 'js/components/Modal'; describe('Modal', () => { it('renders a title and content when open', () => { render( My Content ); expect(screen.queryByRole('banner')).toBeVisible(); expect(screen.queryByRole('banner')).toHaveTextContent('My Title'); expect(screen.queryByText('My Content')).toBeVisible(); expect(screen.queryByRole('img')).not.toBeInTheDocument(); expect(screen.queryByTitle('Close')).not.toBeInTheDocument(); }); it('does not render a title and content when not open', () => { render( My Content ); expect(screen.queryByRole('banner')).not.toBeInTheDocument(); expect(screen.queryByText('My Content')).not.toBeInTheDocument(); }); it('renders a footer', () => { render( My Content My Footer ); expect(screen.queryByRole('banner')).toHaveTextContent('My Title'); expect(screen.queryByText('My Content')).toBeVisible(); expect(screen.getByRole('contentinfo')).toHaveTextContent('My Footer'); }); it('can have a close button', () => { const onClose = jest.fn(); render( My Content ); const button = screen.getByTitle('Close'); expect(button).toBeVisible(); fireEvent.click(button); expect(onClose).toHaveBeenCalledWith(true); }); it('can have an icon', () => { render( My Content ); expect(screen.getByRole('img')).toBeVisible(); }); });