2022-11-23 17:42:43 +01:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
|
2023-05-04 02:30:07 +02:00
|
|
|
import {
|
|
|
|
BackgroundColor,
|
|
|
|
BorderColor,
|
|
|
|
Color,
|
|
|
|
TextColor,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2022-11-23 17:42:43 +01:00
|
|
|
|
|
|
|
import { AvatarBase } from './avatar-base';
|
2023-05-04 02:30:07 +02:00
|
|
|
import { AvatarBaseSize } from './avatar-base.types';
|
2022-11-23 17:42:43 +01:00
|
|
|
|
|
|
|
describe('AvatarBase', () => {
|
|
|
|
it('should render correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<AvatarBase data-testid="avatar-base" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base')).toBeDefined();
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
2023-05-04 02:30:07 +02:00
|
|
|
<AvatarBase size={AvatarBaseSize.Xs} data-testid="avatar-base-xs" />
|
|
|
|
<AvatarBase size={AvatarBaseSize.Sm} data-testid="avatar-base-sm" />
|
|
|
|
<AvatarBase size={AvatarBaseSize.Md} data-testid="avatar-base-md" />
|
|
|
|
<AvatarBase size={AvatarBaseSize.Lg} data-testid="avatar-base-lg" />
|
|
|
|
<AvatarBase size={AvatarBaseSize.Xl} data-testid="avatar-base-xl" />
|
2022-11-23 17:42:43 +01:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base-xs')).toHaveClass(
|
2023-03-17 18:06:59 +01:00
|
|
|
'mm-avatar-base--size-xs mm-text--body-xs',
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base-sm')).toHaveClass(
|
2023-03-17 18:06:59 +01:00
|
|
|
'mm-avatar-base--size-sm mm-text--body-sm',
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base-md')).toHaveClass(
|
2023-03-17 18:06:59 +01:00
|
|
|
'mm-avatar-base--size-md mm-text--body-sm',
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base-lg')).toHaveClass(
|
2023-03-17 18:06:59 +01:00
|
|
|
'mm-avatar-base--size-lg mm-text--body-lg-medium',
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base-xl')).toHaveClass(
|
2023-03-17 18:06:59 +01:00
|
|
|
'mm-avatar-base--size-xl mm-text--body-lg-medium',
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
// className
|
|
|
|
it('should render with custom className', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarBase data-testid="avatar-base" className="test-class" />,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-base')).toHaveClass('test-class');
|
|
|
|
});
|
|
|
|
// children
|
|
|
|
it('should render children', () => {
|
|
|
|
render(
|
|
|
|
<AvatarBase data-testid="avatar-base">
|
|
|
|
<img width="100%" src="./images/arbitrum.svg" />
|
|
|
|
</AvatarBase>,
|
|
|
|
);
|
|
|
|
const image = screen.getByRole('img');
|
|
|
|
expect(image).toBeDefined();
|
|
|
|
expect(image).toHaveAttribute('src', './images/arbitrum.svg');
|
|
|
|
});
|
|
|
|
// color
|
|
|
|
it('should render with different colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarBase
|
2023-03-17 18:06:59 +01:00
|
|
|
color={TextColor.successDefault}
|
|
|
|
data-testid={TextColor.successDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarBase
|
2023-03-17 18:06:59 +01:00
|
|
|
color={TextColor.errorDefault}
|
|
|
|
data-testid={TextColor.errorDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-03-17 18:06:59 +01:00
|
|
|
expect(getByTestId(TextColor.successDefault)).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
`mm-box--color-${TextColor.successDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
2023-03-17 18:06:59 +01:00
|
|
|
expect(getByTestId(TextColor.errorDefault)).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
`mm-box--color-${TextColor.errorDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
// background color
|
|
|
|
it('should render with different background colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarBase
|
2023-05-04 02:30:07 +02:00
|
|
|
backgroundColor={BackgroundColor.successDefault}
|
2023-02-02 21:15:26 +01:00
|
|
|
data-testid={Color.successDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarBase
|
2023-05-04 02:30:07 +02:00
|
|
|
backgroundColor={BackgroundColor.errorDefault}
|
2023-02-02 21:15:26 +01:00
|
|
|
data-testid={Color.errorDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(Color.successDefault)).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
`mm-box--background-color-${Color.successDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(Color.errorDefault)).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
`mm-box--background-color-${Color.errorDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
// border color
|
|
|
|
it('should render with different border colors', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarBase
|
2023-05-04 02:30:07 +02:00
|
|
|
borderColor={BorderColor.successDefault}
|
2023-02-02 21:15:26 +01:00
|
|
|
data-testid={Color.successDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarBase
|
2023-05-04 02:30:07 +02:00
|
|
|
borderColor={BorderColor.errorDefault}
|
2023-02-02 21:15:26 +01:00
|
|
|
data-testid={Color.errorDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(Color.successDefault)).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
`mm-box--border-color-${Color.successDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
2023-02-02 21:15:26 +01:00
|
|
|
expect(getByTestId(Color.errorDefault)).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
`mm-box--border-color-${Color.errorDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
});
|
2023-04-21 17:51:34 +02:00
|
|
|
it('should forward a ref to the root html element', () => {
|
|
|
|
const ref = React.createRef();
|
|
|
|
render(<AvatarBase ref={ref}>A</AvatarBase>);
|
|
|
|
expect(ref.current).not.toBeNull();
|
|
|
|
expect(ref.current.nodeName).toBe('DIV');
|
|
|
|
});
|
2022-11-23 17:42:43 +01:00
|
|
|
});
|