1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-02 22:24:27 +01:00
metamask-extension/ui/pages/first-time-flow/seed-phrase/confirm-seed-phrase-component.test.js
Thomas Huang 4c3c4eebac
Final conversion of tests from enzyme to @testing-library/react (#16862)
* Add transaction activity log component

* Remove duplicate tx activity log snapshot.

* Convert Advanced Tab to tlr.

* Lint fix

* Change ENS to DNS in mock state data.

* Add test ids for speedup, cancel, rety buttons.

* Convert TransactionListItemDetails component to RTL.

* Convert PageContainerHeader component to RTL.

* Convert TokenInput component to RTL.

* Convert UnitInput component to RTL.

* Convert withModalProps to RTL.

* Convert i18n-helper to RTL.

* Convert ConfirmSeedPhrase component to TLR.

* Convert AddRecipient component to RTL.

* Set process.env metamask build type to 'main' for test

Co-authored-by: Brad Decker <bhdecker84@gmail.com>
Co-authored-by: Pedro Figueiredo <pedro.figueiredo@consensys.net>
2023-01-17 07:51:35 -08:00

80 lines
2.0 KiB
JavaScript

import React from 'react';
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,
);
}
describe('ConfirmSeedPhrase Component', () => {
it('should render correctly', () => {
const { queryAllByTestId } = shallowRender({
seedPhrase,
});
// Regex ommitted the empty/undefined draggable boxes
expect(queryAllByTestId(/draggable-seed-(?!.*undefined)/u)).toHaveLength(
12,
);
// For 24 word mnemonic phrases.
expect(queryAllByTestId(/draggable-seed-undefined/u)).toHaveLength(24);
});
it('should submit correctly', async () => {
const originalSeed = [
'鼠',
'牛',
'虎',
'兔',
'龍',
'蛇',
'馬',
'羊',
'猴',
'雞',
'狗',
'豬',
];
const history = {
replace: jest.fn(),
};
const { queryByTestId } = shallowRender({
seedPhrase,
history,
});
originalSeed.forEach((seed) => {
fireEvent.click(queryByTestId(`draggable-seed-${seed}`));
});
const confirmSeedPhrase = queryByTestId('confirm-dragged-seed-phrase');
fireEvent.click(confirmSeedPhrase);
await waitFor(() => {
expect(history.replace).toHaveBeenCalledWith('/initialize/end-of-flow');
});
});
});