refactor(personFormat): replace getInitials(Person) with getInitials(name: string)
Unify the initials-extraction logic: the new string-based getInitials() splits on whitespace, takes the first char of the first and last word uppercased — matching the pattern that was already inlined in CommentThread. Update PersonChip, DocumentMetadataDrawer, and CommentThread to use the shared function. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import {
|
||||
getInitials,
|
||||
abbreviateName,
|
||||
formatXsMeta,
|
||||
personAvatarColor,
|
||||
@@ -8,6 +9,30 @@ import {
|
||||
statusLabel
|
||||
} from './personFormat';
|
||||
|
||||
// ─── getInitials ─────────────────────────────────────────────────────────────
|
||||
|
||||
describe('getInitials', () => {
|
||||
it('returns first chars of first and last word uppercased', () => {
|
||||
expect(getInitials('Marcel Raddatz')).toBe('MR');
|
||||
});
|
||||
|
||||
it('returns single char for a single-word name', () => {
|
||||
expect(getInitials('Raddatz')).toBe('R');
|
||||
});
|
||||
|
||||
it('returns empty string for an empty name', () => {
|
||||
expect(getInitials('')).toBe('');
|
||||
});
|
||||
|
||||
it('splits on whitespace only — hyphenated first word counts as one', () => {
|
||||
expect(getInitials('Anna-Maria Raddatz')).toBe('AR');
|
||||
});
|
||||
|
||||
it('ignores extra whitespace between words', () => {
|
||||
expect(getInitials(' Karl Raddatz ')).toBe('KR');
|
||||
});
|
||||
});
|
||||
|
||||
// ─── abbreviateName ──────────────────────────────────────────────────────────
|
||||
|
||||
describe('abbreviateName', () => {
|
||||
|
||||
Reference in New Issue
Block a user