import { render, screen } from '@testing-library/react' import { describe, expect, it } from 'vitest' import { expectNoA11yViolations } from '../test/a11y' import { Avatar, AvatarGroup } from './Avatar' import { colorFromName, initialsFromName } from './avatar.tokens' describe('Avatar', () => { it('falls back to initials with the name as accessible text', () => { render() expect(screen.getByText('JD')).toHaveAttribute('aria-hidden', 'true') expect(screen.getByText('Jane Doe')).toHaveClass('sr-only') }) it('falls back to initials while the image has not loaded', () => { render() expect(screen.getByText('JS')).toBeInTheDocument() }) it('labels the status dot', () => { render() expect(screen.getByRole('img', { name: 'Online' })).toBeInTheDocument() }) it('accepts a custom status label', () => { render() expect(screen.getByRole('img', { name: 'In a meeting' })).toBeInTheDocument() }) it('derives initials and a stable colour from the name', () => { expect(initialsFromName('Jane Mary Doe')).toBe('JD') expect(initialsFromName('Acme')).toBe('AC') expect(colorFromName('Jane Doe')).toBe(colorFromName('Jane Doe')) }) }) describe('AvatarGroup', () => { it('shows max avatars and an overflow count', () => { render( , ) expect(screen.getByRole('group', { name: 'Team' })).toBeInTheDocument() expect(screen.queryByText('PR')).not.toBeInTheDocument() expect(screen.getByText('+2')).toBeInTheDocument() expect(screen.getByText('and 2 more')).toBeInTheDocument() }) it('has no axe violations', async () => { const { container } = render(
, ) await expectNoA11yViolations(container) }) })