|
1 | 1 | import * as React from 'react'; |
2 | | -import { render, fireEvent } from '@testing-library/react'; |
| 2 | + |
| 3 | +import { userEvent } from '@testing-library/user-event'; |
| 4 | +import { render, screen } from '../../../test-utils/testing-library'; |
3 | 5 | import SidebarNavSign from '../SidebarNavSign'; |
4 | | -// @ts-ignore Module is written in Flow |
5 | | -import FeatureProvider from '../../common/feature-checking/FeatureProvider'; |
6 | 6 |
|
7 | 7 | describe('elements/content-sidebar/SidebarNavSign', () => { |
8 | 8 | const onClickRequestSignature = jest.fn(); |
9 | 9 | const onClickSignMyself = jest.fn(); |
10 | 10 |
|
11 | 11 | const renderComponent = (props = {}, features = {}) => |
12 | | - render( |
13 | | - <FeatureProvider features={features}> |
14 | | - <SidebarNavSign {...props} /> |
15 | | - </FeatureProvider>, |
16 | | - ); |
| 12 | + render(<SidebarNavSign {...props} />, { |
| 13 | + wrapperProps: { features }, |
| 14 | + }); |
17 | 15 |
|
18 | | - test.each([true, false])('should render sign button', isRemoveInterstitialEnabled => { |
19 | | - const features = { |
20 | | - boxSign: { |
21 | | - isSignRemoveInterstitialEnabled: isRemoveInterstitialEnabled, |
22 | | - }, |
23 | | - }; |
| 16 | + test('should render sign button', async () => { |
| 17 | + renderComponent(); |
24 | 18 |
|
25 | | - const wrapper = renderComponent({}, features); |
26 | | - expect(wrapper.getByTestId('sign-button')).toBeVisible(); |
| 19 | + expect(screen.getByRole('button', { name: 'Request Signature' })).toBeVisible(); |
27 | 20 | }); |
28 | 21 |
|
29 | | - test('should call correct handler when sign button is clicked', () => { |
30 | | - const features = { |
31 | | - boxSign: { |
32 | | - isSignRemoveInterstitialEnabled: false, |
33 | | - onClick: onClickRequestSignature, |
34 | | - }, |
35 | | - }; |
36 | | - const { getByTestId } = renderComponent({}, features); |
37 | | - |
38 | | - fireEvent.click(getByTestId('sign-button')); |
| 22 | + test('should open dropdown with 2 menu items when sign button is clicked', async () => { |
| 23 | + renderComponent(); |
39 | 24 |
|
40 | | - expect(onClickRequestSignature).toBeCalled(); |
41 | | - }); |
| 25 | + await userEvent.click(screen.getByRole('button', { name: 'Request Signature' })); |
42 | 26 |
|
43 | | - test('should open dropdown with 2 menu items when sign button is clicked', () => { |
44 | | - const features = { |
45 | | - boxSign: { |
46 | | - isSignRemoveInterstitialEnabled: true, |
47 | | - }, |
48 | | - }; |
49 | | - const { getByTestId } = renderComponent({}, features); |
50 | | - fireEvent.click(getByTestId('sign-button')); |
51 | | - expect(getByTestId('sign-request-signature-button')).toBeVisible(); |
52 | | - expect(getByTestId('sign-sign-myself-button')).toBeVisible(); |
| 27 | + expect(screen.getByText('Request Signature')).toBeVisible(); |
| 28 | + expect(screen.getByText('Sign Myself')).toBeVisible(); |
53 | 29 | }); |
54 | 30 |
|
55 | | - test('should call correct handler when request signature option is clicked', () => { |
| 31 | + test('should call correct handler when request signature option is clicked', async () => { |
56 | 32 | const features = { |
57 | 33 | boxSign: { |
58 | | - isSignRemoveInterstitialEnabled: true, |
59 | 34 | onClick: onClickRequestSignature, |
60 | 35 | }, |
61 | 36 | }; |
62 | | - const { getByTestId } = renderComponent({}, features); |
63 | | - fireEvent.click(getByTestId('sign-button')); |
64 | | - fireEvent.click(getByTestId('sign-request-signature-button')); |
65 | | - expect(onClickRequestSignature).toBeCalled(); |
| 37 | + renderComponent({}, features); |
| 38 | + |
| 39 | + await userEvent.click(screen.getByRole('button', { name: 'Request Signature' })); |
| 40 | + await userEvent.click(screen.getByText('Request Signature')); |
| 41 | + |
| 42 | + expect(onClickRequestSignature).toHaveBeenCalled(); |
66 | 43 | }); |
67 | 44 |
|
68 | | - test('should call correct handler when sign myself option is clicked', () => { |
| 45 | + test('should call correct handler when sign myself option is clicked', async () => { |
69 | 46 | const features = { |
70 | 47 | boxSign: { |
71 | | - isSignRemoveInterstitialEnabled: true, |
72 | 48 | onClickSignMyself, |
73 | 49 | }, |
74 | 50 | }; |
75 | | - const { getByTestId } = renderComponent({}, features); |
76 | | - fireEvent.click(getByTestId('sign-button')); |
77 | | - fireEvent.click(getByTestId('sign-sign-myself-button')); |
78 | | - expect(onClickSignMyself).toBeCalled(); |
| 51 | + renderComponent({}, features); |
| 52 | + |
| 53 | + await userEvent.click(screen.getByRole('button', { name: 'Request Signature' })); |
| 54 | + await userEvent.click(screen.getByText('Sign Myself')); |
| 55 | + |
| 56 | + expect(onClickSignMyself).toHaveBeenCalled(); |
79 | 57 | }); |
80 | 58 | }); |
0 commit comments