Skip to content

Commit

Permalink
fix(user): sort user by name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Pickel committed Jan 9, 2019
1 parent f07dd0d commit 61c1742
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/store/reducers/__tests__/user.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ describe('action creators', () => {

describe('selectors', () => {
describe('getUserArray', () => {
it('returns the current user map as an arry', () => {
it('returns the current user map as an array', () => {
expect(
getUserArray({
user: { 1: { id: 1 }, 2: { id: 2 } },
user: { 1: { id: 1, name: 'a' }, 2: { id: 2, name: 'b' } },
} as any)
).toEqual([{ id: 1 }, { id: 2 }]);
).toEqual([{ id: 1, name: 'a' }, { id: 2, name: 'b' }]);
});
});
describe('getUser', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/store/reducers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ export function getUserState(state: AppState): UsersState {
}

export function getUserArray(state: AppState): User[] {
return Object.values(getUserState(state));
return Object.values(getUserState(state)).sort((a: User, b: User) =>
a.name.localeCompare(b.name)
);
}

export function getUser(state: AppState, userId: number): User | undefined {
Expand Down

0 comments on commit 61c1742

Please sign in to comment.