2020-01-30 20:34:45 +01:00
|
|
|
import assert from 'assert'
|
2020-08-18 21:18:25 +02:00
|
|
|
import React from 'react'
|
2020-01-30 20:34:45 +01:00
|
|
|
import { mountWithRouter } from '../../../../../../test/lib/render-helpers'
|
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
2020-11-09 14:50:24 +01:00
|
|
|
LOCK_ROUTE,
|
2020-01-30 20:34:45 +01:00
|
|
|
INITIALIZE_WELCOME_ROUTE,
|
|
|
|
INITIALIZE_UNLOCK_ROUTE,
|
2020-11-10 22:27:08 +01:00
|
|
|
INITIALIZE_END_OF_FLOW_ROUTE,
|
2020-01-30 20:34:45 +01:00
|
|
|
} from '../../../../helpers/constants/routes'
|
2020-08-19 18:27:05 +02:00
|
|
|
import FirstTimeFlowSwitch from '..'
|
2020-01-30 20:34:45 +01:00
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
describe('FirstTimeFlowSwitch', function () {
|
2020-11-10 22:27:08 +01:00
|
|
|
it('redirects to /welcome route with null props', function () {
|
|
|
|
const props = {
|
|
|
|
completedOnboarding: null,
|
|
|
|
isInitialized: null,
|
|
|
|
isUnlocked: null,
|
|
|
|
seedPhraseBackedUp: null,
|
|
|
|
}
|
|
|
|
const wrapper = mountWithRouter(
|
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
|
|
|
)
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper
|
|
|
|
.find('Lifecycle')
|
|
|
|
.find({ to: { pathname: INITIALIZE_WELCOME_ROUTE } }).length,
|
|
|
|
1,
|
2020-01-30 20:34:45 +01:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('redirects to / route when completedOnboarding is true', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const props = {
|
|
|
|
completedOnboarding: true,
|
|
|
|
}
|
|
|
|
const wrapper = mountWithRouter(
|
2020-07-14 17:20:41 +02:00
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
2020-01-30 20:34:45 +01:00
|
|
|
)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper.find('Lifecycle').find({ to: { pathname: DEFAULT_ROUTE } })
|
|
|
|
.length,
|
|
|
|
1,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-11-10 22:27:08 +01:00
|
|
|
it('redirects to end of flow route when seedPhraseBackedUp is true', function () {
|
|
|
|
const props = {
|
|
|
|
completedOnboarding: false,
|
|
|
|
seedPhraseBackedUp: true,
|
|
|
|
}
|
|
|
|
const wrapper = mountWithRouter(
|
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
|
|
|
)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-10 22:27:08 +01:00
|
|
|
wrapper
|
|
|
|
.find('Lifecycle')
|
|
|
|
.find({ to: { pathname: INITIALIZE_END_OF_FLOW_ROUTE } }).length,
|
|
|
|
1,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('redirects to end of flow route when seedPhraseBackedUp is false', function () {
|
|
|
|
const props = {
|
|
|
|
completedOnboarding: false,
|
|
|
|
seedPhraseBackedUp: false,
|
|
|
|
}
|
|
|
|
const wrapper = mountWithRouter(
|
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
|
|
|
)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-10 22:27:08 +01:00
|
|
|
wrapper
|
|
|
|
.find('Lifecycle')
|
|
|
|
.find({ to: { pathname: INITIALIZE_END_OF_FLOW_ROUTE } }).length,
|
|
|
|
1,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-11-09 14:50:24 +01:00
|
|
|
it('redirects to /lock route when isUnlocked is true ', function () {
|
|
|
|
const props = {
|
|
|
|
completedOnboarding: false,
|
|
|
|
isUnlocked: true,
|
2020-11-10 22:27:08 +01:00
|
|
|
seedPhraseBackedUp: null,
|
2020-11-09 14:50:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = mountWithRouter(
|
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
|
|
|
)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-09 14:50:24 +01:00
|
|
|
wrapper.find('Lifecycle').find({ to: { pathname: LOCK_ROUTE } }).length,
|
|
|
|
1,
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('redirects to /welcome route when isInitialized is false', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const props = {
|
|
|
|
completedOnboarding: false,
|
|
|
|
isUnlocked: false,
|
|
|
|
isInitialized: false,
|
2020-11-10 22:27:08 +01:00
|
|
|
seedPhraseBackedUp: null,
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = mountWithRouter(
|
2020-07-14 17:20:41 +02:00
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
2020-01-30 20:34:45 +01:00
|
|
|
)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper
|
|
|
|
.find('Lifecycle')
|
|
|
|
.find({ to: { pathname: INITIALIZE_WELCOME_ROUTE } }).length,
|
|
|
|
1,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
|
2020-02-11 17:51:13 +01:00
|
|
|
it('redirects to /unlock route when isInitialized is true', function () {
|
2020-01-30 20:34:45 +01:00
|
|
|
const props = {
|
|
|
|
completedOnboarding: false,
|
|
|
|
isUnlocked: false,
|
|
|
|
isInitialized: true,
|
2020-11-10 22:27:08 +01:00
|
|
|
seedPhraseBackedUp: null,
|
2020-01-30 20:34:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = mountWithRouter(
|
2020-07-14 17:20:41 +02:00
|
|
|
<FirstTimeFlowSwitch.WrappedComponent {...props} />,
|
2020-01-30 20:34:45 +01:00
|
|
|
)
|
|
|
|
|
2020-12-03 16:46:22 +01:00
|
|
|
assert.strictEqual(
|
2020-11-03 00:41:28 +01:00
|
|
|
wrapper
|
|
|
|
.find('Lifecycle')
|
|
|
|
.find({ to: { pathname: INITIALIZE_UNLOCK_ROUTE } }).length,
|
|
|
|
1,
|
|
|
|
)
|
2020-01-30 20:34:45 +01:00
|
|
|
})
|
|
|
|
})
|