|
| 1 | +import React from 'react'; |
| 2 | +import { render, fireEvent } from '@testing-library/react'; |
| 3 | +import SidebarNavSign from '../SidebarNavSign'; |
| 4 | +// @ts-ignore Module is written in Flow |
| 5 | +import FeatureProvider from '../../common/feature-checking/FeatureProvider'; |
| 6 | + |
| 7 | +describe('elements/content-sidebar/SidebarNavSign', () => { |
| 8 | + const onClickRequestSignature = jest.fn(); |
| 9 | + const onClickSignMyself = jest.fn(); |
| 10 | + |
| 11 | + const renderComponent = (props = {}, features = {}) => |
| 12 | + render( |
| 13 | + <FeatureProvider features={features}> |
| 14 | + <SidebarNavSign {...props} /> |
| 15 | + </FeatureProvider>, |
| 16 | + ); |
| 17 | + |
| 18 | + test.each([true, false])('should render sign button', isRemoveInterstitialEnabled => { |
| 19 | + const features = { |
| 20 | + boxSign: { |
| 21 | + isSignRemoveInterstitialEnabled: isRemoveInterstitialEnabled, |
| 22 | + }, |
| 23 | + }; |
| 24 | + |
| 25 | + const wrapper = renderComponent({}, features); |
| 26 | + expect(wrapper.getByTestId('sign-button')).toBeVisible(); |
| 27 | + }); |
| 28 | + |
| 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')); |
| 39 | + |
| 40 | + expect(onClickRequestSignature).toBeCalled(); |
| 41 | + }); |
| 42 | + |
| 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(); |
| 53 | + }); |
| 54 | + |
| 55 | + test('should call correct handler when request signature option is clicked', () => { |
| 56 | + const features = { |
| 57 | + boxSign: { |
| 58 | + isSignRemoveInterstitialEnabled: true, |
| 59 | + onClick: onClickRequestSignature, |
| 60 | + }, |
| 61 | + }; |
| 62 | + const { getByTestId } = renderComponent({}, features); |
| 63 | + fireEvent.click(getByTestId('sign-button')); |
| 64 | + fireEvent.click(getByTestId('sign-request-signature-button')); |
| 65 | + expect(onClickRequestSignature).toBeCalled(); |
| 66 | + }); |
| 67 | + |
| 68 | + test('should call correct handler when sign myself option is clicked', () => { |
| 69 | + const features = { |
| 70 | + boxSign: { |
| 71 | + isSignRemoveInterstitialEnabled: true, |
| 72 | + onClickSignMyself, |
| 73 | + }, |
| 74 | + }; |
| 75 | + const { getByTestId } = renderComponent({}, features); |
| 76 | + fireEvent.click(getByTestId('sign-button')); |
| 77 | + fireEvent.click(getByTestId('sign-sign-myself-button')); |
| 78 | + expect(onClickSignMyself).toBeCalled(); |
| 79 | + }); |
| 80 | +}); |
0 commit comments