frigate/web/src/components/__tests__/Prompt.test.jsx

39 lines
1005 B
React
Raw Normal View History

2022-02-27 17:04:12 +03:00
import { h } from 'preact';
import Prompt from '../Prompt';
2022-03-06 07:16:31 +03:00
import { fireEvent, render, screen } from 'testing-library';
2022-02-27 17:04:12 +03:00
describe('Prompt', () => {
let portal;
beforeAll(() => {
portal = document.createElement('div');
portal.id = 'dialogs';
document.body.appendChild(portal);
});
afterAll(() => {
document.body.removeChild(portal);
});
test('renders to a portal', async () => {
2022-03-06 07:16:31 +03:00
render(<Prompt title="Tacos" text="This is the dialog" />);
2022-02-27 17:04:12 +03:00
expect(screen.getByText('Tacos')).toBeInTheDocument();
expect(screen.getByRole('modal').closest('#dialogs')).not.toBeNull();
});
test('renders action buttons', async () => {
const handleClick = jest.fn();
render(
<Prompt
actions={[
{ color: 'red', text: 'Delete' },
{ text: 'Okay', onClick: handleClick },
]}
2022-03-06 07:16:31 +03:00
title="Tacos"
2022-02-27 17:04:12 +03:00
/>
);
fireEvent.click(screen.getByRole('button', { name: 'Okay' }));
expect(handleClick).toHaveBeenCalled();
});
});