2021-02-04 19:15:23 +01:00
|
|
|
import React from 'react';
|
2023-01-17 16:51:35 +01:00
|
|
|
import { DragDropContextProvider } from 'react-dnd';
|
|
|
|
import HTML5Backend from 'react-dnd-html5-backend';
|
|
|
|
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 ConfirmSeedPhrase from './confirm-seed-phrase';
|
|
|
|
|
|
|
|
jest.mock('../../../store/actions.js', () => ({
|
|
|
|
setSeedPhraseBackedUp: () => jest.fn().mockResolvedValue(),
|
|
|
|
}));
|
|
|
|
|
|
|
|
const seedPhrase = '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬';
|
|
|
|
|
|
|
|
function shallowRender(props = {}) {
|
|
|
|
const mockState = {};
|
|
|
|
const mockStore = configureMockStore([thunk])(mockState);
|
|
|
|
|
|
|
|
return renderWithProvider(
|
|
|
|
<DragDropContextProvider backend={HTML5Backend}>
|
|
|
|
<ConfirmSeedPhrase {...props} />
|
|
|
|
</DragDropContextProvider>,
|
|
|
|
mockStore,
|
|
|
|
);
|
2019-05-07 17:03:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
describe('ConfirmSeedPhrase Component', () => {
|
|
|
|
it('should render correctly', () => {
|
2023-01-17 16:51:35 +01:00
|
|
|
const { queryAllByTestId } = shallowRender({
|
|
|
|
seedPhrase,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-05-07 17:03:27 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
// Regex ommitted the empty/undefined draggable boxes
|
|
|
|
expect(queryAllByTestId(/draggable-seed-(?!.*undefined)/u)).toHaveLength(
|
|
|
|
12,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-05-07 17:03:27 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
// For 24 word mnemonic phrases.
|
|
|
|
expect(queryAllByTestId(/draggable-seed-undefined/u)).toHaveLength(24);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-05-07 17:03:27 +02:00
|
|
|
|
2021-04-15 20:01:46 +02:00
|
|
|
it('should submit correctly', async () => {
|
2020-11-03 00:41:28 +01:00
|
|
|
const originalSeed = [
|
|
|
|
'鼠',
|
|
|
|
'牛',
|
|
|
|
'虎',
|
|
|
|
'兔',
|
|
|
|
'龍',
|
|
|
|
'蛇',
|
|
|
|
'馬',
|
|
|
|
'羊',
|
|
|
|
'猴',
|
|
|
|
'雞',
|
|
|
|
'狗',
|
|
|
|
'豬',
|
2021-02-04 19:15:23 +01:00
|
|
|
];
|
2019-05-07 17:03:27 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
const history = {
|
|
|
|
replace: jest.fn(),
|
|
|
|
};
|
2019-05-07 17:03:27 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
const { queryByTestId } = shallowRender({
|
|
|
|
seedPhrase,
|
|
|
|
history,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-05-07 17:03:27 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
originalSeed.forEach((seed) => {
|
|
|
|
fireEvent.click(queryByTestId(`draggable-seed-${seed}`));
|
|
|
|
});
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
const confirmSeedPhrase = queryByTestId('confirm-dragged-seed-phrase');
|
|
|
|
fireEvent.click(confirmSeedPhrase);
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2023-01-17 16:51:35 +01:00
|
|
|
await waitFor(() => {
|
|
|
|
expect(history.replace).toHaveBeenCalledWith('/initialize/end-of-flow');
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|