n8n/packages/design-system/src/utils/labelUtil.test.ts

57 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { MockInstance } from 'vitest';
import { getInitials } from './labelUtil';
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);
});
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);
});
});
});