@ -1,5 +1,6 @@
import configureMockStore from 'redux-mock-store' ;
import React from 'react' ;
import { mountWithRout er } from '../../../../test/lib/render-helpers' ;
import { renderWithProvid er } from '../../../../test/lib/render-helpers' ;
import {
DEFAULT _ROUTE ,
LOCK _ROUTE ,
@ -11,118 +12,112 @@ import FirstTimeFlowSwitch from './first-time-flow-switch.container';
describe ( 'FirstTimeFlowSwitch' , ( ) => {
it ( 'redirects to /welcome route with null props' , ( ) => {
const props = {
completedOnboarding : null ,
isInitialized : null ,
isUnlocked : null ,
seedPhraseBackedUp : null ,
const mockState = {
metamask : {
completedOnboarding : null ,
isInitialized : null ,
isUnlocked : null ,
seedPhraseBackedUp : null ,
} ,
} ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
expect (
wrapper
. find ( 'Lifecycle' )
. find ( { to : { pathname : INITIALIZE _WELCOME _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const store = configureMockStore ( ) ( mockState ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual ( INITIALIZE _WELCOME _ROUTE ) ;
} ) ;
it ( 'redirects to / route when completedOnboarding is true' , ( ) => {
const props = {
completedOnboarding : true ,
const mockState = {
metamask : {
completedOnboarding : true ,
isInitialized : null ,
isUnlocked : null ,
seedPhraseBackedUp : null ,
} ,
} ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
const store = configureMockStore ( ) ( mockState ) ;
expect (
wrapper . find ( 'Lifecycle' ) . find ( { to : { pathname : DEFAULT _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual ( DEFAULT _ROUTE ) ;
} ) ;
it ( 'redirects to end of flow route when seedPhraseBackedUp is true' , ( ) => {
const props = {
completedOnboarding : false ,
seedPhraseBackedUp : true ,
const mockState = {
metamask : {
completedOnboarding : false ,
seedPhraseBackedUp : true ,
isInitialized : null ,
isUnlocked : null ,
} ,
} ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
const store = configureMockStore ( ) ( mockState ) ;
expect (
wrapper
. find ( 'Lifecycle' )
. find ( { to : { pathname : INITIALIZE _END _OF _FLOW _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual (
INITIALIZE _END _OF _FLOW _ROUTE ,
) ;
} ) ;
it ( 'redirects to end of flow route when seedPhraseBackedUp is false' , ( ) => {
const props = {
completedOnboarding : false ,
seedPhraseBackedUp : false ,
const mockState = {
metamask : {
completedOnboarding : false ,
seedPhraseBackedUp : false ,
isInitialized : null ,
isUnlocked : null ,
} ,
} ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
const store = configureMockStore ( ) ( mockState ) ;
expect (
wrapper
. find ( 'Lifecycle' )
. find ( { to : { pathname : INITIALIZE _END _OF _FLOW _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual (
INITIALIZE _END _OF _FLOW _ROUTE ,
) ;
} ) ;
it ( 'redirects to /lock route when isUnlocked is true' , ( ) => {
const props = {
completedOnboarding : false ,
isUnlocked : true ,
seedPhraseBackedUp : null ,
const mockState = {
metamask : {
completedOnboarding : false ,
isUnlocked : true ,
seedPhraseBackedUp : null ,
isInitialized : null ,
} ,
} ;
const store = configureMockStore ( ) ( mockState ) ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
expect (
wrapper . find ( 'Lifecycle' ) . find ( { to : { pathname : LOCK _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual ( LOCK _ROUTE ) ;
} ) ;
it ( 'redirects to /welcome route when isInitialized is false' , ( ) => {
const props = {
completedOnboarding : false ,
isUnlocked : false ,
isInitialized : false ,
seedPhraseBackedUp : null ,
const mockState = {
metamask : {
completedOnboarding : false ,
isUnlocked : false ,
isInitialized : false ,
seedPhraseBackedUp : null ,
} ,
} ;
const store = configureMockStore ( ) ( mockState ) ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
expect (
wrapper
. find ( 'Lifecycle' )
. find ( { to : { pathname : INITIALIZE _WELCOME _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual ( INITIALIZE _WELCOME _ROUTE ) ;
} ) ;
it ( 'redirects to /unlock route when isInitialized is true' , ( ) => {
const props = {
completedOnboarding : false ,
isUnlocked : false ,
isInitialized : true ,
seedPhraseBackedUp : null ,
const mockState = {
metamask : {
completedOnboarding : false ,
isUnlocked : false ,
isInitialized : true ,
seedPhraseBackedUp : null ,
} ,
} ;
const store = configureMockStore ( ) ( mockState ) ;
const wrapper = mountWithRouter (
< FirstTimeFlowSwitch . WrappedComponent { ... props } / > ,
) ;
expect (
wrapper
. find ( 'Lifecycle' )
. find ( { to : { pathname : INITIALIZE _UNLOCK _ROUTE } } ) ,
) . toHaveLength ( 1 ) ;
const { history } = renderWithProvider ( < FirstTimeFlowSwitch / > , store ) ;
expect ( history . location . pathname ) . toStrictEqual ( INITIALIZE _UNLOCK _ROUTE ) ;
} ) ;
} ) ;