/* eslint-disable jest/require-top-level-describe */
import { render, screen } from '@testing-library/react';
import React from 'react';
import {
BackgroundColor,
BorderColor,
TextColor,
} from '../../../helpers/constants/design-system';
import { AvatarNetwork, AvatarNetworkSize } from '.';
describe('AvatarNetwork', () => {
const args = {
name: 'ethereum',
src: './images/eth_logo.png',
showHalo: false,
};
it('should render correctly', () => {
const { getByTestId, container } = render(
,
);
expect(getByTestId('avatar-network')).toBeDefined();
expect(container).toMatchSnapshot();
});
it('should render image of Avatar Network', () => {
render();
const image = screen.getByRole('img');
expect(image).toBeDefined();
expect(image).toHaveAttribute('src', args.src);
});
it('should render the first letter of the name prop if no src is provided', () => {
const { getByText } = render(
,
);
expect(getByText('e')).toBeDefined();
});
it('should render halo effect if showHalo is true and image url is there', () => {
render();
const image = screen.getAllByRole('img', { hidden: true });
expect(image[1]).toHaveClass(
'mm-avatar-network__network-image--size-reduced',
);
});
it('should render the first letter of the name prop when showHalo is true and no image url is provided', () => {
const { getByText } = render(
,
);
expect(getByText('e')).toBeDefined();
});
// className
it('should render with custom className', () => {
const { getByTestId } = render(
,
);
expect(getByTestId('avatar-network')).toHaveClass('test-class');
});
// color
it('should render with different colors', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId(TextColor.successDefault)).toHaveClass(
`mm-box--color-${TextColor.successDefault}`,
);
expect(getByTestId(TextColor.errorDefault)).toHaveClass(
`mm-box--color-${TextColor.errorDefault}`,
);
});
// background color
it('should render with different background colors', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId(BackgroundColor.successDefault)).toHaveClass(
`mm-box--background-color-${BackgroundColor.successDefault}`,
);
expect(getByTestId(BackgroundColor.errorDefault)).toHaveClass(
`mm-box--background-color-${BackgroundColor.errorDefault}`,
);
});
// border color
it('should render with different border colors', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId(BorderColor.successDefault)).toHaveClass(
`mm-box--border-color-${BorderColor.successDefault}`,
);
expect(getByTestId(BorderColor.errorDefault)).toHaveClass(
`mm-box--border-color-${BorderColor.errorDefault}`,
);
});
// AvatarNetworkSize
it('should render with different AvatarNetworkSize', () => {
const { getByTestId } = render(
<>
>,
);
expect(getByTestId(AvatarNetworkSize.Xs)).toHaveClass(
`mm-avatar-base--size-${AvatarNetworkSize.Xs}`,
);
expect(getByTestId(AvatarNetworkSize.Sm)).toHaveClass(
`mm-avatar-base--size-${AvatarNetworkSize.Sm}`,
);
expect(getByTestId(AvatarNetworkSize.Md)).toHaveClass(
`mm-avatar-base--size-${AvatarNetworkSize.Md}`,
);
expect(getByTestId(AvatarNetworkSize.Lg)).toHaveClass(
`mm-avatar-base--size-${AvatarNetworkSize.Lg}`,
);
expect(getByTestId(AvatarNetworkSize.Xl)).toHaveClass(
`mm-avatar-base--size-${AvatarNetworkSize.Xl}`,
);
});
it('should forward a ref to the root html element', () => {
const ref = React.createRef();
render();
expect(ref.current).not.toBeNull();
if (ref.current) {
expect(ref.current.nodeName).toBe('DIV');
}
});
});