import { screen, mocks, testA11y, render, waitFor, act } from '@fuels/jest';
import { Avatar } from './Avatar';
describe('Avatar', () => {
beforeAll(() => {
mocks.image();
});
afterAll(() => {
mocks.image.restore();
});
beforeEach(() => {
render(
,
);
});
it('a11y', async () => {
await act(async () =>
testA11y(
,
),
);
});
it('should render the fallback initially with first with letters of name', async () => {
expect(screen.getByText('CT')).toBeInTheDocument();
});
it('should fallback text has just one letter if name is one word', async () => {
render(
,
);
expect(screen.getByText('C')).toBeInTheDocument();
});
it('should not render the image initially', async () => {
await waitFor(() => {
expect(screen.queryByRole('img')).not.toBeInTheDocument();
});
});
it('should render the image after it has loaded', async () => {
await waitFor(() => {
const image = screen.getByRole('img');
expect(image).toBeInTheDocument();
});
});
it('should have alt text on the image', async () => {
await waitFor(() => {
const image = screen.getByAltText('Colm Tuite');
expect(image).toBeInTheDocument();
});
});
});