2022-08-18 18:30:19 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
|
2022-12-15 18:29:24 +01:00
|
|
|
import { COLORS } from '../../../helpers/constants/design-system';
|
|
|
|
|
2022-08-18 18:30:19 +02:00
|
|
|
import { AvatarToken } from './avatar-token';
|
|
|
|
|
|
|
|
describe('AvatarToken', () => {
|
|
|
|
const args = {
|
2022-12-15 18:29:24 +01:00
|
|
|
name: 'ast',
|
|
|
|
src: './AST.png',
|
2022-08-18 18:30:19 +02:00
|
|
|
showHalo: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should render correctly', () => {
|
2022-12-15 18:29:24 +01:00
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<AvatarToken {...args} data-testid="avatar-token" />,
|
|
|
|
);
|
2022-08-18 18:30:19 +02:00
|
|
|
expect(getByTestId('avatar-token')).toBeDefined();
|
2022-12-15 18:29:24 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-08-18 18:30:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render image Avatar', () => {
|
|
|
|
render(<AvatarToken {...args} data-testid="avatar-token" />);
|
|
|
|
const image = screen.getByRole('img');
|
|
|
|
expect(image).toBeDefined();
|
2022-12-15 18:29:24 +01:00
|
|
|
expect(image).toHaveAttribute('src', args.src);
|
2022-08-18 18:30:19 +02:00
|
|
|
});
|
|
|
|
|
2022-12-15 18:29:24 +01:00
|
|
|
it('should render the first letter of the name prop if no src is provided', () => {
|
2022-08-18 18:30:19 +02:00
|
|
|
const { getByText } = render(
|
2022-12-15 18:29:24 +01:00
|
|
|
<AvatarToken {...args} data-testid="avatar-token" src="" />,
|
2022-08-18 18:30:19 +02:00
|
|
|
);
|
|
|
|
expect(getByText('a')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render halo effect if showHalo is true and image url is there', () => {
|
|
|
|
render(<AvatarToken {...args} data-testid="avatar-token" showHalo />);
|
|
|
|
const image = screen.getAllByRole('img', { hidden: true });
|
2022-12-15 18:29:24 +01:00
|
|
|
expect(image[1]).toHaveClass('mm-avatar-token__token-image--size-reduced');
|
2022-08-18 18:30:19 +02:00
|
|
|
});
|
|
|
|
|
2022-12-15 18:29:24 +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 18:30:19 +02:00
|
|
|
const { getByText } = render(
|
2022-12-15 18:29:24 +01:00
|
|
|
<AvatarToken {...args} src="" data-testid="avatar-token" showHalo />,
|
2022-08-18 18:30:19 +02:00
|
|
|
);
|
|
|
|
expect(getByText('a')).toBeDefined();
|
|
|
|
});
|
2022-12-15 18:29:24 +01:00
|
|
|
// className
|
|
|
|
it('should render with custom className', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarToken data-testid="avatar-token" className="test-class" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-token')).toHaveClass('test-class');
|
|
|
|
});
|
|
|
|
// color
|
|
|
|
it('should render with different colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarToken
|
|
|
|
color={COLORS.SUCCESS_DEFAULT}
|
|
|
|
data-testid={COLORS.SUCCESS_DEFAULT}
|
|
|
|
/>
|
|
|
|
<AvatarToken
|
|
|
|
color={COLORS.ERROR_DEFAULT}
|
|
|
|
data-testid={COLORS.ERROR_DEFAULT}
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId(COLORS.SUCCESS_DEFAULT)).toHaveClass(
|
|
|
|
`box--color-${COLORS.SUCCESS_DEFAULT}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass(
|
|
|
|
`box--color-${COLORS.ERROR_DEFAULT}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
// background color
|
|
|
|
it('should render with different background colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarToken
|
|
|
|
backgroundColor={COLORS.SUCCESS_DEFAULT}
|
|
|
|
data-testid={COLORS.SUCCESS_DEFAULT}
|
|
|
|
/>
|
|
|
|
<AvatarToken
|
|
|
|
backgroundColor={COLORS.ERROR_DEFAULT}
|
|
|
|
data-testid={COLORS.ERROR_DEFAULT}
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId(COLORS.SUCCESS_DEFAULT)).toHaveClass(
|
|
|
|
`box--background-color-${COLORS.SUCCESS_DEFAULT}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass(
|
|
|
|
`box--background-color-${COLORS.ERROR_DEFAULT}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
// border color
|
|
|
|
it('should render with different border colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarToken
|
|
|
|
borderColor={COLORS.SUCCESS_DEFAULT}
|
|
|
|
data-testid={COLORS.SUCCESS_DEFAULT}
|
|
|
|
/>
|
|
|
|
<AvatarToken
|
|
|
|
borderColor={COLORS.ERROR_DEFAULT}
|
|
|
|
data-testid={COLORS.ERROR_DEFAULT}
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId(COLORS.SUCCESS_DEFAULT)).toHaveClass(
|
|
|
|
`box--border-color-${COLORS.SUCCESS_DEFAULT}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(COLORS.ERROR_DEFAULT)).toHaveClass(
|
|
|
|
`box--border-color-${COLORS.ERROR_DEFAULT}`,
|
|
|
|
);
|
|
|
|
});
|
2022-08-18 18:30:19 +02:00
|
|
|
});
|