This repository has been archived by the owner on Apr 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for savedAccounts middleware
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { expect } from 'chai'; | ||
import { spy, mock } from 'sinon'; | ||
|
||
import { accountLoggedOut } from '../../actions/account'; | ||
import { successToastDisplayed } from '../../actions/toaster'; | ||
import actionTypes from '../../constants/actions'; | ||
import middleware from './savedAccounts'; | ||
|
||
describe('SavedAccounts middleware', () => { | ||
let store; | ||
let next; | ||
|
||
beforeEach(() => { | ||
store = mock(); | ||
store.dispatch = spy(); | ||
store.getState = () => ({}); | ||
|
||
next = spy(); | ||
}); | ||
|
||
it('should pass the action to next middleware', () => { | ||
const randomAction = { | ||
type: 'SOME_ACTION', | ||
data: { something: true }, | ||
}; | ||
|
||
middleware(store)(next)(randomAction); | ||
expect(next).to.have.been.calledWith(randomAction); | ||
}); | ||
|
||
it(`should dispatch successToastDisplayed action on ${actionTypes.accountSaved} action`, () => { | ||
const action = { | ||
type: actionTypes.accountSaved, | ||
data: {}, | ||
}; | ||
middleware(store)(next)(action); | ||
expect(store.dispatch).to.have.been.calledWith(successToastDisplayed({ label: 'Account saved' })); | ||
}); | ||
|
||
it(`should dispatch successToastDisplayed action on ${actionTypes.accountRemoved} action`, () => { | ||
const action = { | ||
type: actionTypes.accountRemoved, | ||
data: {}, | ||
}; | ||
middleware(store)(next)(action); | ||
expect(store.dispatch).to.have.been.calledWith(successToastDisplayed({ label: 'Account was successfully forgotten.' })); | ||
}); | ||
|
||
it(`should dispatch accountLoggedOut action on ${actionTypes.accountSwitched} action`, () => { | ||
const action = { | ||
type: actionTypes.accountSwitched, | ||
data: { | ||
publicKey: '', | ||
network: 0, | ||
}, | ||
}; | ||
middleware(store)(next)(action); | ||
expect(store.dispatch).to.have.been.calledWith(accountLoggedOut()); | ||
}); | ||
}); |