1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-04 23:14:56 +01:00
metamask-extension/ui/pages/first-time-flow/seed-phrase/confirm-seed-phrase-component.test.js

180 lines
4.8 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import ConfirmSeedPhrase from './confirm-seed-phrase/confirm-seed-phrase.component';
2020-11-03 00:41:28 +01:00
function shallowRender(props = {}, context = {}) {
return shallow(<ConfirmSeedPhrase {...props} />, {
context: {
t: (str) => `${str}_t`,
...context,
},
});
}
describe('ConfirmSeedPhrase Component', () => {
it('should render correctly', () => {
const root = shallowRender({
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
});
expect(root.find('.confirm-seed-phrase__seed-word--sorted')).toHaveLength(
12,
);
});
it('should add/remove selected on click', () => {
const metricsEventSpy = sinon.spy();
const pushSpy = sinon.spy();
const root = shallowRender(
{
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
history: { push: pushSpy },
},
{
metricsEvent: metricsEventSpy,
},
);
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
// Click on 3 seeds to add to selected
seeds.at(0).simulate('click');
seeds.at(1).simulate('click');
seeds.at(2).simulate('click');
expect(root.state().selectedSeedIndices).toStrictEqual([0, 1, 2]);
// Click on a selected seed to remove
root.state();
root.update();
root.state();
root
.find('.confirm-seed-phrase__seed-word--sorted')
.at(1)
.simulate('click');
expect(root.state().selectedSeedIndices).toStrictEqual([0, 2]);
});
it('should render correctly on hover', () => {
const metricsEventSpy = sinon.spy();
const pushSpy = sinon.spy();
const root = shallowRender(
{
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
history: { push: pushSpy },
},
{
metricsEvent: metricsEventSpy,
},
);
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
// Click on 3 seeds to add to selected
seeds.at(0).simulate('click');
seeds.at(1).simulate('click');
seeds.at(2).simulate('click');
// Dragging Seed # 2 to 0 placeth
root.instance().setDraggingSeedIndex(2);
root.instance().setHoveringIndex(0);
root.update();
2020-11-03 00:41:28 +01:00
const pendingSeeds = root.find(
'.confirm-seed-phrase__selected-seed-words__pending-seed',
);
expect(pendingSeeds.at(0).props().seedIndex).toStrictEqual(2);
expect(pendingSeeds.at(1).props().seedIndex).toStrictEqual(0);
expect(pendingSeeds.at(2).props().seedIndex).toStrictEqual(1);
});
it('should insert seed in place on drop', () => {
const metricsEventSpy = sinon.spy();
const pushSpy = sinon.spy();
const root = shallowRender(
{
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
history: { push: pushSpy },
},
{
metricsEvent: metricsEventSpy,
},
);
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
// Click on 3 seeds to add to selected
seeds.at(0).simulate('click');
seeds.at(1).simulate('click');
seeds.at(2).simulate('click');
// Drop Seed # 2 to 0 placeth
root.instance().setDraggingSeedIndex(2);
root.instance().setHoveringIndex(0);
root.instance().onDrop(0);
root.update();
expect(root.state().selectedSeedIndices).toStrictEqual([2, 0, 1]);
expect(root.state().pendingSeedIndices).toStrictEqual([2, 0, 1]);
});
it('should submit correctly', async () => {
2020-11-03 00:41:28 +01:00
const originalSeed = [
'鼠',
'牛',
'虎',
'兔',
'龍',
'蛇',
'馬',
'羊',
'猴',
'雞',
'狗',
'豬',
];
const metricsEventSpy = sinon.spy();
const pushSpy = sinon.spy();
const initialize3BoxSpy = sinon.spy();
const root = shallowRender(
{
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
history: { push: pushSpy },
setSeedPhraseBackedUp: () => Promise.resolve(),
3box integration 2.0 (#6972) * Adds threebox controller * Adds threebox approval modal * Fix unit tests and lint after addition of threebox * Correct threebox behaviour after rejecting request for backup; fixes e2e tests. * Update threebox controller for automatic syncing * Ensure frontend locale updates when preferences are changed via direct update within controller * Add toggle in settings for 3box syncing * Update threebox controller for latest 3box version * Delete unnecessary frontend changes for threebox integration * Backing up address book contacts with threebox * Update unit tests for 3box-integration additions * Only enable threebox by default for new wallets * Mock globals for correct unit tests * 3box '1.10.2' -> '^1.10.2' * Correct capilalization on 3Box * Use log.debug instead of console.log in threebox controller * Update yarn.lock * Remove edge build * Split 3box module into background deps js file * extra bundle opts for bg-libs * sync yarn.lock * new3Box logic * Show confirm threebox restore after import * Remove bg-libs.js from manifest file for dev builds * Switch 3Box controller to using the spaces api (instead of the profile api) * Finalize switching to spaces api and only restoring from 3box after import * Update metamask-controller-test.js for threebox controller changes * Make threebox modal style consistent with others and update success button wording * Use mock 3box when in test * Correct 3box modal header * Remove unnecessary property of threebox controller provider * Remove unnecessary method calls after restoration from 3box in the threebox-restore-confirm modal. * Replace setThreeBoxSyncingPermission calls in routes/index.js with turnThreeBoxSyncingOn * Replace erroneous use of with * Replace erroneous use of threeboxSyncing with threeBoxSyncingAllowed in advancted-tab directory * Lint fixes for 3box changes * Log errors encountered when updating 3Box * Remove unnecessary parameter from state update * Add timeout to initial 3Box sync The initial 3Box sync will now timeout after 1 minute. If the timeout is triggered, 3Box is disabled and cannot be re-enabled unless the initial sync does finally finish. If it never finishes, 3Box cannot be enabled unless the extension is reinstalled. The Advanced Settings page was updated to show this option as disabled in that circumstance, with a new discription explaining why it's disabled. The UI here could certainly be improved. Additionally, "on" and "off" labels were added to the toggle to match the other toggles on the Advanced Settings page. * Use non-minified 3Box module We had previously used the minified 3Box module to avoid a build error encountered when `envify` was processing the `libp2p` module (which is used by 3Box). The build would fail because `esprima` (used by `envify`) is incompatible with the object spread/rest operator (which is used in `libp2p`). That issue has been solved by adding a global Babelify transformation specifically for transpiling out the object rest/spread operator from dependencies. It has been targetted to only affect `libp2p` to avoid extending the build time too much. This workaround can be used until a new version of `esprima` is released that includes this bug fix. * Use app key addresses for threebox * Replace use of modal for confirming 3box restoration with a home notification * Adds e2e tests for restoring from threebox * Update eth-keyring-controller to 5.1.0 * Correct parameters passed to getAppKeyAddress in threebox.js * Add prefix to origin passed to getAppKeyAddress in threebox.js * Remove unused locale message. * Prevent CORS errors in firefox e2e tests * Ensure extraneous scripts are excluded from the local test dev build * Move threeBoxLastUpdate state from home.component to redux * Threebox PR code cleanup * Always use first address when initializing threebox * Replace setRestoredFromThreeBox api with setRestoredFromThreeBoxToFalse and setRestoredFromThreeBoxToTrue * Update development/metamaskbot-build-announce.js to include ui-libs and bg-libs in hard coded bundle list * Update test/e2e/threebox.spec.js to use new helpers added with pull #7144 * Make setFeatureFlag available on the ui window during testing * Hide threebox feature behind a feature flag that can only be activated via dev console * Remove unnecessary migration of threebox feature flag * Prevent this.init() call in threebox constructor if feature flag is not turned on * Prevent threebox notification from showing if feature flag is falsy * http://localhost/8889 -> http://localhost/* in gulp manifest:testing tasks
2019-09-16 19:11:01 +02:00
initializeThreeBox: initialize3BoxSpy,
},
{
metricsEvent: metricsEventSpy,
},
);
const sorted = root.state().sortedSeedWords;
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
2020-02-15 21:34:12 +01:00
originalSeed.forEach((seed) => {
const seedIndex = sorted.findIndex((s) => s === seed);
seeds.at(seedIndex).simulate('click');
});
root.update();
root.find('.first-time-flow__button').simulate('click');
await new Promise((resolve) => setTimeout(resolve, 100));
expect(metricsEventSpy.args[0][0]).toStrictEqual({
eventOpts: {
category: 'Onboarding',
action: 'Seed Phrase Setup',
name: 'Verify Complete',
},
});
expect(initialize3BoxSpy.calledOnce).toStrictEqual(true);
expect(pushSpy.args[0][0]).toStrictEqual('/initialize/end-of-flow');
});
});