import { Sentiment } from '../../common'; import { render, screen, mockMatchMedia, fireEvent } from '../../test-utils'; import AvatarWrapper from '.'; mockMatchMedia(); const name = 'Elizabeth Alexandra Mary Windsor'; describe('FlowNavigationAvatar', () => { describe('with a name', () => { it('shows the initials for a long name', () => { render(); expect(screen.getByText('EW')).toBeInTheDocument(); }); it('shows the first letter for a mononym', () => { render(); expect(screen.getByText('Z')).toBeInTheDocument(); }); describe('AND profileType', () => { describe('FlowNavigationAvatar', () => { describe('with a name', () => { it('shows the initials for a long name', () => { render(); expect(screen.getByText('EW')).toBeInTheDocument(); }); it('shows the first letter for a mononym', () => { render(); expect(screen.getByText('M')).toBeInTheDocument(); }); }); }); describe('with nothing passed', () => { it('renders aria-label', () => { render(); expect(screen.getByLabelText('test')).toBeInTheDocument(); }); }); describe('with a badge status icon passed', () => { it('renders the badge', () => { render(); expect(screen.getByTestId('check-icon')).toBeInTheDocument(); }); it('renders aria-label', () => { render(); expect(screen.getByLabelText('test')).toBeInTheDocument(); }); }); describe('with image URL', () => { it('falls back to initials when image fails to load', () => { const { container } = render(); const img = container.querySelector('img'); if (img) { fireEvent.error(img); } expect(screen.getByText('JD')).toBeInTheDocument(); }); it('resets error state when url prop changes', () => { const { container, rerender } = render( , ); const img = container.querySelector('img'); if (img) { fireEvent.error(img); } expect(screen.getByText('JD')).toBeInTheDocument(); rerender(); const newImg = container.querySelector('img'); expect(newImg).toHaveAttribute('src', 'valid-url.jpg'); }); }); }); }); });