diff options
Diffstat (limited to 'test/unit/ui')
-rw-r--r-- | test/unit/ui/app/actions.spec.js | 247 | ||||
-rw-r--r-- | test/unit/ui/app/reducers/app.spec.js | 15 | ||||
-rw-r--r-- | test/unit/ui/app/reducers/metamask.spec.js | 58 |
3 files changed, 27 insertions, 293 deletions
diff --git a/test/unit/ui/app/actions.spec.js b/test/unit/ui/app/actions.spec.js index 34dd6a39b..5bf82a185 100644 --- a/test/unit/ui/app/actions.spec.js +++ b/test/unit/ui/app/actions.spec.js @@ -134,95 +134,25 @@ describe('Actions', () => { }) }) - describe('#confirmSeedWords', () => { - - let clearSeedWordCacheSpy - - afterEach(() => { - clearSeedWordCacheSpy.restore() - }) - - it('shows account page after clearing seed word cache', () => { - - const store = mockStore({}) - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'HIDE_LOADING_INDICATION' }, - { type: 'SHOW_ACCOUNTS_PAGE' }, - ] - - clearSeedWordCacheSpy = sinon.spy(background, 'clearSeedWordCache') - - return store.dispatch(actions.confirmSeedWords()) - .then(() => { - assert.equal(clearSeedWordCacheSpy.callCount, 1) - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - - it('errors in callback will display warning', () => { - const store = mockStore({}) - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'HIDE_LOADING_INDICATION' }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - clearSeedWordCacheSpy = sinon.stub(background, 'clearSeedWordCache') - - clearSeedWordCacheSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.confirmSeedWords()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#createNewVaultAndRestore', () => { - let createNewVaultAndRestoreSpy, clearSeedWordCacheSpy + let createNewVaultAndRestoreSpy afterEach(() => { createNewVaultAndRestoreSpy.restore() }) - it('clears seed words and restores new vault', () => { + it('restores new vault', () => { const store = mockStore({}) createNewVaultAndRestoreSpy = sinon.spy(background, 'createNewVaultAndRestore') - clearSeedWordCacheSpy = sinon.spy(background, 'clearSeedWordCache') return store.dispatch(actions.createNewVaultAndRestore()) .catch(() => { - assert(clearSeedWordCacheSpy.calledOnce) assert(createNewVaultAndRestoreSpy.calledOnce) }) }) - it('errors when callback in clearSeedWordCache throws', () => { - const store = mockStore() - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - { type: 'HIDE_LOADING_INDICATION' }, - ] - - clearSeedWordCacheSpy = sinon.stub(background, 'clearSeedWordCache') - clearSeedWordCacheSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.createNewVaultAndRestore()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - it('errors when callback in createNewVaultAndRestore throws', () => { const store = mockStore({}) @@ -246,113 +176,6 @@ describe('Actions', () => { }) }) - describe('#createNewVaultAndKeychain', () => { - - let createNewVaultAndKeychainSpy, placeSeedWordsSpy - - afterEach(() => { - createNewVaultAndKeychainSpy.restore() - placeSeedWordsSpy.restore() - }) - - it('calls createNewVaultAndKeychain and placeSeedWords in background', () => { - - const store = mockStore() - - createNewVaultAndKeychainSpy = sinon.spy(background, 'createNewVaultAndKeychain') - placeSeedWordsSpy = sinon.spy(background, 'placeSeedWords') - - return store.dispatch(actions.createNewVaultAndKeychain()) - .then(() => { - assert(createNewVaultAndKeychainSpy.calledOnce) - assert(placeSeedWordsSpy.calledOnce) - }) - }) - - it('displays error and value when callback errors', () => { - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - { type: 'HIDE_LOADING_INDICATION' }, - ] - - createNewVaultAndKeychainSpy = sinon.stub(background, 'createNewVaultAndKeychain') - createNewVaultAndKeychainSpy.callsFake((_, callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.createNewVaultAndKeychain()) - .then(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - - }) - - it('errors when placeSeedWords throws', () => { - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - { type: 'HIDE_LOADING_INDICATION' }, - ] - - placeSeedWordsSpy = sinon.stub(background, 'placeSeedWords') - placeSeedWordsSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.createNewVaultAndKeychain()) - .then(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - - describe('#requestRevealSeed', () => { - - let submitPasswordSpy, placeSeedWordsSpy - - afterEach(() => { - submitPasswordSpy.restore() - }) - - it('calls submitPassword and placeSeedWords from background', () => { - - const store = mockStore() - - submitPasswordSpy = sinon.spy(background, 'submitPassword') - placeSeedWordsSpy = sinon.spy(background, 'placeSeedWords') - - return store.dispatch(actions.requestRevealSeed()) - .then(() => { - assert(submitPasswordSpy.calledOnce) - assert(placeSeedWordsSpy.calledOnce) - }) - }) - - it('displays warning error with value when callback errors', () => { - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - submitPasswordSpy = sinon.stub(background, 'submitPassword') - submitPasswordSpy.callsFake((_, callback) => { - callback(new Error('error')) - }) - - return store.dispatch(actions.requestRevealSeed()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#requestRevealSeedWords', () => { let submitPasswordSpy @@ -389,68 +212,6 @@ describe('Actions', () => { }) }) - describe('#requestRevealSeed', () => { - - let submitPasswordSpy, placeSeedWordsSpy - - afterEach(() => { - submitPasswordSpy.restore() - placeSeedWordsSpy.restore() - }) - - it('calls submitPassword and placeSeedWords in background', () => { - - const store = mockStore() - - submitPasswordSpy = sinon.spy(background, 'submitPassword') - placeSeedWordsSpy = sinon.spy(background, 'placeSeedWords') - - return store.dispatch(actions.requestRevealSeed()) - .then(() => { - assert(submitPasswordSpy.calledOnce) - assert(placeSeedWordsSpy.calledOnce) - }) - }) - - it('displays warning error message when submitPassword in background errors', () => { - submitPasswordSpy = sinon.stub(background, 'submitPassword') - submitPasswordSpy.callsFake((_, callback) => { - callback(new Error('error')) - }) - - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - return store.dispatch(actions.requestRevealSeed()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - - it('errors when placeSeedWords throw', () => { - placeSeedWordsSpy = sinon.stub(background, 'placeSeedWords') - placeSeedWordsSpy.callsFake((callback) => { - callback(new Error('error')) - }) - - const store = mockStore() - - const expectedActions = [ - { type: 'SHOW_LOADING_INDICATION', value: undefined }, - { type: 'DISPLAY_WARNING', value: 'error' }, - ] - - return store.dispatch(actions.requestRevealSeed()) - .catch(() => { - assert.deepEqual(store.getActions(), expectedActions) - }) - }) - }) - describe('#removeAccount', () => { let removeAccountSpy @@ -867,7 +628,7 @@ describe('Actions', () => { { type: 'DISPLAY_WARNING', value: 'error' }, { type: 'HIDE_LOADING_INDICATION' }, { type: 'LOCK_METAMASK' }, - ] + ] backgroundSetLockedSpy = sinon.stub(background, 'setLocked') backgroundSetLockedSpy.callsFake(callback => { callback(new Error('error')) @@ -1108,7 +869,7 @@ describe('Actions', () => { }) it('', () => { - const store = mockStore() + const store = mockStore({ metamask: devState }) store.dispatch(actions.addToAddressBook('test')) assert(addToAddressBookSpy.calledOnce) }) diff --git a/test/unit/ui/app/reducers/app.spec.js b/test/unit/ui/app/reducers/app.spec.js index 09cf3dbf0..6f8dd920c 100644 --- a/test/unit/ui/app/reducers/app.spec.js +++ b/test/unit/ui/app/reducers/app.spec.js @@ -270,18 +270,6 @@ describe('App State', () => { assert.equal(state.isLoading, true) }) - it('shows new vault seed', () => { - const state = reduceApp(metamaskState, { - type: actions.SHOW_NEW_VAULT_SEED, - value: 'test seed words', - }) - - assert.equal(state.currentView.name, 'createVaultComplete') - assert.equal(state.currentView.seedWords, 'test seed words') - assert.equal(state.transForward, true) - assert.equal(state.isLoading, false) - }) - it('shows new account screen', () => { const state = reduceApp(metamaskState, { type: actions.NEW_ACCOUNT_SCREEN, @@ -437,7 +425,6 @@ describe('App State', () => { }) assert.equal(state.currentView.name, 'accounts') - assert.equal(state.currentView.seedWords, undefined) assert.equal(state.transForward, true) assert.equal(state.isLoading, false) assert.equal(state.warning, null) @@ -700,7 +687,7 @@ describe('App State', () => { }) it('hides sub loading indicator', () => { - const oldState = {...metamaskState, ...oldState} + const oldState = {...metamaskState, isSubLoading: true } const state = reduceApp(oldState, { type: actions.HIDE_SUB_LOADING_INDICATION, }) diff --git a/test/unit/ui/app/reducers/metamask.spec.js b/test/unit/ui/app/reducers/metamask.spec.js index d7876bf39..714bd476a 100644 --- a/test/unit/ui/app/reducers/metamask.spec.js +++ b/test/unit/ui/app/reducers/metamask.spec.js @@ -9,32 +9,6 @@ describe('MetaMask Reducers', () => { assert(initState) }) - it('sets revealing seed to true and adds seed words to new state', () => { - const seedWordsState = reduceMetamask({}, { - type: actions.SHOW_NEW_VAULT_SEED, - value: 'test seed words', - }) - - assert.equal(seedWordsState.seedWords, 'test seed words') - assert.equal(seedWordsState.isRevealingSeedWords, true) - }) - - it('shows account page', () => { - const seedWordsState = { - metamask: { - seedwords: 'test seed words', - isRevealing: true, - }, - } - - const state = reduceMetamask(seedWordsState, { - type: actions.SHOW_ACCOUNTS_PAGE, - }) - - assert.equal(state.seedWords, undefined) - assert.equal(state.isRevealingSeedWords, false) - }) - it('unlocks MetaMask', () => { const state = reduceMetamask({}, { type: actions.UNLOCK_METAMASK, @@ -152,16 +126,6 @@ describe('MetaMask Reducers', () => { }) }) - it('shows new vault seed words and sets isRevealingSeedWords to true', () => { - const showNewVaultSeedState = reduceMetamask({}, { - type: actions.SHOW_NEW_VAULT_SEED, - value: 'test seed words', - }) - - assert.equal(showNewVaultSeedState.isRevealingSeedWords, true) - assert.equal(showNewVaultSeedState.seedWords, 'test seed words') - }) - it('shows account detail', () => { const state = reduceMetamask({}, { @@ -345,6 +309,8 @@ describe('MetaMask Reducers', () => { errors: {}, editingTransactionId: 22, forceGasMin: '0xGas', + ensResolution: null, + ensResolutionError: '', } const sendState = reduceMetamask({}, { @@ -528,4 +494,24 @@ describe('MetaMask Reducers', () => { assert.deepEqual(state.pendingTokens, {}) }) + + it('update ensResolution', () => { + const state = reduceMetamask({}, { + type: actions.UPDATE_SEND_ENS_RESOLUTION, + payload: '0x1337', + }) + + assert.deepEqual(state.send.ensResolution, '0x1337') + assert.deepEqual(state.send.ensResolutionError, '') + }) + + it('update ensResolutionError', () => { + const state = reduceMetamask({}, { + type: actions.UPDATE_SEND_ENS_RESOLUTION_ERROR, + payload: 'ens name not found', + }) + + assert.deepEqual(state.send.ensResolutionError, 'ens name not found') + assert.deepEqual(state.send.ensResolution, null) + }) }) |