forked from alan2207/bulletproof-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfirmationDialog.test.tsx
35 lines (25 loc) · 1.11 KB
/
ConfirmationDialog.test.tsx
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
import { rtlRender, screen, userEvent, waitFor } from '@/test/test-utils';
import { Button } from '../../Button';
import { ConfirmationDialog } from '../ConfirmationDialog';
test('should handle confirmation flow', async () => {
const titleText = 'Are you sure?';
const bodyText = 'Are you sure you want to delete this item?';
const confirmationButtonText = 'Confirm';
const openButtonText = 'Open';
await rtlRender(
<ConfirmationDialog
icon="danger"
title={titleText}
body={bodyText}
confirmButton={<Button>{confirmationButtonText}</Button>}
triggerButton={<Button>{openButtonText}</Button>}
/>
);
expect(screen.queryByText(titleText)).not.toBeInTheDocument();
userEvent.click(screen.getByRole('button', { name: openButtonText }));
expect(screen.getByText(titleText)).toBeInTheDocument();
expect(screen.getByText(bodyText)).toBeInTheDocument();
userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
await waitFor(() => expect(screen.queryByText(titleText)).not.toBeInTheDocument());
expect(screen.queryByText(bodyText)).not.toBeInTheDocument();
});