|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { generateInitialsForEmail } from './generateInitialsForEmail.ts'; |
| 3 | + |
| 4 | +describe('generateInitialsForEmail', () => { |
| 5 | + it('should generate initials from a standard email', () => { |
| 6 | + expect(generateInitialsForEmail('[email protected]')).toBe('FL'); |
| 7 | + }); |
| 8 | + |
| 9 | + it('should generate initials from an email with a single-part name', () => { |
| 10 | + expect(generateInitialsForEmail('[email protected]')).toBe('F'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should generate initials from an email with multiple name parts', () => { |
| 14 | + expect(generateInitialsForEmail('[email protected]')).toBe( |
| 15 | + 'FML', |
| 16 | + ); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should truncate to 3 initials if more than 3 name parts exist', () => { |
| 20 | + expect( |
| 21 | + generateInitialsForEmail('[email protected]'), |
| 22 | + ).toBe('FST'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should handle emails where the name part is short', () => { |
| 26 | + expect(generateInitialsForEmail('[email protected]')).toBe('AB'); |
| 27 | + expect(generateInitialsForEmail('[email protected]')).toBe('X'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should convert initials to uppercase', () => { |
| 31 | + expect(generateInitialsForEmail('[email protected]')).toBe('FL'); |
| 32 | + expect(generateInitialsForEmail('[email protected]')).toBe('FL'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should handle emails with numbers in the name part', () => { |
| 36 | + expect(generateInitialsForEmail('[email protected]')).toBe('FL'); |
| 37 | + expect(generateInitialsForEmail('[email protected]')).toBe('12'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should handle emails with leading/trailing dots in the name part gracefully', () => { |
| 41 | + expect(generateInitialsForEmail('[email protected]')).toBe('LD'); |
| 42 | + expect(generateInitialsForEmail('[email protected]')).toBe('TD'); |
| 43 | + expect(generateInitialsForEmail('[email protected]')).toBe('DD'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should return an empty string for undefined input', () => { |
| 47 | + expect(generateInitialsForEmail(undefined)).toBe(''); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should return an empty string for an empty string input', () => { |
| 51 | + expect(generateInitialsForEmail('')).toBe(''); |
| 52 | + }); |
| 53 | +}); |
0 commit comments