diff --git a/lib/utils/text-utils.test.js b/lib/utils/text-utils.test.js --- a/lib/utils/text-utils.test.js +++ b/lib/utils/text-utils.test.js @@ -1,6 +1,6 @@ // @flow -import { pluralize, trimText } from './text-utils.js'; +import { pluralize, trimText, pluralizeAndTrim } from './text-utils.js'; describe('pluralize(nouns, maxNumberOfNouns)', () => { it('should return an empty string when no words are given', () => { @@ -114,3 +114,26 @@ expect(trimText('abc', 3).length).toBeLessThanOrEqual(3); }); }); + +test('pluralizeAndTrim', () => { + expect(pluralizeAndTrim([], 10)).toBe(''); + expect(pluralizeAndTrim(['a'], 10)).toBe('a'); + expect(pluralizeAndTrim(['a', 'b'], 10)).toBe('a and b'); + + expect(pluralizeAndTrim(['a', 'b', 'c'], 10)).toBe('3 users'); + expect(pluralizeAndTrim(['a', 'b', 'c'], 12)).toBe('a, b, and c'); + + expect(pluralizeAndTrim(['a', 'b', 'c', 'd'], 10)).toBe('4 users'); + expect(pluralizeAndTrim(['a', 'b', 'c', 'd'], 20)).toBe('a, b, and 2 others'); + + expect(pluralizeAndTrim(['cat', 'dog', 'sheep'], 10)).toBe('3 users'); + expect(pluralizeAndTrim(['cat', 'dog', 'sheep'], 16)).toBe( + 'cat and 2 others', + ); + expect(pluralizeAndTrim(['cat', 'dog', 'sheep'], 20)).toBe( + 'cat, dog, and sheep', + ); + expect(pluralizeAndTrim(['cat', 'dog', 'sheep'], 1000)).toBe( + 'cat, dog, and sheep', + ); +});