/* eslint-disable jest/require-top-level-describe */
import { render, fireEvent } from '@testing-library/react';
import React from 'react';
import { Modal } from './modal';
describe('Modal', () => {
const onClose = jest.fn();
beforeEach(() => {
onClose.mockClear();
});
it('should render the Modal without crashing', () => {
const { getByText, getByTestId } = render(
modal content
,
);
expect(getByText('modal content')).toBeDefined();
expect(getByTestId('modal')).toHaveClass('mm-modal');
});
it('should match snapshot', () => {
const { getByTestId } = render(
modal content
,
);
expect(getByTestId('test')).toMatchSnapshot();
});
it('should render with and additional className', () => {
const { getByTestId } = render(
modal content
,
);
expect(getByTestId('modal')).toHaveClass('mm-modal test-class');
});
it('should render the modal when isOpen is true', () => {
const { getByText } = render(
modal content
,
);
const modalContent = getByText('modal content');
expect(modalContent).toBeInTheDocument();
});
it('should not render the modal when isOpen is false', () => {
const { queryByText } = render(
modal content
,
);
const modalContent = queryByText('modal content');
expect(modalContent).not.toBeInTheDocument();
});
it('should call the onClose callback when clicking the close button', () => {
const { getByText } = render(
modal content
,
);
const closeButton = getByText('Close');
fireEvent.click(closeButton);
expect(onClose).toHaveBeenCalledTimes(1);
});
});