2021-10-06 20:52:25 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
2022-12-15 15:38:15 +01:00
|
|
|
import thunk from 'redux-thunk';
|
2021-10-06 20:52:25 +02:00
|
|
|
import reactRouterDom from 'react-router-dom';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
|
|
|
import { ONBOARDING_COMPLETION_ROUTE } from '../../../helpers/constants/routes';
|
2022-12-15 15:38:15 +01:00
|
|
|
import * as Actions from '../../../store/actions';
|
2021-10-06 20:52:25 +02:00
|
|
|
import SecureYourWallet from './secure-your-wallet';
|
|
|
|
|
|
|
|
describe('Secure Your Wallet Onboarding View', () => {
|
|
|
|
const useHistoryOriginal = reactRouterDom.useHistory;
|
|
|
|
const pushMock = jest.fn();
|
|
|
|
beforeAll(() => {
|
|
|
|
jest
|
|
|
|
.spyOn(reactRouterDom, 'useHistory')
|
|
|
|
.mockImplementation()
|
|
|
|
.mockReturnValue({ push: pushMock });
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
reactRouterDom.useHistory = useHistoryOriginal;
|
|
|
|
});
|
|
|
|
|
|
|
|
const mockStore = {
|
|
|
|
metamask: {
|
|
|
|
provider: {
|
|
|
|
type: 'test',
|
|
|
|
},
|
|
|
|
},
|
2023-02-01 18:53:35 +01:00
|
|
|
localeMessages: {
|
|
|
|
currentLocale: 'en',
|
|
|
|
},
|
2021-10-06 20:52:25 +02:00
|
|
|
};
|
|
|
|
|
2022-12-15 15:38:15 +01:00
|
|
|
const store = configureMockStore([thunk])(mockStore);
|
|
|
|
|
2021-10-06 20:52:25 +02:00
|
|
|
it('should show a popover asking the user if they want to skip account security if they click "Remind me later"', () => {
|
|
|
|
const { queryAllByText, getByText } = renderWithProvider(
|
|
|
|
<SecureYourWallet />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
const remindMeLaterButton = getByText('Remind me later (not recommended)');
|
2022-08-08 21:01:38 +02:00
|
|
|
expect(queryAllByText('Skip account security?')).toHaveLength(0);
|
2021-10-06 20:52:25 +02:00
|
|
|
fireEvent.click(remindMeLaterButton);
|
2022-08-08 21:01:38 +02:00
|
|
|
expect(queryAllByText('Skip account security?')).toHaveLength(1);
|
2021-10-06 20:52:25 +02:00
|
|
|
});
|
|
|
|
|
2022-12-15 15:38:15 +01:00
|
|
|
it('should not be able to click "skip" until "Skip Account Security" terms are agreed to', async () => {
|
|
|
|
const setSeedPhraseBackedUpSpy = jest
|
|
|
|
.spyOn(Actions, 'setSeedPhraseBackedUp')
|
|
|
|
.mockReturnValue({ type: 'setSeedPhraseBackedUp' });
|
|
|
|
|
2021-10-06 20:52:25 +02:00
|
|
|
const { getByText, getByTestId } = renderWithProvider(
|
|
|
|
<SecureYourWallet />,
|
|
|
|
store,
|
|
|
|
);
|
|
|
|
const remindMeLaterButton = getByText('Remind me later (not recommended)');
|
|
|
|
fireEvent.click(remindMeLaterButton);
|
|
|
|
const skipButton = getByText('Skip');
|
|
|
|
fireEvent.click(skipButton);
|
|
|
|
expect(pushMock).toHaveBeenCalledTimes(0);
|
|
|
|
const checkbox = getByTestId('skip-srp-backup-popover-checkbox');
|
|
|
|
fireEvent.click(checkbox);
|
2022-12-15 15:38:15 +01:00
|
|
|
const confirmSkip = getByTestId('skip-srp-backup');
|
|
|
|
await fireEvent.click(confirmSkip);
|
|
|
|
expect(setSeedPhraseBackedUpSpy).toHaveBeenCalledTimes(1);
|
2021-10-06 20:52:25 +02:00
|
|
|
expect(pushMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(pushMock).toHaveBeenCalledWith(ONBOARDING_COMPLETION_ROUTE);
|
|
|
|
});
|
|
|
|
});
|