1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00
metamask-extension/ui/pages/keychains/reveal-seed.test.js

342 lines
9.8 KiB
JavaScript
Raw Normal View History

import React from 'react';
import configureMockStore from 'redux-mock-store';
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
import { fireEvent, waitFor } from '@testing-library/react';
import thunk from 'redux-thunk';
import { renderWithProvider } from '../../../test/lib/render-helpers';
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
import mockState from '../../../test/data/mock-state.json';
import { MetaMetricsContext } from '../../contexts/metametrics';
import {
MetaMetricsEventCategory,
MetaMetricsEventKeyType,
MetaMetricsEventName,
} from '../../../shared/constants/metametrics';
import { Modal } from '../../components/app/modals';
import configureStore from '../../store/store';
import RevealSeedPage from './reveal-seed';
const mockRequestRevealSeedWords = jest.fn();
const mockShowModal = jest.fn();
jest.mock('../../store/actions.ts', () => ({
...jest.requireActual('../../store/actions.ts'),
requestRevealSeedWords: () => mockRequestRevealSeedWords,
}));
const mockStateWithModal = {
...mockState,
appState: {
...mockState.appState,
modal: {
open: true,
modalState: {
name: 'HOLD_TO_REVEAL_SRP',
props: {
onLongPressed: jest.fn(),
},
},
},
},
};
describe('Reveal Seed Page', () => {
const mockStore = configureMockStore([thunk])(mockStateWithModal);
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
afterEach(() => {
jest.clearAllMocks();
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
});
it('should match snapshot', () => {
const { container } = renderWithProvider(<RevealSeedPage />, mockStore);
expect(container).toMatchSnapshot();
});
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
it('form submit', async () => {
mockRequestRevealSeedWords.mockResolvedValueOnce('test srp');
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
const { queryByTestId, queryByText } = renderWithProvider(
<RevealSeedPage />,
mockStore,
);
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'password' },
});
fireEvent.click(queryByText('Next'));
await waitFor(() => {
expect(mockRequestRevealSeedWords).toHaveBeenCalled();
});
});
it('shows hold to reveal', async () => {
mockRequestRevealSeedWords.mockResolvedValueOnce('test srp');
const { queryByTestId, queryByText } = renderWithProvider(
<RevealSeedPage />,
mockStore,
);
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'password' },
});
fireEvent.click(queryByText('Next'));
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
await waitFor(() => {
expect(mockRequestRevealSeedWords).toHaveBeenCalled();
});
});
it('does not show modal on bad password', async () => {
mockRequestRevealSeedWords.mockRejectedValueOnce('incorrect password');
SRP hold to reveal (#17232) * refactor class to functional component * update messages * fix: use classnames * feat: add hold to reveal modal * feat: add new zendesk url for secret recovery phrase and noncustodial wallet * update: clipboard to clear copied text after delay * fix: remove save to csv * feat: update styles for reveal seed page * fix: update reveal seed snapshot * add test to check for modal * fix: lint * fix: unused messages locale * fix: use new banner component * fix: use new button from design system * fix: update snapshot * fix: lint * revert text * fix: lint * fix: remove --copy-only * fix: marginBottom prop value * fix: iconName and prop error * --made the QR code slightly smaller so it's less likely to have a scrollbar --updated the snapshots * fix: error message not displaying * SRP hold to reveal using more DS components (#17583) * Updating to add DS components and remove CSS * Fixing rendered html and removing some unneeded props * fix: set block to true --------- Co-authored-by: Monte <monte.lai@consensys.net> * fix: add descriptions to messages * Update ui/components/ui/export-text-container/export-text-container.component.js fix: lint Co-authored-by: HowardBraham <HowardBraham@users.noreply.github.com> * fix: remove using displayWarning in requestRevealSeedWords * fix: update test to remove displayError * fix: update design system enums * fix: messages descriptions * fix: banner to banneralert * fix: update preview * add additional tests * fix: use jest instead of sinon * add test if long press isn't completed * add test if password is wrong --------- Co-authored-by: Howard Braham <howrad@gmail.com> Co-authored-by: George Marshall <george.marshall@consensys.net>
2023-02-15 19:07:33 +01:00
const { queryByTestId, queryByText } = renderWithProvider(
<RevealSeedPage />,
mockStore,
);
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'bad password' },
});
fireEvent.click(queryByText('Next'));
await waitFor(() => {
expect(mockShowModal).not.toHaveBeenCalled();
});
});
it('should show srp after hold to reveal', async () => {
// need to use actual store because redux-mock-store does not execute actions
const store = configureStore(mockState);
mockRequestRevealSeedWords.mockResolvedValueOnce('test srp');
const { queryByTestId, queryByText } = renderWithProvider(
<div>
<Modal />
<RevealSeedPage />
</div>,
store,
);
const nextButton = queryByText('Next');
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'password' },
});
fireEvent.click(nextButton);
await waitFor(() => {
expect(mockRequestRevealSeedWords).toHaveBeenCalled();
expect(queryByText('Keep your SRP safe')).toBeInTheDocument();
});
});
it('emits events when correct password is entered', async () => {
const store = configureStore(mockState);
mockRequestRevealSeedWords
.mockRejectedValueOnce('incorrect password')
.mockResolvedValueOnce('test srp');
const mockTrackEvent = jest.fn();
const { queryByTestId, queryByText, getByText, queryByLabelText } =
renderWithProvider(
<MetaMetricsContext.Provider value={mockTrackEvent}>
<Modal />
<RevealSeedPage />
</MetaMetricsContext.Provider>,
store,
);
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'bad-password' },
});
fireEvent.click(queryByText('Next'));
await waitFor(() => {
expect(mockRequestRevealSeedWords).toHaveBeenCalled();
expect(mockTrackEvent).toHaveBeenNthCalledWith(1, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportRequested,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpRevealNextClicked,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
expect(mockTrackEvent).toHaveBeenLastCalledWith({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportFailed,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
reason: undefined,
},
});
});
mockTrackEvent.mockClear();
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'password' },
});
fireEvent.click(queryByText('Next'));
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenNthCalledWith(1, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportRequested,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpRevealNextClicked,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
expect(mockTrackEvent).toHaveBeenLastCalledWith({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportRevealed,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
expect(queryByText('Keep your SRP safe')).toBeInTheDocument();
});
const holdButton = getByText('Hold to reveal SRP');
const circleLocked = queryByLabelText('hold to reveal circle locked');
fireEvent.pointerDown(holdButton);
fireEvent.transitionEnd(circleLocked);
const circleUnlocked = queryByLabelText('hold to reveal circle unlocked');
fireEvent.animationEnd(circleUnlocked);
await waitFor(() => {
expect(holdButton.firstChild).toHaveClass(
'hold-to-reveal-button__icon-container',
);
// tests that the mock srp is now shown.
expect(getByText('test srp')).toBeInTheDocument();
expect(mockTrackEvent).toHaveBeenLastCalledWith({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpViewSrpText,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
});
mockTrackEvent.mockClear();
// completed hold click
const qrTab = getByText('QR');
const textTab = getByText('Text');
fireEvent.click(qrTab);
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenLastCalledWith({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpViewsSrpQR,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
});
fireEvent.click(textTab);
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenLastCalledWith({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpViewSrpText,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
});
mockTrackEvent.mockClear();
const copyButton = getByText('Copy to clipboard');
fireEvent.click(copyButton);
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenNthCalledWith(1, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportCopied,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
copy_method: 'clipboard',
},
});
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpCopiedToClipboard,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
copy_method: 'clipboard',
},
});
});
const doneButton = getByText('Close');
fireEvent.click(doneButton);
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenLastCalledWith({
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpRevealCloseClicked,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
});
});
it('should emit event when cancel is clicked', async () => {
mockRequestRevealSeedWords
.mockRejectedValueOnce('incorrect password')
.mockResolvedValueOnce('test srp');
const mockTrackEvent = jest.fn();
const { queryByText } = renderWithProvider(
<MetaMetricsContext.Provider value={mockTrackEvent}>
<RevealSeedPage />
</MetaMetricsContext.Provider>,
mockStore,
);
const cancelButton = queryByText('Cancel');
fireEvent.click(cancelButton);
await waitFor(() => {
expect(mockTrackEvent).toHaveBeenNthCalledWith(1, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.KeyExportCanceled,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
expect(mockTrackEvent).toHaveBeenNthCalledWith(2, {
category: MetaMetricsEventCategory.Keys,
event: MetaMetricsEventName.SrpRevealCancelled,
properties: {
key_type: MetaMetricsEventKeyType.Srp,
},
});
});
});
});