mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-30 15:29:33 +05:30
#48: add account sorting
This commit is contained in:
parent
420ce65392
commit
81a5437be0
@ -30,6 +30,14 @@ export default function accounts(
|
||||
.filter((account) => account.id !== payload.id)
|
||||
.concat(payload);
|
||||
|
||||
state.available.sort((account1, account2) => {
|
||||
if (account1.username === account2.username) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return account1.username > account2.username ? 1 : -1;
|
||||
});
|
||||
|
||||
return state;
|
||||
|
||||
case ACTIVATE:
|
||||
|
@ -56,13 +56,26 @@ describe('Accounts reducer', () => {
|
||||
token: 'newToken'
|
||||
};
|
||||
|
||||
return expect(
|
||||
expect(
|
||||
accounts({...initial, available: [outdatedAccount]}, add(updatedAccount)),
|
||||
'to satisfy', {
|
||||
available: [updatedAccount]
|
||||
});
|
||||
});
|
||||
|
||||
it('should sort accounts by username', () => {
|
||||
const newAccount = {
|
||||
...account,
|
||||
id: 2,
|
||||
username: 'abc'
|
||||
};
|
||||
|
||||
expect(accounts({...initial, available: [account]}, add(newAccount)),
|
||||
'to satisfy', {
|
||||
available: [newAccount, account]
|
||||
});
|
||||
});
|
||||
|
||||
it('throws, when account is invalid', () => {
|
||||
expect(() => accounts(initial, add()),
|
||||
'to throw', 'Invalid or empty payload passed for accounts.add');
|
||||
|
Loading…
x
Reference in New Issue
Block a user