1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-28 05:12:18 +01:00
metamask-extension/ui/app/pages/first-time-flow/seed-phrase/tests/confirm-seed-phrase-component.test.js
Mark Stacey 552ea136b7
Fix onboarding library integration (#9835)
The bug with our onboarding library integration was introduced in #8873
because of a change in when `completeOnboarding` was called. We hadn't
realized at the time that the onboarding integration relied upon the
onboarding completing event to know when the onboarding state should
be cleared. Because onboarding is now marked as completed earlier, the
state was cleared just as it was intended to be used.

The onboarding completed event has been moved back to where it was
before: after the user exits the "end of flow" page.

The original problem that #8873 was addressing was a routing issue,
where the user would be redirected back to the seed phrase confirmation
page despite already having confirmed their seed phrase. This was fixed
in a different way here, by updating the routing in the first time flow
switch to skip straight to the end of flow page if the seed phrase has
already been confirmed.

This does involve one user-facing change in behavior; if the user opens
any MetaMask UI before navigating away from the end-of-flow screen,
they will still be considered mid-onboarding so it'll redirect to the
end-of-flow screen. But we do mark onboarding as completed if the user
closes the tab/window while on the end of flow screen, which was
another goal of #8873.
2020-11-10 17:57:08 -03:30

188 lines
4.9 KiB
JavaScript

import assert from 'assert'
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', function () {
it('should render correctly', function () {
const root = shallowRender({
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
})
assert.equal(
root.find('.confirm-seed-phrase__seed-word--sorted').length,
12,
'should render 12 seed phrases',
)
})
it('should add/remove selected on click', function () {
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')
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()
root.find('.confirm-seed-phrase__seed-word--sorted').at(1).simulate('click')
assert.deepEqual(
root.state().selectedSeedIndices,
[0, 2],
'should remove seed phrase from selected when click again',
)
})
it('should render correctly on hover', function () {
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()
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)
})
it('should insert seed in place on drop', function () {
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()
assert.deepEqual(root.state().selectedSeedIndices, [2, 0, 1])
assert.deepEqual(root.state().pendingSeedIndices, [2, 0, 1])
})
it('should submit correctly', async function () {
const originalSeed = [
'鼠',
'牛',
'虎',
'兔',
'龍',
'蛇',
'馬',
'羊',
'猴',
'雞',
'狗',
'豬',
]
const metricsEventSpy = sinon.spy()
const pushSpy = sinon.spy()
const initialize3BoxSpy = sinon.spy()
const root = shallowRender(
{
seedPhrase: '鼠 牛 虎 兔 龍 蛇 馬 羊 猴 雞 狗 豬',
history: { push: pushSpy },
setSeedPhraseBackedUp: () => Promise.resolve(),
initializeThreeBox: initialize3BoxSpy,
},
{
metricsEvent: metricsEventSpy,
},
)
const sorted = root.state().sortedSeedWords
const seeds = root.find('.confirm-seed-phrase__seed-word--sorted')
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))
assert.deepEqual(metricsEventSpy.args[0][0], {
eventOpts: {
category: 'Onboarding',
action: 'Seed Phrase Setup',
name: 'Verify Complete',
},
})
assert(initialize3BoxSpy.calledOnce)
assert.equal(pushSpy.args[0][0], '/initialize/end-of-flow')
})
})