1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-05 23:44:56 +01:00
metamask-extension/ui/pages/first-time-flow/first-time-flow-switch/first-time-flow-switch.test.js

124 lines
3.6 KiB
JavaScript
Raw Normal View History

import configureMockStore from 'redux-mock-store';
import React from 'react';
import { renderWithProvider } from '../../../../test/lib/render-helpers';
import {
DEFAULT_ROUTE,
LOCK_ROUTE,
INITIALIZE_WELCOME_ROUTE,
INITIALIZE_UNLOCK_ROUTE,
INITIALIZE_END_OF_FLOW_ROUTE,
} from '../../../helpers/constants/routes';
import FirstTimeFlowSwitch from './first-time-flow-switch.container';
describe('FirstTimeFlowSwitch', () => {
it('redirects to /welcome route with null props', () => {
const mockState = {
metamask: {
completedOnboarding: null,
isInitialized: null,
isUnlocked: null,
seedPhraseBackedUp: null,
},
};
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 mockState = {
metamask: {
completedOnboarding: true,
isInitialized: null,
isUnlocked: null,
seedPhraseBackedUp: null,
},
};
const store = configureMockStore()(mockState);
const { history } = renderWithProvider(<FirstTimeFlowSwitch />, store);
expect(history.location.pathname).toStrictEqual(DEFAULT_ROUTE);
});
it('redirects to end of flow route when seedPhraseBackedUp is true', () => {
const mockState = {
metamask: {
completedOnboarding: false,
seedPhraseBackedUp: true,
isInitialized: null,
isUnlocked: null,
},
};
const store = configureMockStore()(mockState);
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 mockState = {
metamask: {
completedOnboarding: false,
seedPhraseBackedUp: false,
isInitialized: null,
isUnlocked: null,
},
};
const store = configureMockStore()(mockState);
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 mockState = {
metamask: {
completedOnboarding: false,
isUnlocked: true,
seedPhraseBackedUp: null,
isInitialized: null,
},
};
const store = configureMockStore()(mockState);
const { history } = renderWithProvider(<FirstTimeFlowSwitch />, store);
expect(history.location.pathname).toStrictEqual(LOCK_ROUTE);
});
it('redirects to /welcome route when isInitialized is false', () => {
const mockState = {
metamask: {
completedOnboarding: false,
isUnlocked: false,
isInitialized: false,
seedPhraseBackedUp: null,
},
};
const store = configureMockStore()(mockState);
const { history } = renderWithProvider(<FirstTimeFlowSwitch />, store);
expect(history.location.pathname).toStrictEqual(INITIALIZE_WELCOME_ROUTE);
});
it('redirects to /unlock route when isInitialized is true', () => {
const mockState = {
metamask: {
completedOnboarding: false,
isUnlocked: false,
isInitialized: true,
seedPhraseBackedUp: null,
},
};
const store = configureMockStore()(mockState);
const { history } = renderWithProvider(<FirstTimeFlowSwitch />, store);
expect(history.location.pathname).toStrictEqual(INITIALIZE_UNLOCK_ROUTE);
});
});