mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-12 04:37:13 +01:00
a8c1756816
* Remove 3box feature and delete ThreeBoxController Lint locale messages lavamoat policy updates * Restore 3Box user trait with value `false` The 3Box user trait has been restored and hard-coded as `false`. This ensures that users don't get stuck in our metrics as having this trait. A deprecation comment has been left in various places for this trait. * Remove unused state * Remove additional 3box-related things * Run `yarn-deduplicate` * Restore migration that was lost while rebasing * Remove obsolete override * Remove additional unused resolutions/dependencies * Update LavaMoat policies * Remove obsolete security advisory ignore entries * Remove 3Box fixture builder method * Update unit tests Co-authored-by: Mark Stacey <markjstacey@gmail.com>
178 lines
4.8 KiB
JavaScript
178 lines
4.8 KiB
JavaScript
import React from 'react';
|
|
import { shallow } from 'enzyme';
|
|
import sinon from 'sinon';
|
|
import ConfirmSeedPhrase from './confirm-seed-phrase/confirm-seed-phrase.component';
|
|
|
|
function shallowRender(props = {}, context = {}) {
|
|
return shallow(<ConfirmSeedPhrase {...props} />, {
|
|
context: {
|
|
t: (str) => `${str}_t`,
|
|
...context,
|
|
},
|
|
});
|
|
}
|
|
|
|
describe('ConfirmSeedPhrase Component', () => {
|
|
it('should render correctly', () => {
|
|
const component = shallowRender({
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
});
|
|
|
|
expect(
|
|
component.find('.confirm-seed-phrase__seed-word--sorted'),
|
|
).toHaveLength(12);
|
|
});
|
|
|
|
it('should add/remove selected on click', () => {
|
|
const trackEventSpy = sinon.spy();
|
|
const replaceSpy = sinon.spy();
|
|
const component = shallowRender(
|
|
{
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
history: { replace: replaceSpy },
|
|
},
|
|
{
|
|
trackEvent: trackEventSpy,
|
|
},
|
|
);
|
|
|
|
const seeds = component.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(component.state().selectedSeedIndices).toStrictEqual([0, 1, 2]);
|
|
|
|
// Click on a selected seed to remove
|
|
component.state();
|
|
component.update();
|
|
component.state();
|
|
component
|
|
.find('.confirm-seed-phrase__seed-word--sorted')
|
|
.at(1)
|
|
.simulate('click');
|
|
expect(component.state().selectedSeedIndices).toStrictEqual([0, 2]);
|
|
});
|
|
|
|
it('should render correctly on hover', () => {
|
|
const trackEventSpy = sinon.spy();
|
|
const replaceSpy = sinon.spy();
|
|
const component = shallowRender(
|
|
{
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
history: { replace: replaceSpy },
|
|
},
|
|
{
|
|
trackEvent: trackEventSpy,
|
|
},
|
|
);
|
|
|
|
const seeds = component.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
|
|
component.instance().setDraggingSeedIndex(2);
|
|
component.instance().setHoveringIndex(0);
|
|
|
|
component.update();
|
|
|
|
const pendingSeeds = component.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 trackEventSpy = sinon.spy();
|
|
const replaceSpy = sinon.spy();
|
|
const component = shallowRender(
|
|
{
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
history: { replace: replaceSpy },
|
|
},
|
|
{
|
|
trackEvent: trackEventSpy,
|
|
},
|
|
);
|
|
|
|
const seeds = component.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
|
|
component.instance().setDraggingSeedIndex(2);
|
|
component.instance().setHoveringIndex(0);
|
|
component.instance().onDrop(0);
|
|
|
|
component.update();
|
|
|
|
expect(component.state().selectedSeedIndices).toStrictEqual([2, 0, 1]);
|
|
expect(component.state().pendingSeedIndices).toStrictEqual([2, 0, 1]);
|
|
});
|
|
|
|
it('should submit correctly', async () => {
|
|
const originalSeed = [
|
|
'鼠',
|
|
'牛',
|
|
'虎',
|
|
'兔',
|
|
'龍',
|
|
'蛇',
|
|
'馬',
|
|
'羊',
|
|
'猴',
|
|
'雞',
|
|
'狗',
|
|
'豬',
|
|
];
|
|
const trackEventSpy = sinon.spy();
|
|
const replaceSpy = sinon.spy();
|
|
const component = shallowRender(
|
|
{
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
history: { replace: replaceSpy },
|
|
setSeedPhraseBackedUp: () => Promise.resolve(),
|
|
},
|
|
{
|
|
trackEvent: trackEventSpy,
|
|
},
|
|
);
|
|
|
|
const sorted = component.state().sortedSeedWords;
|
|
const seeds = component.find('.confirm-seed-phrase__seed-word--sorted');
|
|
|
|
originalSeed.forEach((seed) => {
|
|
const seedIndex = sorted.findIndex((s) => s === seed);
|
|
seeds.at(seedIndex).simulate('click');
|
|
});
|
|
|
|
component.update();
|
|
|
|
component.find('.first-time-flow__button').simulate('click');
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
|
|
expect(trackEventSpy.args[0][0]).toStrictEqual({
|
|
category: 'Onboarding',
|
|
event: 'Wallet Created',
|
|
properties: {
|
|
account_type: 'metamask',
|
|
is_backup_skipped: false,
|
|
},
|
|
});
|
|
expect(replaceSpy.args[0][0]).toStrictEqual('/initialize/end-of-flow');
|
|
});
|
|
});
|