2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2022-10-11 19:54:50 +02:00
|
|
|
import configureMockStore from 'redux-mock-store';
|
2023-02-15 19:07:33 +01:00
|
|
|
import { fireEvent, waitFor } from '@testing-library/react';
|
2022-10-11 19:54:50 +02:00
|
|
|
import thunk from 'redux-thunk';
|
|
|
|
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
2023-02-15 19:07:33 +01:00
|
|
|
import { MODAL_OPEN } from '../../store/actionConstants';
|
|
|
|
import mockState from '../../../test/data/mock-state.json';
|
2021-03-16 22:00:08 +01:00
|
|
|
import RevealSeedPage from './reveal-seed';
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2023-02-15 19:07:33 +01:00
|
|
|
const mockRequestRevealSeedWords = jest
|
|
|
|
.fn()
|
|
|
|
.mockResolvedValue('test seed words');
|
|
|
|
|
|
|
|
const mockShowModal = jest.fn().mockResolvedValue({
|
|
|
|
type: MODAL_OPEN,
|
|
|
|
payload: { name: 'HOLD_TO_REVEAL_SRP' },
|
|
|
|
});
|
2022-10-11 19:54:50 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
jest.mock('../../store/actions.ts', () => ({
|
2022-10-11 19:54:50 +02:00
|
|
|
requestRevealSeedWords: () => mockRequestRevealSeedWords,
|
2023-02-15 19:07:33 +01:00
|
|
|
showModal: () => mockShowModal,
|
2022-10-11 19:54:50 +02:00
|
|
|
}));
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('Reveal Seed Page', () => {
|
2022-10-11 19:54:50 +02:00
|
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
|
2023-02-15 19:07:33 +01:00
|
|
|
afterEach(() => {
|
|
|
|
mockRequestRevealSeedWords.mockClear();
|
|
|
|
mockShowModal.mockClear();
|
|
|
|
});
|
|
|
|
|
2022-10-11 19:54:50 +02:00
|
|
|
it('should match snapshot', () => {
|
|
|
|
const { container } = renderWithProvider(<RevealSeedPage />, mockStore);
|
|
|
|
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2023-02-15 19:07:33 +01:00
|
|
|
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 () => {
|
2022-10-11 19:54:50 +02:00
|
|
|
const { queryByTestId, queryByText } = renderWithProvider(
|
|
|
|
<RevealSeedPage />,
|
|
|
|
mockStore,
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.change(queryByTestId('input-password'), {
|
|
|
|
target: { value: 'password' },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2022-10-11 19:54:50 +02:00
|
|
|
fireEvent.click(queryByText('Next'));
|
|
|
|
|
2023-02-15 19:07:33 +01:00
|
|
|
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();
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|