-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathErrorDialog.test.jsx
More file actions
44 lines (35 loc) · 1.29 KB
/
ErrorDialog.test.jsx
File metadata and controls
44 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { render, screen } from '@tests/utils/test-utils';
import userEvent from '@testing-library/user-event';
import { ErrorDialog } from '../../../src/components/ErrorDialog';
/**
* Helper function to create a shallow wrapper around ErrorDialog
*/
function createWrapper(props) {
return render(
<ErrorDialog
{...props}
/>,
);
}
describe('ErrorDialog', () => {
it('renders properly', () => {
const error = { id: 'testid123', message: '' };
createWrapper({ error });
expect(screen.getByRole('dialog')).toBeInTheDocument();
expect(screen.getByRole('heading')).toHaveTextContent('An error occurred');
});
it('shows up error message correctly', () => {
const errorMessage = 'error testMessage 123';
const error = { id: 'testid123', message: errorMessage };
createWrapper({ error });
expect(screen.getByRole('dialog')).toHaveTextContent(errorMessage);
});
it('triggers the handleClick prop when clicking the ok button', async () => {
const error = { id: 'testid123', message: '' };
const mockHandleClick = vi.fn();
const user = userEvent.setup();
createWrapper({ error, removeError: mockHandleClick });
await user.click(screen.getByRole('button', { name: 'OK' }));
expect(mockHandleClick).toHaveBeenCalledTimes(1);
});
});