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-03-17 18:06:59 +01:00
|
|
|
import { Color, TextColor } from '../../../helpers/constants/design-system';
|
2022-11-23 17:42:43 +01:00
|
|
|
|
|
|
|
import { AvatarBase } from './avatar-base';
|
|
|
|
|
|
|
|
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(
|
|
|
|
<>
|
|
|
|
<AvatarBase size="xs" data-testid="avatar-base-xs" />
|
|
|
|
<AvatarBase size="sm" data-testid="avatar-base-sm" />
|
|
|
|
<AvatarBase size="md" data-testid="avatar-base-md" />
|
|
|
|
<AvatarBase size="lg" data-testid="avatar-base-lg" />
|
|
|
|
<AvatarBase size="xl" data-testid="avatar-base-xl" />
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
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-03-23 21:00:37 +01:00
|
|
|
`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-03-23 21:00:37 +01:00
|
|
|
`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-03-17 18:06:59 +01:00
|
|
|
backgroundColor={TextColor.successDefault}
|
2023-02-02 21:15:26 +01:00
|
|
|
data-testid={Color.successDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarBase
|
2023-03-17 18:06:59 +01:00
|
|
|
backgroundColor={TextColor.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(
|
|
|
|
`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(
|
|
|
|
`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-02-02 21:15:26 +01:00
|
|
|
borderColor={Color.successDefault}
|
|
|
|
data-testid={Color.successDefault}
|
2022-11-23 17:42:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarBase
|
2023-02-02 21:15:26 +01:00
|
|
|
borderColor={Color.errorDefault}
|
|
|
|
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(
|
|
|
|
`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(
|
|
|
|
`box--border-color-${Color.errorDefault}`,
|
2022-11-23 17:42:43 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|