Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import srp onboarding unit tests #18255

Merged
merged 25 commits into from
Apr 20, 2023
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
22327d7
Import srp onboarding unit tests
tmashuang Mar 21, 2023
094c8a3
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 22, 2023
2b67527
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 23, 2023
ab35666
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 24, 2023
9af3340
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 25, 2023
1db1b08
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 28, 2023
b342072
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 29, 2023
0c3969b
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 30, 2023
f3095e6
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Mar 31, 2023
2033bc8
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 1, 2023
b08002a
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 3, 2023
8a15fbf
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 5, 2023
2339cc3
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 5, 2023
8f72e66
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 6, 2023
b745d68
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 7, 2023
f360ee8
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 12, 2023
60c92f7
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 12, 2023
a63d8b2
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 13, 2023
92dbb08
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 17, 2023
2bf9d62
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 17, 2023
fcc7a04
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 17, 2023
09b8866
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 18, 2023
2843c99
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 19, 2023
8e37ebd
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 20, 2023
e5d55f2
Merge branch 'develop' into 17191-onboarding-unit-tests-import-srp
tmashuang Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions ui/pages/onboarding-flow/import-srp/import-srp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { fireEvent } from '@testing-library/react';
import React from 'react';
import configureMockStore from 'redux-mock-store';
import initializedMockState from '../../../../test/data/mock-state.json';
import { ONBOARDING_CREATE_PASSWORD_ROUTE } from '../../../helpers/constants/routes';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import ImportSrp from './import-srp';

const mockHistoryReplace = jest.fn();

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => ({
replace: mockHistoryReplace,
}),
}));

const TEST_SEED =
'debris dizzy just program just float decrease vacant alarm reduce speak stadium';

describe('Import SRP', () => {
const mockState = {
metamask: {
identities: {},
selectedAddress: '',
},
};

afterEach(() => {
jest.clearAllMocks();
});

it('should route to create password route when keyring is already initialized', () => {
const mockStore = configureMockStore()(initializedMockState);
renderWithProvider(<ImportSrp />, mockStore);

expect(mockHistoryReplace).toHaveBeenCalledWith(
ONBOARDING_CREATE_PASSWORD_ROUTE,
);
});

it('should render import srp and disable confirm srp button', () => {
const mockStore = configureMockStore()(mockState);
const { queryByTestId } = renderWithProvider(<ImportSrp />, mockStore);

const importSrpTestId = queryByTestId('import-srp');
expect(importSrpTestId).toBeInTheDocument();

const confirmSrpButton = queryByTestId('import-srp-confirm');

expect(confirmSrpButton).toBeDisabled();
});

it('should input and submit srp', () => {
const mockStore = configureMockStore()(mockState);
const mockSubmitSecretRecoveryPhrase = jest.fn();

const { queryByTestId } = renderWithProvider(
<ImportSrp submitSecretRecoveryPhrase={mockSubmitSecretRecoveryPhrase} />,
mockStore,
);

inputSRP(TEST_SEED, queryByTestId);

const confirmSrpButton = queryByTestId('import-srp-confirm');

expect(confirmSrpButton).not.toBeDisabled();

fireEvent.click(confirmSrpButton);

expect(mockSubmitSecretRecoveryPhrase).toHaveBeenCalledWith(TEST_SEED);
expect(mockHistoryReplace).toHaveBeenCalledWith(
ONBOARDING_CREATE_PASSWORD_ROUTE,
);
});

function inputSRP(seedStr, queryByTestId) {
for (const [index, word] of seedStr.split(' ').entries()) {
const srpInput = queryByTestId(`import-srp__srp-word-${index}`);
fireEvent.change(srpInput, { target: { value: word } });
}
}
});