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

Onboarding Unit Tests #17360

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c5a1730
Onboarding Welcome component test
tmashuang Jan 23, 2023
3a6384d
Onboarding Add Network Modal component test
tmashuang Jan 23, 2023
e57eb98
Onboarding Create Password component tests, data-testid, and snapshot.
tmashuang Jan 23, 2023
ca8e2ec
Onboarding Creation Successful test
tmashuang Jan 23, 2023
72d3ba1
Onboarding Import SRP component test
tmashuang Jan 23, 2023
1a0b9ce
Onboarding MetaMetrics component test
tmashuang Jan 23, 2023
de671f1
Onboarding App Header component test
tmashuang Jan 23, 2023
e61b833
Onboarding Flow Switch Test
tmashuang Jan 23, 2023
f45d254
Onboarding Privacy Settings IPFS input test
tmashuang Jan 23, 2023
bbc280f
Onboarding Review Recovery Phrase component test
tmashuang Jan 23, 2023
9a40f2f
Onboarding Recovery Phrase Chips component test
tmashuang Jan 23, 2023
87d3ed8
Onboarding Confirm Recovery Phrase component test
tmashuang Jan 23, 2023
cc6fa64
Proper describe component test names
tmashuang Jan 23, 2023
330711a
Create New Vault tests
tmashuang Jan 23, 2023
608ef5b
Update snapshots
tmashuang Jan 23, 2023
a7bf7a5
Lint
tmashuang Jan 23, 2023
7a12453
Update Review Recovery Phrase test snapshot
tmashuang Jan 31, 2023
af7d7ee
Update Onboarding App Header with change in local messages in state
tmashuang Feb 1, 2023
528121a
Update Metametrics snapshot
tmashuang Feb 3, 2023
84c7489
Bump coverage targets
tmashuang Feb 3, 2023
5549368
Update actions.js filename to actions.ts in tests
tmashuang Feb 3, 2023
8e929eb
Bump coverage targets
tmashuang Feb 8, 2023
8cde4a8
Bump coverage targets
tmashuang Feb 8, 2023
61aae93
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 9, 2023
275b2c6
Bump coverage targets
tmashuang Feb 9, 2023
767ccb1
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 9, 2023
647e1fe
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 9, 2023
c58abb8
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 9, 2023
90b1ce9
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 10, 2023
bf01bf2
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 10, 2023
8bf8e88
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 10, 2023
a04644a
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 10, 2023
abd64af
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 10, 2023
e5b4d20
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 13, 2023
8dae818
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 14, 2023
d4415cc
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 14, 2023
96a0757
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 14, 2023
a62fc48
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 15, 2023
4d1e535
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 15, 2023
fa6391f
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 16, 2023
f08e8a3
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 16, 2023
1359f11
Update Onboarding App Header Snapshot test
tmashuang Feb 16, 2023
af20203
Update Review Recovery Phrase snapshot
tmashuang Feb 16, 2023
15f78af
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 20, 2023
98a6309
Bump coverage
tmashuang Feb 21, 2023
cccd00d
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 21, 2023
745646f
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 21, 2023
e40fd38
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 22, 2023
058a7dc
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 22, 2023
4b916ec
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 22, 2023
a4d77d3
Update Snapshot
tmashuang Feb 23, 2023
ccb50e6
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 23, 2023
dad1aa0
Update snapshot for onboarding metametrics screen
tmashuang Feb 23, 2023
75ff5de
Bump coverage
tmashuang Feb 23, 2023
1ebc1f8
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 23, 2023
6348312
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 23, 2023
3415072
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 23, 2023
fd9c87f
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Feb 28, 2023
94a61d2
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 8, 2023
f48c2f1
Update onboarding metametrics snapshot
tmashuang Mar 8, 2023
2e9b6cd
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 8, 2023
99fec91
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 8, 2023
db068d0
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 10, 2023
c1df571
Bump coverage targets
tmashuang Mar 10, 2023
6b9c367
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 11, 2023
b7874e3
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 13, 2023
7c5d45c
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 14, 2023
898e266
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 16, 2023
ad4940c
Fix typo
tmashuang Mar 16, 2023
5789476
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 16, 2023
9e48191
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 17, 2023
56c0ea1
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 18, 2023
e26a1fb
Merge branch 'develop' into 17191/onboarding-unit-tests
tmashuang Mar 21, 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
8 changes: 4 additions & 4 deletions coverage-targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// subset of files to check against these targets.
module.exports = {
global: {
lines: 65,
branches: 53.5,
statements: 64,
functions: 57.4,
lines: 65.2,
branches: 54,
statements: 64.4,
functions: 57.5,
},
transforms: {
branches: 100,
Expand Down
3 changes: 3 additions & 0 deletions ui/components/app/create-new-vault/create-new-vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default function CreateNewVault({
<SrpInput onChange={setSeedPhrase} srpText={t('secretRecoveryPhrase')} />
<div className="create-new-vault__create-password">
<TextField
data-testid="create-vault-password"
id="password"
label={t('newPassword')}
type="password"
Expand All @@ -112,6 +113,7 @@ export default function CreateNewVault({
largeLabel
/>
<TextField
data-testid="create-vault-confirm-password"
id="confirm-password"
label={t('confirmPassword')}
type="password"
Expand Down Expand Up @@ -140,6 +142,7 @@ export default function CreateNewVault({
</div>
) : null}
<Button
data-testid="create-new-vault-submit-button"
className="create-new-vault__submit-button"
type="primary"
submit
Expand Down
149 changes: 145 additions & 4 deletions ui/components/app/create-new-vault/create-new-vault.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import React from 'react';
import { screen } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/jest';
import { screen, fireEvent } from '@testing-library/react';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import configureStore from '../../../store/store';
import mockState from '../../../../test/data/mock-state.json';
import CreateNewVault from './create-new-vault';

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

const store = configureStore({
metamask: {
...mockState.metamask,
Expand All @@ -13,13 +16,16 @@ const store = configureStore({

describe('CreateNewVault', () => {
it('renders CreateNewVault component and shows Secret Recovery Phrase text', () => {
renderWithProvider(<CreateNewVault submitText="Import" />, store);
renderWithProvider(
<CreateNewVault submitText="Import" onSubmit={jest.fn()} />,
store,
);
expect(screen.getByText('Secret Recovery Phrase')).toBeInTheDocument();
});

it('renders CreateNewVault component and shows You can paste... text', () => {
renderWithProvider(
<CreateNewVault submitText="Import" includeTerms />,
<CreateNewVault submitText="Import" onSubmit={jest.fn()} includeTerms />,
store,
);
expect(
Expand All @@ -28,4 +34,139 @@ describe('CreateNewVault', () => {
),
).toBeInTheDocument();
});

it('should check terms', () => {
const props = {
onSubmit: jest.fn(),
submitText: 'Submit',
includeTerms: true,
};

const { queryByTestId } = renderWithProvider(
<CreateNewVault {...props} />,
store,
);

const terms = queryByTestId('create-new-vault__terms-checkbox');

fireEvent.click(terms);

expect(terms).toBeChecked();
});

it('should error with password length is less than 8', () => {
const props = {
onSubmit: jest.fn(),
submitText: 'Submit',
};

const { queryByTestId, queryByText } = renderWithProvider(
<CreateNewVault {...props} />,
store,
);

const passwordInput = queryByTestId('create-vault-password');

const passwordEvent = {
target: {
value: '1234567',
},
};

fireEvent.change(passwordInput, passwordEvent);

const passwordError = queryByText('Password not long enough');

expect(passwordError).toBeInTheDocument();

const submitButton = queryByTestId('create-new-vault-submit-button');

expect(submitButton).toBeDisabled();
});

it('should error with password and confirm password mismatch', () => {
const props = {
onSubmit: jest.fn(),
submitText: 'Submit',
};

const { queryByTestId, queryByText } = renderWithProvider(
<CreateNewVault {...props} />,
store,
);

const passwordInput = queryByTestId('create-vault-password');
const confirmPasswordInput = queryByTestId('create-vault-confirm-password');

const passwordEvent = {
target: {
value: '12345678',
},
};

const confirmPasswordEvent = {
target: {
value: 'abcdefgh',
},
};

fireEvent.change(passwordInput, passwordEvent);
fireEvent.change(confirmPasswordInput, confirmPasswordEvent);

const passwordError = queryByText(`Passwords don't match`);

expect(passwordError).toBeInTheDocument();

const submitButton = queryByTestId('create-new-vault-submit-button');

expect(submitButton).toBeDisabled();
});

it('should valid', () => {
const props = {
onSubmit: jest.fn(),
submitText: 'Submit',
};

const { queryByTestId } = renderWithProvider(
<CreateNewVault {...props} />,
store,
);

inputSRP(TEST_SEED, queryByTestId);

const passwordInput = queryByTestId('create-vault-password');
const confirmPasswordInput = queryByTestId('create-vault-confirm-password');

const password = '12345678';

const passwordEvent = {
target: {
value: password,
},
};

const confirmPasswordEvent = {
target: {
value: password,
},
};

fireEvent.change(passwordInput, passwordEvent);
fireEvent.change(confirmPasswordInput, confirmPasswordEvent);

const submitButton = queryByTestId('create-new-vault-submit-button');
expect(submitButton).not.toBeDisabled();

fireEvent.click(submitButton);

expect(props.onSubmit).toHaveBeenCalledWith(password, TEST_SEED);
});
});

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 } });
}
}
Loading