import React from 'react'; import { render, screen } from '@testing-library/react'; import { Modal } from '../modal'; describe('Modal Component', () => { it('should render as expected when modal is true', () => { const closeFn = jest.fn(); const { getByText } = render( This modal is so cool! ); expect(getByText('This modal is so cool!')).toBeTruthy(); }); it('should render as expected when modal is false', () => { const closeFn = jest.fn(); render( This modal is so cool! ); const text = screen.queryByText('This modal is so cool!'); expect(text).not.toBeInTheDocument(); }); it('should have portalId', () => { const portalId = 'example-modal'; const closeFn = jest.fn(); render( This modal is so cool! ); const element = document.getElementById(portalId); expect(element.getAttribute('id')).toBe(portalId); }); it('has given class names', () => { const closeFn = jest.fn(); render( This modal is so cool! ); const section = document.querySelector('section'); expect(section).toHaveClass('accent-primary'); }); it('should have title', () => { const closeFn = jest.fn(); render( This modal is so cool! ); const title = document.querySelector('h3'); expect(title).toHaveTextContent('Example Title'); }); it('should have close button', () => { const closeFn = jest.fn(); render( This modal is so cool! ); const button = document.querySelector('use'); expect(button.getAttribute('xlink:href')).toBe('/icon-sprite.svg#close'); }); });