import { describe, it, expect } from 'vitest'; import { avatarPalette, initials } from './avatar'; describe('avatarPalette', () => { it('returns the neutral palette for empty / nullish names', () => { expect(avatarPalette(null)).toContain('bg-gray-100'); expect(avatarPalette(undefined)).toContain('bg-gray-100'); expect(avatarPalette('')).toContain('bg-gray-100'); }); it('is deterministic for the same name', () => { expect(avatarPalette('Alice')).toBe(avatarPalette('Alice')); }); it('returns a real palette entry (not neutral) for a non-empty name', () => { expect(avatarPalette('Bob')).toMatch(/bg-(blue|purple|green|amber|rose|teal)-100/); }); }); describe('initials', () => { it('returns "?" for empty / nullish / whitespace-only names', () => { expect(initials(null)).toBe('?'); expect(initials(undefined)).toBe('?'); expect(initials('')).toBe('?'); expect(initials(' ')).toBe('?'); }); it('uses the first letter (uppercased) for a single word', () => { expect(initials('alice')).toBe('A'); }); it('uses the first letters of the first two words', () => { expect(initials('Alice Bob Carol')).toBe('AB'); }); it('collapses runs of whitespace between words', () => { expect(initials(' john doe ')).toBe('JD'); }); });