2024-10-04 07:55:41 -07:00
|
|
|
|
import type { MockInstance } from 'vitest';
|
|
|
|
|
|
2024-07-18 05:17:27 -07:00
|
|
|
|
import { getInitials } from './labelUtil';
|
2024-06-17 09:50:29 -07:00
|
|
|
|
|
|
|
|
|
describe('labelUtil.getInitials', () => {
|
|
|
|
|
it.each([
|
|
|
|
|
['', ''],
|
|
|
|
|
|
|
|
|
|
// simple words
|
|
|
|
|
['Hello', 'He'],
|
|
|
|
|
['Hello World', 'HW'],
|
|
|
|
|
['H', 'H'],
|
|
|
|
|
|
|
|
|
|
// multiple spaces
|
|
|
|
|
['Double Space', 'DS'],
|
|
|
|
|
[' ', ''],
|
|
|
|
|
|
|
|
|
|
// simple emoji
|
|
|
|
|
['👋 Hello', '👋H'],
|
|
|
|
|
['👋Hello', '👋H'],
|
|
|
|
|
['Hello 👋', 'H👋'],
|
|
|
|
|
['Hello👋', 'He'],
|
|
|
|
|
|
|
|
|
|
// combined emojis
|
|
|
|
|
['1️⃣ 1️⃣', '1️⃣1️⃣'],
|
|
|
|
|
['1️⃣', '1️⃣'],
|
|
|
|
|
['👩⚕️D 👩⚕️D', '👩⚕️👩⚕️'],
|
|
|
|
|
])('turns "%s" into "%s"', (input, output) => {
|
|
|
|
|
expect(getInitials(input)).toBe(output);
|
|
|
|
|
});
|
2024-10-04 07:55:41 -07:00
|
|
|
|
|
|
|
|
|
describe('when Intl.Segmenter is not supported', () => {
|
|
|
|
|
let intlSpy: MockInstance;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
// No Intl.Segmenter support
|
|
|
|
|
intlSpy = vi.spyOn(globalThis, 'Intl', 'get');
|
|
|
|
|
intlSpy.mockImplementation(() => ({}));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
|
['', ''],
|
|
|
|
|
|
|
|
|
|
// simple words
|
|
|
|
|
['Hello', 'He'],
|
|
|
|
|
['Hello World', 'HW'],
|
|
|
|
|
['H', 'H'],
|
|
|
|
|
|
|
|
|
|
// multiple spaces
|
|
|
|
|
['Double Space', 'DS'],
|
|
|
|
|
[' ', ''],
|
|
|
|
|
])('turns "%s" into "%s"', (input, output) => {
|
|
|
|
|
expect(getInitials(input)).toBe(output);
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-06-17 09:50:29 -07:00
|
|
|
|
});
|