|
1 |
| -import { sortLastNameFirst, sortHeaders } from './helpers' |
| 1 | +import { |
| 2 | + sortLastNameFirst, |
| 3 | + sortHeaders, |
| 4 | + makeGroupLabelsAndCounts |
| 5 | +} from './helpers' |
| 6 | + |
| 7 | +const t = x => x |
| 8 | + |
2 | 9 | describe('Sort contacts', () => {
|
3 | 10 | describe('By Last Name', () => {
|
4 | 11 | it('should sort contact by last name', () => {
|
@@ -99,3 +106,45 @@ describe('sortHeaders', () => {
|
99 | 106 | expect(sortedHeaders).toEqual(['me', 'empty', 'B', 'F', 'H'])
|
100 | 107 | })
|
101 | 108 | })
|
| 109 | + |
| 110 | +describe('makeGroupLabelsAndCounts', () => { |
| 111 | + it('should returns labels and counts', () => { |
| 112 | + const contacts = [ |
| 113 | + { name: 'Alex', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'A' } }, |
| 114 | + { name: 'Alan', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'A' } }, |
| 115 | + { name: 'Cleo', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'C' } }, |
| 116 | + { name: 'Cloé', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'C' } }, |
| 117 | + { name: 'Clotilde', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'C' } }, |
| 118 | + { name: 'Constant', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'C' } }, |
| 119 | + { |
| 120 | + name: 'Christophe', |
| 121 | + indexes: { byFamilyNameGivenNameEmailCozyUrl: 'C' } |
| 122 | + }, |
| 123 | + { name: 'Bernard', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'B' } }, |
| 124 | + { name: 'Baptiste', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'B' } }, |
| 125 | + { name: 'Xavier', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'X' } }, |
| 126 | + { name: 'Zorro', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'Z' } }, |
| 127 | + { name: '', indexes: { byFamilyNameGivenNameEmailCozyUrl: '' } }, |
| 128 | + { name: {}, indexes: { byFamilyNameGivenNameEmailCozyUrl: {} } }, |
| 129 | + { name: 'John', indexes: { byFamilyNameGivenNameEmailCozyUrl: null } }, |
| 130 | + { |
| 131 | + name: 'Connor', |
| 132 | + indexes: { byFamilyNameGivenNameEmailCozyUrl: undefined } |
| 133 | + }, |
| 134 | + { name: 'Àlbert', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'À' } }, |
| 135 | + { |
| 136 | + name: 'Alice', |
| 137 | + me: true, |
| 138 | + indexes: { byFamilyNameGivenNameEmailCozyUrl: 'Alice' } |
| 139 | + }, |
| 140 | + { name: 'Èllen', indexes: { byFamilyNameGivenNameEmailCozyUrl: 'È' } } |
| 141 | + ] |
| 142 | + |
| 143 | + const res = makeGroupLabelsAndCounts(contacts, t) |
| 144 | + |
| 145 | + expect(res).toStrictEqual({ |
| 146 | + groupLabels: ['A', 'C', 'B', 'X', 'Z', 'empty', 'me', 'E'], |
| 147 | + groupCounts: [3, 5, 2, 1, 1, 4, 1, 1] |
| 148 | + }) |
| 149 | + }) |
| 150 | +}) |
0 commit comments