mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-02 09:15:22 +03:00
fix: added a test for the prompt and refactored the dialog test
This commit is contained in:
parent
0c50c71b57
commit
0c07eccbd1
@ -16,23 +16,8 @@ describe('Dialog', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('renders to a portal', async () => {
|
test('renders to a portal', async () => {
|
||||||
render(<Dialog title="Tacos" text="This is the dialog" />);
|
render(<Dialog>Sample</Dialog>);
|
||||||
expect(screen.getByText('Tacos')).toBeInTheDocument();
|
expect(screen.getByText('Sample')).toBeInTheDocument();
|
||||||
expect(screen.getByRole('modal').closest('#dialogs')).not.toBeNull();
|
expect(screen.getByRole('modal').closest('#dialogs')).not.toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('renders action buttons', async () => {
|
|
||||||
const handleClick = jest.fn();
|
|
||||||
render(
|
|
||||||
<Dialog
|
|
||||||
actions={[
|
|
||||||
{ color: 'red', text: 'Delete' },
|
|
||||||
{ text: 'Okay', onClick: handleClick },
|
|
||||||
]}
|
|
||||||
title="Tacos"
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
fireEvent.click(screen.getByRole('button', { name: 'Okay' }));
|
|
||||||
expect(handleClick).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
38
web/src/components/__tests__/Prompt.test.jsx
Normal file
38
web/src/components/__tests__/Prompt.test.jsx
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { h } from 'preact';
|
||||||
|
import Prompt from '../Prompt';
|
||||||
|
import { fireEvent, render, screen } from '@testing-library/preact';
|
||||||
|
|
||||||
|
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 () => {
|
||||||
|
render(<Prompt title='Tacos' text='This is the dialog' />);
|
||||||
|
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 },
|
||||||
|
]}
|
||||||
|
title='Tacos'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: 'Okay' }));
|
||||||
|
expect(handleClick).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user