|
| 1 | +import { fromJS } from 'immutable'; |
| 2 | +import { sortUserList, filterUserList } from '../userListSelectors'; |
| 3 | + |
| 4 | +it('empty input to filterUserList results in empty list', () => { |
| 5 | + const users = fromJS([]); |
| 6 | + const filteredUsers = filterUserList(users, 'some filter'); |
| 7 | + expect(filteredUsers).toEqual(fromJS([])); |
| 8 | +}); |
| 9 | + |
| 10 | +it('filterUserList returns same list if no filter', () => { |
| 11 | + const users = fromJS([{ fullName: 'user1' }, { fullName: 'user2' }]); |
| 12 | + const filteredUsers = filterUserList(users); |
| 13 | + expect(filteredUsers).toEqual(users); |
| 14 | +}); |
| 15 | + |
| 16 | +it('filterUserList searches in name, email and is case insensitive', () => { |
| 17 | + const allUsers = fromJS([ |
| 18 | + { fullName: 'match', email: '[email protected]' }, |
| 19 | + { fullName: 'partial match', email: '[email protected]' }, |
| 20 | + { fullName: 'Case Insensitive MaTcH', email: '[email protected]' }, |
| 21 | + { fullName: 'Any Name', email: '[email protected]' }, |
| 22 | + { fullName: 'some name', email: '[email protected]' }, |
| 23 | + ]); |
| 24 | + const shouldMatch = fromJS([ |
| 25 | + { fullName: 'match', email: '[email protected]' }, |
| 26 | + { fullName: 'partial match', email: '[email protected]' }, |
| 27 | + { fullName: 'Case Insensitive MaTcH', email: '[email protected]' }, |
| 28 | + { fullName: 'Any Name', email: '[email protected]' }, |
| 29 | + ]); |
| 30 | + const filteredUsers = filterUserList(allUsers, 'match'); |
| 31 | + expect(filteredUsers).toEqual(shouldMatch); |
| 32 | +}); |
| 33 | + |
| 34 | +it('sortUserList sorts by name', () => { |
| 35 | + const users = fromJS([{ fullName: 'abc' }, { fullName: 'xyz' }, { fullName: 'jkl' }]); |
| 36 | + const shouldMatch = fromJS([{ fullName: 'abc' }, { fullName: 'jkl' }, { fullName: 'xyz' }]); |
| 37 | + const sortedUsers = sortUserList(users); |
| 38 | + expect(sortedUsers).toEqual(shouldMatch); |
| 39 | +}); |
| 40 | + |
| 41 | +it('sortUserList prioritizes status', () => { |
| 42 | + const users = fromJS([ |
| 43 | + { fullName: 'abc', status: 'offline' }, |
| 44 | + { fullName: 'xyz', status: 'idle' }, |
| 45 | + { fullName: 'jkl', status: 'active' }, |
| 46 | + { fullName: 'abc', status: 'active' }, |
| 47 | + ]); |
| 48 | + const shouldMatch = fromJS([ |
| 49 | + { fullName: 'abc', status: 'active' }, |
| 50 | + { fullName: 'jkl', status: 'active' }, |
| 51 | + { fullName: 'xyz', status: 'idle' }, |
| 52 | + { fullName: 'abc', status: 'offline' }, |
| 53 | + ]); |
| 54 | + const sortedUsers = sortUserList(users); |
| 55 | + expect(sortedUsers).toEqual(shouldMatch); |
| 56 | +}); |
0 commit comments