Skip to content

Commit 576c80f

Browse files
committed
fix: Remove English words from list-users method
1 parent 9c05577 commit 576c80f

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

projects/stream-chat-angular/src/lib/list-users.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ describe('listUsers', () => {
1111
{ id: 'id1', name: 'Sara' },
1212
{ id: 'id2', name: 'Jane' },
1313
])
14-
).toBe('Sara and Jane');
14+
).toBe('Sara, Jane');
1515
});
1616

1717
it('should return correct result if user has no name, the fallback should be id', () => {
1818
expect(listUsers([{ id: 'id1' }, { id: 'id2', name: 'Jane' }])).toBe(
19-
'id1 and Jane'
19+
'id1, Jane'
2020
);
2121
});
2222

2323
it(`should return the correct result if called with one user`, () => {
24-
expect(listUsers([{ id: 'id2', name: 'Jane' }])).toBe('Jane ');
24+
expect(listUsers([{ id: 'id2', name: 'Jane' }])).toBe('Jane');
2525
});
2626

2727
it('should return the correct result if called with more than two users, but less or equal than five', () => {
@@ -33,7 +33,7 @@ describe('listUsers', () => {
3333
{ id: 'id5', name: 'John' },
3434
];
3535

36-
expect(listUsers(readBy)).toBe('Bob, Sophie, Jack, John, and Rose');
36+
expect(listUsers(readBy)).toBe('Bob, Sophie, Jack, Rose, John');
3737
});
3838

3939
it('should return the correct result if called with more than five users', () => {
@@ -46,6 +46,6 @@ describe('listUsers', () => {
4646
{ id: 'id6', name: 'Adam' },
4747
];
4848

49-
expect(listUsers(readBy)).toBe('Bob, Sophie, Jack, Rose, John and 1 more');
49+
expect(listUsers(readBy)).toBe('Bob, Sophie, Jack, Rose, John +1');
5050
});
5151
});

projects/stream-chat-angular/src/lib/list-users.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,10 @@ export const listUsers = (users: UserResponse[]) => {
66
const slicedArr = users.map((item) => item.name || item.id).slice(0, 5);
77
const restLength = users.length - slicedArr.length;
88

9-
if (slicedArr.length === 1) {
10-
outStr = `${slicedArr[0]} `;
11-
} else if (slicedArr.length === 2) {
12-
// joins all with "and" but =no commas
13-
// example: "bob and sam"
14-
outStr = `${slicedArr[0]} and ${slicedArr[1]}`;
15-
} else if (slicedArr.length > 2) {
16-
// joins all with commas, but last one gets ", and" (oxford comma!)
17-
// example: "bob, joe, sam and 4 more"
18-
if (restLength === 0) {
19-
// mutate slicedArr to remove last user to display it separately
20-
const lastUser = slicedArr.splice(slicedArr.length - 2, 1)[0];
21-
const commaSeparatedUsers = slicedArr.join(', ');
22-
outStr = `${commaSeparatedUsers}, and ${lastUser}`;
23-
} else {
24-
const commaSeparatedUsers = slicedArr.join(', ');
25-
outStr = `${commaSeparatedUsers} and ${restLength} more`;
26-
}
9+
const commaSeparatedUsers = slicedArr.join(', ');
10+
outStr = commaSeparatedUsers;
11+
if (restLength > 0) {
12+
outStr += ` +${restLength}`;
2713
}
2814

2915
return outStr;

0 commit comments

Comments
 (0)