Isolate variables to individual tests

feature/default_network_editable
Thomas 6 years ago
parent be3f411a60
commit 611a61b7bc
  1. 117
      test/unit/ui/app/reducers/app.spec.js

@ -3,19 +3,6 @@ import reduceApp from '../../../../../ui/app/reducers/app'
import * as actions from '../../../../../ui/app/actions' import * as actions from '../../../../../ui/app/actions'
describe('App State', () => { describe('App State', () => {
let initState,
dropdownOpen,
openSidebar,
alertOpen,
opensModal,
transitionForwardState,
errorState,
loadingState,
subLoadingIndicatorState,
displayWarningState,
requestAccountExportState,
buyEthState,
gasLoadingState
const metamaskState = { const metamaskState = {
metamask: { metamask: {
@ -30,21 +17,22 @@ describe('App State', () => {
} }
it('App init state', () => { it('App init state', () => {
initState = reduceApp(metamaskState, {}) const initState = reduceApp(metamaskState, {})
assert(initState) assert(initState)
}) })
it('sets networkd dropdown to true', () => { it('sets networkd dropdown to true', () => {
dropdownOpen = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.NETWORK_DROPDOWN_OPEN, type: actions.NETWORK_DROPDOWN_OPEN,
}) })
assert.equal(dropdownOpen.networkDropdownOpen, true) assert.equal(state.networkDropdownOpen, true)
}) })
it('sets networkd dropdown to false', () => { it('sets networkd dropdown to false', () => {
const state = {...metamaskState, ...dropdownOpen} const dropdown = { networkDropdowopen: true }
const state = {...metamaskState, ...dropdown}
const newState = reduceApp(state, { const newState = reduceApp(state, {
type: actions.NETWORK_DROPDOWN_CLOSE, type: actions.NETWORK_DROPDOWN_CLOSE,
}) })
@ -58,15 +46,16 @@ describe('App State', () => {
'type': 'wallet-view', 'type': 'wallet-view',
'isOpen': true, 'isOpen': true,
} }
openSidebar = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.SIDEBAR_OPEN, type: actions.SIDEBAR_OPEN,
value, value,
}) })
assert.deepEqual(openSidebar.sidebar, value) assert.deepEqual(state.sidebar, value)
}) })
it('closes sidebar', () => { it('closes sidebar', () => {
const openSidebar = { sidebar: { isOpen: true }}
const state = {...metamaskState, ...openSidebar} const state = {...metamaskState, ...openSidebar}
const newState = reduceApp(state, { const newState = reduceApp(state, {
@ -77,17 +66,18 @@ describe('App State', () => {
}) })
it('opens alert', () => { it('opens alert', () => {
alertOpen = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.ALERT_OPEN, type: actions.ALERT_OPEN,
value: 'test message', value: 'test message',
}) })
assert.equal(alertOpen.alertOpen, true) assert.equal(state.alertOpen, true)
assert.equal(alertOpen.alertMessage, 'test message') assert.equal(state.alertMessage, 'test message')
}) })
it('closes alert', () => { it('closes alert', () => {
const state = {...metamaskState, ...alertOpen} const alert = { alertOpen: true, alertMessage: 'test message' }
const state = {...metamaskState, ...alert}
const newState = reduceApp(state, { const newState = reduceApp(state, {
type: actions.ALERT_CLOSE, type: actions.ALERT_CLOSE,
}) })
@ -106,18 +96,27 @@ describe('App State', () => {
}) })
it('opens modal', () => { it('opens modal', () => {
opensModal = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.MODAL_OPEN, type: actions.MODAL_OPEN,
payload: { payload: {
name: 'test', name: 'test',
}, },
}) })
assert.equal(opensModal.modal.open, true) assert.equal(state.modal.open, true)
assert.equal(opensModal.modal.modalState.name, 'test') assert.equal(state.modal.modalState.name, 'test')
}) })
it('closes modal, but moves open modal state to previous modal state', () => { it('closes modal, but moves open modal state to previous modal state', () => {
const opensModal = {
modal: {
open: true,
modalState: {
name: 'test',
},
},
}
const state = { ...metamaskState, appState: { ...opensModal } } const state = { ...metamaskState, appState: { ...opensModal } }
const newState = reduceApp(state, { const newState = reduceApp(state, {
type: actions.MODAL_CLOSE, type: actions.MODAL_CLOSE,
@ -129,14 +128,16 @@ describe('App State', () => {
}) })
it('tansitions forwards', () => { it('tansitions forwards', () => {
transitionForwardState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.TRANSITION_FORWARD, type: actions.TRANSITION_FORWARD,
}) })
assert.equal(transitionForwardState.transForward, true) assert.equal(state.transForward, true)
}) })
it('transition backwards', () => { it('transition backwards', () => {
const transitionForwardState = { transitionForward: true }
const state = { ...metamaskState, ...transitionForwardState } const state = { ...metamaskState, ...transitionForwardState }
const newState = reduceApp(state, { const newState = reduceApp(state, {
type: actions.TRANSITION_BACKWARD, type: actions.TRANSITION_BACKWARD,
@ -644,15 +645,16 @@ describe('App State', () => {
}) })
it('sets default warning when unlock fails', () => { it('sets default warning when unlock fails', () => {
errorState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.UNLOCK_FAILED, type: actions.UNLOCK_FAILED,
value: 'errors', value: 'errors',
}) })
assert.equal(errorState.warning, 'errors') assert.equal(state.warning, 'errors')
}) })
it('sets warning to empty string when unlock succeeds', () => { it('sets warning to empty string when unlock succeeds', () => {
const errorState = { warning: 'errors' }
const oldState = {...metamaskState, ...errorState} const oldState = {...metamaskState, ...errorState}
const state = reduceApp(oldState, { const state = reduceApp(oldState, {
type: actions.UNLOCK_SUCCEEDED, type: actions.UNLOCK_SUCCEEDED,
@ -678,16 +680,17 @@ describe('App State', () => {
}) })
it('shows loading message', () => { it('shows loading message', () => {
loadingState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.SHOW_LOADING, type: actions.SHOW_LOADING,
value: 'loading', value: 'loading',
}) })
assert.equal(loadingState.isLoading, true) assert.equal(state.isLoading, true)
assert.equal(loadingState.loadingMessage, 'loading') assert.equal(state.loadingMessage, 'loading')
}) })
it('hides loading message', () => { it('hides loading message', () => {
const loadingState = { isLoading: true}
const oldState = {...metamaskState, ...loadingState} const oldState = {...metamaskState, ...loadingState}
const state = reduceApp(oldState, { const state = reduceApp(oldState, {
@ -698,11 +701,11 @@ describe('App State', () => {
}) })
it('shows sub loading indicator', () => { it('shows sub loading indicator', () => {
subLoadingIndicatorState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.SHOW_SUB_LOADING_INDICATION, type: actions.SHOW_SUB_LOADING_INDICATION,
}) })
assert.equal(subLoadingIndicatorState.isSubLoading, true) assert.equal(state.isSubLoading, true)
}) })
it('hides sub loading indicator', () => { it('hides sub loading indicator', () => {
@ -715,16 +718,17 @@ describe('App State', () => {
}) })
it('displays warning', () => { it('displays warning', () => {
displayWarningState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.DISPLAY_WARNING, type: actions.DISPLAY_WARNING,
value: 'warning', value: 'warning',
}) })
assert.equal(displayWarningState.isLoading, false) assert.equal(state.isLoading, false)
assert.equal(displayWarningState.warning, 'warning') assert.equal(state.warning, 'warning')
}) })
it('hides warning', () => { it('hides warning', () => {
const displayWarningState = { warning: 'warning'}
const oldState = {...metamaskState, ...displayWarningState} const oldState = {...metamaskState, ...displayWarningState}
const state = reduceApp(oldState, { const state = reduceApp(oldState, {
type: actions.HIDE_WARNING, type: actions.HIDE_WARNING,
@ -734,16 +738,22 @@ describe('App State', () => {
}) })
it('request to display account export', () => { it('request to display account export', () => {
requestAccountExportState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.REQUEST_ACCOUNT_EXPORT, type: actions.REQUEST_ACCOUNT_EXPORT,
}) })
assert.equal(requestAccountExportState.transForward, true) assert.equal(state.transForward, true)
assert.equal(requestAccountExportState.accountDetail.subview, 'export') assert.equal(state.accountDetail.subview, 'export')
assert.equal(requestAccountExportState.accountDetail.accountExport, 'requested') assert.equal(state.accountDetail.accountExport, 'requested')
}) })
it('completes account export', () => { it('completes account export', () => {
const requestAccountExportState = {
accountDetail: {
subview: 'something',
accountExport: 'progress',
},
}
const oldState = {...metamaskState, ...requestAccountExportState} const oldState = {...metamaskState, ...requestAccountExportState}
const state = reduceApp(oldState, { const state = reduceApp(oldState, {
type: actions.EXPORT_ACCOUNT, type: actions.EXPORT_ACCOUNT,
@ -766,19 +776,19 @@ describe('App State', () => {
it('shows buy eth view', () => { it('shows buy eth view', () => {
buyEthState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.BUY_ETH_VIEW, type: actions.BUY_ETH_VIEW,
value: '0xAddress', value: '0xAddress',
}) })
assert.equal(buyEthState.currentView.name, 'buyEth') assert.equal(state.currentView.name, 'buyEth')
assert.equal(buyEthState.currentView.context, 'accountDetail') assert.equal(state.currentView.context, 'accountDetail')
assert.equal(buyEthState.identity.address, '0xAddress') assert.equal(state.identity.address, '0xAddress')
assert.equal(buyEthState.buyView.subview, 'Coinbase') assert.equal(state.buyView.subview, 'Coinbase')
assert.equal(buyEthState.buyView.amount, '15.00') assert.equal(state.buyView.amount, '15.00')
assert.equal(buyEthState.buyView.buyAddress, '0xAddress') assert.equal(state.buyView.buyAddress, '0xAddress')
assert.equal(buyEthState.buyView.formView.coinbase, true) assert.equal(state.buyView.formView.coinbase, true)
assert.equal(buyEthState.buyView.formView.shapeshift, false) assert.equal(state.buyView.formView.shapeshift, false)
}) })
it('shows onboarding subview to buy eth', () => { it('shows onboarding subview to buy eth', () => {
@ -960,14 +970,15 @@ describe('App State', () => {
}) })
it('sets gas loading', () => { it('sets gas loading', () => {
gasLoadingState = reduceApp(metamaskState, { const state = reduceApp(metamaskState, {
type: actions.GAS_LOADING_STARTED, type: actions.GAS_LOADING_STARTED,
}) })
assert.equal(gasLoadingState.gasIsLoading, true) assert.equal(state.gasIsLoading, true)
}) })
it('unsets gas loading', () => { it('unsets gas loading', () => {
const gasLoadingState = { gasIsLoading: true }
const oldState = {...metamaskState, ...gasLoadingState} const oldState = {...metamaskState, ...gasLoadingState}
const state = reduceApp(oldState, { const state = reduceApp(oldState, {
type: actions.GAS_LOADING_FINISHED, type: actions.GAS_LOADING_FINISHED,

Loading…
Cancel
Save