mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-17 21:53:03 +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)
|
.filter((account) => account.id !== payload.id)
|
||||||
.concat(payload);
|
.concat(payload);
|
||||||
|
|
||||||
|
state.available.sort((account1, account2) => {
|
||||||
|
if (account1.username === account2.username) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return account1.username > account2.username ? 1 : -1;
|
||||||
|
});
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
|
||||||
case ACTIVATE:
|
case ACTIVATE:
|
||||||
|
@ -56,13 +56,26 @@ describe('Accounts reducer', () => {
|
|||||||
token: 'newToken'
|
token: 'newToken'
|
||||||
};
|
};
|
||||||
|
|
||||||
return expect(
|
expect(
|
||||||
accounts({...initial, available: [outdatedAccount]}, add(updatedAccount)),
|
accounts({...initial, available: [outdatedAccount]}, add(updatedAccount)),
|
||||||
'to satisfy', {
|
'to satisfy', {
|
||||||
available: [updatedAccount]
|
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', () => {
|
it('throws, when account is invalid', () => {
|
||||||
expect(() => accounts(initial, add()),
|
expect(() => accounts(initial, add()),
|
||||||
'to throw', 'Invalid or empty payload passed for accounts.add');
|
'to throw', 'Invalid or empty payload passed for accounts.add');
|
||||||
|
Loading…
Reference in New Issue
Block a user