This repository has been archived by the owner on Jun 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assign account index to accounts in state (#715)
* feat: add read-only (account) index to account info for each account * fix: order account names by account index * feat: add ability to auto assign account index to existing accounts in account state * Reorder account indexes on account deletion
- Loading branch information
1 parent
ced0b49
commit 80fe0ae
Showing
8 changed files
with
231 additions
and
160 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
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
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,64 @@ | ||
import configureMockStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
import { expect } from 'chai'; | ||
import * as actions from '../../actions/accounts'; | ||
|
||
const middlewares = [thunk]; | ||
const mockStore = configureMockStore(middlewares); | ||
|
||
describe('actions: accounts', () => { | ||
describe('#assignAccountIndexIfNecessary', () => { | ||
describe('provided param is empty', () => { | ||
it('should not create an action of type IOTA/ACCOUNTS/ASSIGN_ACCOUNT_INDEX', () => { | ||
const store = mockStore({}); | ||
|
||
// Dispatch action | ||
store.dispatch(actions.assignAccountIndexIfNecessary({})); | ||
|
||
expect(store.getActions()).to.eql([]); | ||
}); | ||
}); | ||
|
||
describe('provided param is not empty', () => { | ||
describe('when some accounts in accountInfo object have an index property with a non-numeric value', () => { | ||
it('should not create an action of type IOTA/ACCOUNTS/ASSIGN_ACCOUNT_INDEX', () => { | ||
const store = mockStore({}); | ||
|
||
let accountInfo = { foo: {}, baz: { index: 2 } }; | ||
|
||
const expectedActions = [ | ||
{ | ||
type: 'IOTA/ACCOUNTS/ASSIGN_ACCOUNT_INDEX', | ||
}, | ||
]; | ||
|
||
// Dispatch action | ||
store.dispatch(actions.assignAccountIndexIfNecessary(accountInfo)); | ||
expect(store.getActions()).to.eql(expectedActions); | ||
|
||
// Clear actions | ||
store.clearActions(); | ||
|
||
// Reassign account info and check for undefined values | ||
accountInfo = { foo: { index: undefined }, baz: { index: 1 } }; | ||
|
||
// Dispatch action | ||
store.dispatch(actions.assignAccountIndexIfNecessary(accountInfo)); | ||
expect(store.getActions()).to.eql(expectedActions); | ||
}); | ||
}); | ||
|
||
describe('when every account in accountInfo object has an index property with a numeric value', () => { | ||
it('should not create an action of type IOTA/ACCOUNTS/ASSIGN_ACCOUNT_INDEX', () => { | ||
const store = mockStore({}); | ||
|
||
const accountInfo = { foo: { index: 0 }, baz: { index: 1 } }; | ||
|
||
// Dispatch action | ||
store.dispatch(actions.assignAccountIndexIfNecessary(accountInfo)); | ||
expect(store.getActions()).to.eql([]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.