import { screen } from '@testing-library/react'; import { describe, expect, it } from 'vitest'; import { renderWithProviders } from '../test/render'; import { Avatar, avatarSlot, initials } from './Avatar'; describe('Avatar', () => { it('derives initials and slots (AC-4.5, design-spec §2.5)', () => { expect(initials('Jacob Hagstedt')).toBe('JH'); expect(initials(' anna ')).toBe('A'); expect(initials('Åsa Öberg Lind')).toBe('ÅÖ'); expect(avatarSlot('b', ['b', 'a'])).toBe(2); expect(avatarSlot('a', ['b', 'a'])).toBe(1); }); it('shows initials, or the picture, and is announced only when not decorative', () => { const { rerender, wrap } = renderWithProviders(); expect(screen.getByRole('img', { name: 'Anna' })).toHaveTextContent('A'); rerender(wrap()); expect(screen.queryByRole('img', { name: 'Anna' })).not.toBeInTheDocument(); expect(document.querySelector('img')).toHaveAttribute('src', 'blob:picture'); }); });