import React, { useState } from 'react';
import { screen, waitForElementToBeRemoved } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { Button } from '../Button';
import { renderWithGrapesProvider } from '../../test-utils/renderers';
import { PageModal } from './';
describe('PageModal component', () => {
it('should display a page modal with content', async () => {
const Container = () => {
const [open, setOpen] = useState(false);
return (
);
};
renderWithGrapesProvider();
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
await userEvent.click(screen.getByRole('button', { name: 'Open' }));
expect(await screen.findByRole('dialog', { name: 'Title' })).toBeVisible();
expect(screen.getByText('Content')).toBeVisible();
await userEvent.click(screen.getByRole('button', { name: 'Close' }));
await waitForElementToBeRemoved(screen.getByRole('dialog'));
});
it('should support additional accessibility attributs', () => {
const descriptionId = 'dialog-description';
renderWithGrapesProvider(
Content
,
);
expect(screen.getByRole('dialog', { name: 'Title' })).toBeVisible();
expect(
screen.getByRole('dialog', { name: 'Title' }),
).toHaveAccessibleDescription('Content');
});
describe('given a className property is provided', () => {
it("adds it to the component's classnames", () => {
renderWithGrapesProvider(
Content
,
);
expect(screen.getByRole('dialog', { name: 'Title' })).toHaveClass(
'MyPageModal',
);
});
});
});