import { render, screen } from '@testing-library/react';
import { ThemeProvider } from '../../../theme';
import InitialsAvatar from './InitialsAvatar';
describe('', () => {
const wrap = (ui: React.ReactNode) => render({ui});
it('renders initials from the first two words of the name', () => {
wrap();
expect(screen.getByText('مر')).toBeInTheDocument();
});
it('renders a single-word name as one initial', () => {
wrap();
expect(screen.getByText('م')).toBeInTheDocument();
});
it('is hidden from assistive tech (decorative next to a visible name)', () => {
wrap();
expect(screen.getByText('مر')).toHaveAttribute('aria-hidden', 'true');
});
it('picks the same color index for the same name every render', () => {
const { container: first } = render(
,
);
const { container: second } = render(
,
);
const bg = (el: HTMLElement) => el.querySelector('.MuiAvatar-root')?.getAttribute('style');
expect(bg(first.firstChild as HTMLElement)).toEqual(bg(second.firstChild as HTMLElement));
});
});