2019-05-07 17:03:27 +02:00
|
|
|
import React from 'react'
|
|
|
|
import assert from 'assert'
|
|
|
|
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: {
|
2020-02-15 21:34:12 +01:00
|
|
|
t: (str) => str + '_t',
|
2019-05-07 17:03:27 +02:00
|
|
|
...context,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('ConfirmSeedPhrase Component', function () {
|
|
|
|
it('should render correctly', function () {
|
2019-05-07 17:03:27 +02:00
|
|
|
const root = shallowRender({
|
|
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
|
|
})
|
|
|
|
|
|
|
|
assert.equal(
|
2020-01-29 20:42:46 +01:00
|
|
|
root.find('.confirm-seed-phrase__seed-word--sorted').length,
|
2019-05-07 17:03:27 +02:00
|
|
|
12,
|
|
|
|
'should render 12 seed phrases'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should add/remove selected on click', function () {
|
2019-05-07 17:03:27 +02:00
|
|
|
const metricsEventSpy = sinon.spy()
|
|
|
|
const pushSpy = sinon.spy()
|
|
|
|
const root = shallowRender(
|
|
|
|
{
|
|
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
|
|
history: { push: pushSpy },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
metricsEvent: metricsEventSpy,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-01-29 20:42:46 +01:00
|
|
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted')
|
2019-05-07 17:03:27 +02:00
|
|
|
|
|
|
|
// Click on 3 seeds to add to selected
|
|
|
|
seeds.at(0).simulate('click')
|
|
|
|
seeds.at(1).simulate('click')
|
|
|
|
seeds.at(2).simulate('click')
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
|
|
root.state().selectedSeedIndices,
|
|
|
|
[0, 1, 2],
|
|
|
|
'should add seed phrase to selected on click',
|
|
|
|
)
|
|
|
|
|
|
|
|
// Click on a selected seed to remove
|
|
|
|
root.state()
|
|
|
|
root.update()
|
|
|
|
root.state()
|
2020-01-29 20:42:46 +01:00
|
|
|
root.find('.confirm-seed-phrase__seed-word--sorted').at(1).simulate('click')
|
2019-05-07 17:03:27 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
root.state().selectedSeedIndices,
|
|
|
|
[0, 2],
|
|
|
|
'should remove seed phrase from selected when click again',
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should render correctly on hover', function () {
|
2019-05-07 17:03:27 +02:00
|
|
|
const metricsEventSpy = sinon.spy()
|
|
|
|
const pushSpy = sinon.spy()
|
|
|
|
const root = shallowRender(
|
|
|
|
{
|
|
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
|
|
history: { push: pushSpy },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
metricsEvent: metricsEventSpy,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-01-29 20:42:46 +01:00
|
|
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted')
|
2019-05-07 17:03:27 +02:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
|
|
|
const pendingSeeds = root.find('.confirm-seed-phrase__selected-seed-words__pending-seed')
|
|
|
|
|
|
|
|
assert.equal(pendingSeeds.at(0).props().seedIndex, 2)
|
|
|
|
assert.equal(pendingSeeds.at(1).props().seedIndex, 0)
|
|
|
|
assert.equal(pendingSeeds.at(2).props().seedIndex, 1)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should insert seed in place on drop', function () {
|
2019-05-07 17:03:27 +02:00
|
|
|
const metricsEventSpy = sinon.spy()
|
|
|
|
const pushSpy = sinon.spy()
|
|
|
|
const root = shallowRender(
|
|
|
|
{
|
|
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
|
|
history: { push: pushSpy },
|
|
|
|
},
|
|
|
|
{
|
|
|
|
metricsEvent: metricsEventSpy,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-01-29 20:42:46 +01:00
|
|
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted')
|
2019-05-07 17:03:27 +02:00
|
|
|
|
|
|
|
// 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()
|
|
|
|
|
|
|
|
assert.deepEqual(root.state().selectedSeedIndices, [2, 0, 1])
|
|
|
|
assert.deepEqual(root.state().pendingSeedIndices, [2, 0, 1])
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('should submit correctly', async function () {
|
2019-05-07 17:03:27 +02:00
|
|
|
const originalSeed = ['鼠', '牛', '虎', '兔', '龍', '蛇', '馬', '羊', '猴', '雞', '狗', '豬']
|
|
|
|
const metricsEventSpy = sinon.spy()
|
|
|
|
const pushSpy = sinon.spy()
|
2019-09-16 19:11:01 +02:00
|
|
|
const initialize3BoxSpy = sinon.spy()
|
2019-05-07 17:03:27 +02:00
|
|
|
const root = shallowRender(
|
|
|
|
{
|
|
|
|
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
|
|
|
|
history: { push: pushSpy },
|
2019-08-02 05:57:26 +02:00
|
|
|
setSeedPhraseBackedUp: () => Promise.resolve(),
|
2019-09-16 19:11:01 +02:00
|
|
|
initializeThreeBox: initialize3BoxSpy,
|
2019-05-07 17:03:27 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
metricsEvent: metricsEventSpy,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2020-01-29 20:42:46 +01:00
|
|
|
const sorted = root.state().sortedSeedWords
|
|
|
|
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted')
|
2019-05-07 17:03:27 +02:00
|
|
|
|
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
originalSeed.forEach((seed) => {
|
|
|
|
const seedIndex = sorted.findIndex((s) => s === seed)
|
2019-05-07 17:03:27 +02:00
|
|
|
seeds.at(seedIndex).simulate('click')
|
|
|
|
})
|
|
|
|
|
|
|
|
root.update()
|
|
|
|
|
|
|
|
root.find('.first-time-flow__button').simulate('click')
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
await (new Promise((resolve) => setTimeout(resolve, 100)))
|
2019-08-02 05:57:26 +02:00
|
|
|
|
2019-05-07 17:03:27 +02:00
|
|
|
assert.deepEqual(metricsEventSpy.args[0][0], {
|
|
|
|
eventOpts: {
|
|
|
|
category: 'Onboarding',
|
|
|
|
action: 'Seed Phrase Setup',
|
|
|
|
name: 'Verify Complete',
|
|
|
|
},
|
|
|
|
})
|
2019-09-16 19:11:01 +02:00
|
|
|
assert(initialize3BoxSpy.calledOnce)
|
2019-05-07 17:03:27 +02:00
|
|
|
assert.equal(pushSpy.args[0][0], '/initialize/end-of-flow')
|
|
|
|
})
|
|
|
|
})
|