|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; |
| 3 | +import DerivMT5Password from '../deriv-mt5-password'; |
| 4 | +import { APIProvider, useMutation } from '@deriv/api'; |
| 5 | +import { mockStore, StoreProvider } from '@deriv/stores'; |
| 6 | + |
| 7 | +jest.mock('@deriv/quill-icons', () => ({ |
| 8 | + ...jest.requireActual('@deriv/quill-icons'), |
| 9 | + PartnersProductDerivMt5BrandLightLogoHorizontalIcon: () => 'PartnersProductDerivMt5BrandLightLogoHorizontalIcon', |
| 10 | +})); |
| 11 | + |
| 12 | +jest.mock('@deriv/api', () => ({ |
| 13 | + ...jest.requireActual('@deriv/api'), |
| 14 | + useMutation: jest.fn(() => ({ mutate: jest.fn() })), |
| 15 | +})); |
| 16 | + |
| 17 | +describe('<DerivMT5Password />', () => { |
| 18 | + let modal_root_el: HTMLDivElement; |
| 19 | + |
| 20 | + beforeAll(() => { |
| 21 | + modal_root_el = document.createElement('div'); |
| 22 | + modal_root_el.setAttribute('id', 'modal_root'); |
| 23 | + document.body.appendChild(modal_root_el); |
| 24 | + }); |
| 25 | + |
| 26 | + afterAll(() => { |
| 27 | + document.body.removeChild(modal_root_el); |
| 28 | + }); |
| 29 | + |
| 30 | + const store = mockStore({ client: { email: '[email protected]' } }); |
| 31 | + |
| 32 | + const renderComponent = ({ store_config = store }) => |
| 33 | + render( |
| 34 | + <APIProvider> |
| 35 | + <StoreProvider store={store_config}> |
| 36 | + <DerivMT5Password /> |
| 37 | + </StoreProvider> |
| 38 | + </APIProvider> |
| 39 | + ); |
| 40 | + |
| 41 | + it('Should render properly', async () => { |
| 42 | + renderComponent({}); |
| 43 | + |
| 44 | + expect(screen.getAllByText(/deriv mt5 password/i)).toHaveLength(2); |
| 45 | + expect( |
| 46 | + screen.getByText(/use your to log in to your Deriv MT5 accounts on the desktop, web and mobile apps\./i) |
| 47 | + ).toBeInTheDocument(); |
| 48 | + expect(screen.queryByText(/PartnersProductDerivMt5BrandLightLogoHorizontalIcon/i)).toBeInTheDocument(); |
| 49 | + expect(screen.getByRole('button', { name: /Change password/i })).toBeInTheDocument(); |
| 50 | + expect(screen.queryByText(/unlink from/i)).not.toBeInTheDocument(); |
| 51 | + }); |
| 52 | + |
| 53 | + it('displays a change password button', () => { |
| 54 | + renderComponent({}); |
| 55 | + const change_password_button = screen.getByRole('button', { |
| 56 | + name: /change password/i, |
| 57 | + }); |
| 58 | + |
| 59 | + expect(change_password_button).toBeInTheDocument(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should invoke useMutation when change password is clicked', async () => { |
| 63 | + renderComponent({}); |
| 64 | + const ele_change_btn = screen.getByRole('button', { |
| 65 | + name: /change password/i, |
| 66 | + }); |
| 67 | + fireEvent.click(ele_change_btn); |
| 68 | + expect(screen.queryByText(/we’ve sent you an email/i)).toBeInTheDocument(); |
| 69 | + expect(screen.getByText(/please click on the link in the email to change your/i)).toBeInTheDocument(); |
| 70 | + await waitFor(() => { |
| 71 | + expect(useMutation).toHaveBeenCalled(); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
0 commit comments