2022-08-18 20:54:10 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
|
2023-02-02 21:15:26 +01:00
|
|
|
import {
|
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
|
|
|
TextColor,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2022-12-15 18:28:42 +01:00
|
|
|
|
2022-08-18 20:54:10 +02:00
|
|
|
import { AvatarNetwork } from './avatar-network';
|
|
|
|
|
|
|
|
describe('AvatarNetwork', () => {
|
|
|
|
const args = {
|
2022-12-15 18:28:42 +01:00
|
|
|
name: 'ethereum',
|
|
|
|
src: './images/eth_logo.svg',
|
2022-08-18 20:54:10 +02:00
|
|
|
showHalo: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should render correctly', () => {
|
2022-12-15 18:28:42 +01:00
|
|
|
const { getByTestId, container } = render(
|
2022-08-18 20:54:10 +02:00
|
|
|
<AvatarNetwork data-testid="avatar-network" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-network')).toBeDefined();
|
2022-12-15 18:28:42 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-08-18 20:54:10 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render image of Avatar Network', () => {
|
|
|
|
render(<AvatarNetwork data-testid="avatar-network" {...args} />);
|
|
|
|
const image = screen.getByRole('img');
|
|
|
|
expect(image).toBeDefined();
|
2022-12-15 18:28:42 +01:00
|
|
|
expect(image).toHaveAttribute('src', args.src);
|
2022-08-18 20:54:10 +02:00
|
|
|
});
|
|
|
|
|
2022-12-15 18:28:42 +01:00
|
|
|
it('should render the first letter of the name prop if no src is provided', () => {
|
2022-08-18 20:54:10 +02:00
|
|
|
const { getByText } = render(
|
2022-12-15 18:28:42 +01:00
|
|
|
<AvatarNetwork data-testid="avatar-network" {...args} src="" />,
|
2022-08-18 20:54:10 +02:00
|
|
|
);
|
|
|
|
expect(getByText('e')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render halo effect if showHalo is true and image url is there', () => {
|
|
|
|
render(<AvatarNetwork data-testid="avatar-network" {...args} showHalo />);
|
|
|
|
const image = screen.getAllByRole('img', { hidden: true });
|
2022-12-15 18:28:42 +01:00
|
|
|
expect(image[1]).toHaveClass(
|
|
|
|
'mm-avatar-network__network-image--size-reduced',
|
|
|
|
);
|
2022-08-18 20:54:10 +02:00
|
|
|
});
|
|
|
|
|
2022-12-15 18:28:42 +01:00
|
|
|
it('should render the first letter of the name prop when showHalo is true and no image url is provided', () => {
|
2022-08-18 20:54:10 +02:00
|
|
|
const { getByText } = render(
|
2022-12-15 18:28:42 +01:00
|
|
|
<AvatarNetwork {...args} src="" data-testid="avatar-network" showHalo />,
|
2022-08-18 20:54:10 +02:00
|
|
|
);
|
|
|
|
expect(getByText('e')).toBeDefined();
|
|
|
|
});
|
2022-12-15 18:28:42 +01:00
|
|
|
// className
|
|
|
|
it('should render with custom className', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarNetwork data-testid="avatar-network" className="test-class" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-network')).toHaveClass('test-class');
|
|
|
|
});
|
|
|
|
// color
|
|
|
|
it('should render with different colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarNetwork
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.successDefault}
|
|
|
|
data-testid={TextColor.successDefault}
|
2022-12-15 18:28:42 +01:00
|
|
|
/>
|
|
|
|
<AvatarNetwork
|
2023-02-02 21:15:26 +01:00
|
|
|
color={TextColor.errorDefault}
|
|
|
|
data-testid={TextColor.errorDefault}
|
2022-12-15 18:28:42 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(TextColor.successDefault)).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
`box--color-${TextColor.successDefault}`,
|
2022-12-15 18:28:42 +01:00
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(TextColor.errorDefault)).toHaveClass(
|
2023-03-23 21:00:37 +01:00
|
|
|
`box--color-${TextColor.errorDefault}`,
|
2022-12-15 18:28:42 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
// background color
|
|
|
|
it('should render with different background colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarNetwork
|
2023-02-02 21:15:26 +01:00
|
|
|
backgroundColor={BackgroundColor.successDefault}
|
|
|
|
data-testid={BackgroundColor.successDefault}
|
2022-12-15 18:28:42 +01:00
|
|
|
/>
|
|
|
|
<AvatarNetwork
|
2023-02-02 21:15:26 +01:00
|
|
|
backgroundColor={BackgroundColor.errorDefault}
|
|
|
|
data-testid={BackgroundColor.errorDefault}
|
2022-12-15 18:28:42 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(BackgroundColor.successDefault)).toHaveClass(
|
|
|
|
`box--background-color-${BackgroundColor.successDefault}`,
|
2022-12-15 18:28:42 +01:00
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(BackgroundColor.errorDefault)).toHaveClass(
|
|
|
|
`box--background-color-${BackgroundColor.errorDefault}`,
|
2022-12-15 18:28:42 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
// border color
|
|
|
|
it('should render with different border colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarNetwork
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={BorderColor.successDefault}
|
|
|
|
data-testid={BorderColor.successDefault}
|
2022-12-15 18:28:42 +01:00
|
|
|
/>
|
|
|
|
<AvatarNetwork
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={BorderColor.errorDefault}
|
|
|
|
data-testid={BorderColor.errorDefault}
|
2022-12-15 18:28:42 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(BorderColor.successDefault)).toHaveClass(
|
|
|
|
`box--border-color-${BorderColor.successDefault}`,
|
2022-12-15 18:28:42 +01:00
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(BorderColor.errorDefault)).toHaveClass(
|
|
|
|
`box--border-color-${BorderColor.errorDefault}`,
|
2022-12-15 18:28:42 +01:00
|
|
|
);
|
|
|
|
});
|
2022-08-18 20:54:10 +02:00
|
|
|
});
|