1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 20:39:08 +01:00
metamask-extension/ui/pages/keychains/reveal-seed.test.js
Monte Lai cdc1bce688
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 10:07:33 -08:00

95 lines
2.6 KiB
JavaScript

import React from 'react';
import configureMockStore from 'redux-mock-store';
import { fireEvent, waitFor } from '@testing-library/react';
import thunk from 'redux-thunk';
import { renderWithProvider } from '../../../test/lib/render-helpers';
import { MODAL_OPEN } from '../../store/actionConstants';
import mockState from '../../../test/data/mock-state.json';
import RevealSeedPage from './reveal-seed';
const mockRequestRevealSeedWords = jest
.fn()
.mockResolvedValue('test seed words');
const mockShowModal = jest.fn().mockResolvedValue({
type: MODAL_OPEN,
payload: { name: 'HOLD_TO_REVEAL_SRP' },
});
jest.mock('../../store/actions.ts', () => ({
requestRevealSeedWords: () => mockRequestRevealSeedWords,
showModal: () => mockShowModal,
}));
describe('Reveal Seed Page', () => {
const mockStore = configureMockStore([thunk])(mockState);
afterEach(() => {
mockRequestRevealSeedWords.mockClear();
mockShowModal.mockClear();
});
it('should match snapshot', () => {
const { container } = renderWithProvider(<RevealSeedPage />, mockStore);
expect(container).toMatchSnapshot();
});
it('form submit', async () => {
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 () => {
const { queryByTestId, queryByText } = renderWithProvider(
<RevealSeedPage />,
mockStore,
);
fireEvent.change(queryByTestId('input-password'), {
target: { value: 'password' },
});
fireEvent.click(queryByText('Next'));
await waitFor(() => {
expect(mockRequestRevealSeedWords).toHaveBeenCalled();
expect(mockShowModal).toHaveBeenCalled();
});
});
it('does not show modal on bad password', async () => {
const mockRequestPasswordFail = jest.fn().mockRejectedValue();
jest.mock('../../store/actions.ts', () => ({
requestRevealSeedWords: () => mockRequestPasswordFail,
showModal: () => mockShowModal,
}));
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();
});
});
});