You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.8 KiB
180 lines
4.8 KiB
4 years ago
|
import React from 'react';
|
||
|
import { shallow } from 'enzyme';
|
||
|
import sinon from 'sinon';
|
||
4 years ago
|
import ConfirmSeedPhrase from './confirm-seed-phrase/confirm-seed-phrase.component';
|
||
6 years ago
|
|
||
4 years ago
|
function shallowRender(props = {}, context = {}) {
|
||
|
return shallow(<ConfirmSeedPhrase {...props} />, {
|
||
|
context: {
|
||
|
t: (str) => `${str}_t`,
|
||
|
...context,
|
||
4 years ago
|
},
|
||
4 years ago
|
});
|
||
6 years ago
|
}
|
||
|
|
||
4 years ago
|
describe('ConfirmSeedPhrase Component', () => {
|
||
|
it('should render correctly', () => {
|
||
6 years ago
|
const root = shallowRender({
|
||
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
expect(root.find('.confirm-seed-phrase__seed-word--sorted')).toHaveLength(
|
||
6 years ago
|
12,
|
||
4 years ago
|
);
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should add/remove selected on click', () => {
|
||
4 years ago
|
const metricsEventSpy = sinon.spy();
|
||
|
const pushSpy = sinon.spy();
|
||
6 years ago
|
const root = shallowRender(
|
||
|
{
|
||
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
||
|
history: { push: pushSpy },
|
||
|
},
|
||
|
{
|
||
|
metricsEvent: metricsEventSpy,
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
|
||
6 years ago
|
|
||
|
// Click on 3 seeds to add to selected
|
||
4 years ago
|
seeds.at(0).simulate('click');
|
||
|
seeds.at(1).simulate('click');
|
||
|
seeds.at(2).simulate('click');
|
||
6 years ago
|
|
||
4 years ago
|
expect(root.state().selectedSeedIndices).toStrictEqual([0, 1, 2]);
|
||
6 years ago
|
|
||
|
// Click on a selected seed to remove
|
||
4 years ago
|
root.state();
|
||
|
root.update();
|
||
|
root.state();
|
||
|
root
|
||
|
.find('.confirm-seed-phrase__seed-word--sorted')
|
||
|
.at(1)
|
||
|
.simulate('click');
|
||
4 years ago
|
expect(root.state().selectedSeedIndices).toStrictEqual([0, 2]);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should render correctly on hover', () => {
|
||
4 years ago
|
const metricsEventSpy = sinon.spy();
|
||
|
const pushSpy = sinon.spy();
|
||
6 years ago
|
const root = shallowRender(
|
||
|
{
|
||
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
||
|
history: { push: pushSpy },
|
||
|
},
|
||
|
{
|
||
|
metricsEvent: metricsEventSpy,
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
|
||
6 years ago
|
|
||
|
// Click on 3 seeds to add to selected
|
||
4 years ago
|
seeds.at(0).simulate('click');
|
||
|
seeds.at(1).simulate('click');
|
||
|
seeds.at(2).simulate('click');
|
||
6 years ago
|
|
||
|
// Dragging Seed # 2 to 0 placeth
|
||
4 years ago
|
root.instance().setDraggingSeedIndex(2);
|
||
|
root.instance().setHoveringIndex(0);
|
||
6 years ago
|
|
||
4 years ago
|
root.update();
|
||
6 years ago
|
|
||
4 years ago
|
const pendingSeeds = root.find(
|
||
|
'.confirm-seed-phrase__selected-seed-words__pending-seed',
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
expect(pendingSeeds.at(0).props().seedIndex).toStrictEqual(2);
|
||
|
expect(pendingSeeds.at(1).props().seedIndex).toStrictEqual(0);
|
||
|
expect(pendingSeeds.at(2).props().seedIndex).toStrictEqual(1);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should insert seed in place on drop', () => {
|
||
4 years ago
|
const metricsEventSpy = sinon.spy();
|
||
|
const pushSpy = sinon.spy();
|
||
6 years ago
|
const root = shallowRender(
|
||
|
{
|
||
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
||
|
history: { push: pushSpy },
|
||
|
},
|
||
|
{
|
||
|
metricsEvent: metricsEventSpy,
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
|
||
6 years ago
|
|
||
|
// Click on 3 seeds to add to selected
|
||
4 years ago
|
seeds.at(0).simulate('click');
|
||
|
seeds.at(1).simulate('click');
|
||
|
seeds.at(2).simulate('click');
|
||
6 years ago
|
|
||
|
// Drop Seed # 2 to 0 placeth
|
||
4 years ago
|
root.instance().setDraggingSeedIndex(2);
|
||
|
root.instance().setHoveringIndex(0);
|
||
|
root.instance().onDrop(0);
|
||
6 years ago
|
|
||
4 years ago
|
root.update();
|
||
6 years ago
|
|
||
4 years ago
|
expect(root.state().selectedSeedIndices).toStrictEqual([2, 0, 1]);
|
||
|
expect(root.state().pendingSeedIndices).toStrictEqual([2, 0, 1]);
|
||
4 years ago
|
});
|
||
6 years ago
|
|
||
4 years ago
|
it('should submit correctly', async () => {
|
||
4 years ago
|
const originalSeed = [
|
||
|
'鼠',
|
||
|
'牛',
|
||
|
'虎',
|
||
|
'兔',
|
||
|
'龍',
|
||
|
'蛇',
|
||
|
'馬',
|
||
|
'羊',
|
||
|
'猴',
|
||
|
'雞',
|
||
|
'狗',
|
||
|
'豬',
|
||
4 years ago
|
];
|
||
|
const metricsEventSpy = sinon.spy();
|
||
|
const pushSpy = sinon.spy();
|
||
|
const initialize3BoxSpy = sinon.spy();
|
||
6 years ago
|
const root = shallowRender(
|
||
|
{
|
||
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
||
|
history: { push: pushSpy },
|
||
5 years ago
|
setSeedPhraseBackedUp: () => Promise.resolve(),
|
||
5 years ago
|
initializeThreeBox: initialize3BoxSpy,
|
||
6 years ago
|
},
|
||
|
{
|
||
|
metricsEvent: metricsEventSpy,
|
||
4 years ago
|
},
|
||
4 years ago
|
);
|
||
6 years ago
|
|
||
4 years ago
|
const sorted = root.state().sortedSeedWords;
|
||
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted');
|
||
6 years ago
|
|
||
5 years ago
|
originalSeed.forEach((seed) => {
|
||
4 years ago
|
const seedIndex = sorted.findIndex((s) => s === seed);
|
||
|
seeds.at(seedIndex).simulate('click');
|
||
|
});
|
||
6 years ago
|
|
||
4 years ago
|
root.update();
|
||
6 years ago
|
|
||
4 years ago
|
root.find('.first-time-flow__button').simulate('click');
|
||
5 years ago
|
|
||
4 years ago
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||
5 years ago
|
|
||
4 years ago
|
expect(metricsEventSpy.args[0][0]).toStrictEqual({
|
||
6 years ago
|
eventOpts: {
|
||
|
category: 'Onboarding',
|
||
|
action: 'Seed Phrase Setup',
|
||
|
name: 'Verify Complete',
|
||
|
},
|
||
4 years ago
|
});
|
||
4 years ago
|
expect(initialize3BoxSpy.calledOnce).toStrictEqual(true);
|
||
|
expect(pushSpy.args[0][0]).toStrictEqual('/initialize/end-of-flow');
|
||
4 years ago
|
});
|
||
|
});
|