2022-12-08 19:25:19 +01:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
|
2023-04-05 18:11:10 +02:00
|
|
|
import { IconName } from '..';
|
2023-02-02 21:15:26 +01:00
|
|
|
import {
|
|
|
|
BackgroundColor,
|
|
|
|
IconColor,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-07-26 23:18:36 +02:00
|
|
|
import { AvatarIcon, AvatarIconSize } from '.';
|
2022-12-08 19:25:19 +01:00
|
|
|
|
|
|
|
describe('AvatarIcon', () => {
|
|
|
|
it('should render correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2022-12-08 19:25:19 +01:00
|
|
|
data-testid="avatar-icon"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-icon')).toBeDefined();
|
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2023-07-26 23:18:36 +02:00
|
|
|
size={AvatarIconSize.Xs}
|
|
|
|
data-testid={AvatarIconSize.Xs}
|
2022-12-08 19:25:19 +01:00
|
|
|
/>
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2023-07-26 23:18:36 +02:00
|
|
|
size={AvatarIconSize.Sm}
|
|
|
|
data-testid={AvatarIconSize.Sm}
|
2022-12-08 19:25:19 +01:00
|
|
|
/>
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2023-07-26 23:18:36 +02:00
|
|
|
size={AvatarIconSize.Md}
|
|
|
|
data-testid={AvatarIconSize.Md}
|
2022-12-08 19:25:19 +01:00
|
|
|
/>
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2023-07-26 23:18:36 +02:00
|
|
|
size={AvatarIconSize.Lg}
|
|
|
|
data-testid={AvatarIconSize.Lg}
|
2022-12-08 19:25:19 +01:00
|
|
|
/>
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2023-07-26 23:18:36 +02:00
|
|
|
size={AvatarIconSize.Xl}
|
|
|
|
data-testid={AvatarIconSize.Xl}
|
2022-12-08 19:25:19 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-07-26 23:18:36 +02:00
|
|
|
expect(getByTestId(AvatarIconSize.Xs)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AvatarIconSize.Xs}`,
|
2022-12-08 19:25:19 +01:00
|
|
|
);
|
2023-07-26 23:18:36 +02:00
|
|
|
expect(getByTestId(AvatarIconSize.Sm)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AvatarIconSize.Sm}`,
|
2022-12-08 19:25:19 +01:00
|
|
|
);
|
2023-07-26 23:18:36 +02:00
|
|
|
expect(getByTestId(AvatarIconSize.Md)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AvatarIconSize.Md}`,
|
2022-12-08 19:25:19 +01:00
|
|
|
);
|
2023-07-26 23:18:36 +02:00
|
|
|
expect(getByTestId(AvatarIconSize.Lg)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AvatarIconSize.Lg}`,
|
2022-12-08 19:25:19 +01:00
|
|
|
);
|
2023-07-26 23:18:36 +02:00
|
|
|
expect(getByTestId(AvatarIconSize.Xl)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AvatarIconSize.Xl}`,
|
2022-12-08 19:25:19 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with added classname', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2022-12-08 19:25:19 +01:00
|
|
|
className="mm-avatar-icon--test"
|
|
|
|
data-testid="classname"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('classname')).toHaveClass('mm-avatar-icon--test');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with icon', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2022-12-08 19:25:19 +01:00
|
|
|
iconProps={{ 'data-testid': 'avatar-icon' }}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(getByTestId('avatar-icon')).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with success color icon and background color', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarIcon
|
2023-04-05 18:11:10 +02:00
|
|
|
iconName={IconName.SwapHorizontal}
|
2023-02-02 21:15:26 +01:00
|
|
|
color={IconColor.successDefault}
|
|
|
|
backgroundColor={BackgroundColor.successMuted}
|
2022-12-08 19:25:19 +01:00
|
|
|
data-testid="success"
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
|
2023-07-17 23:00:16 +02:00
|
|
|
expect(getByTestId('success')).toHaveClass('mm-box--color-success-default');
|
2022-12-08 19:25:19 +01:00
|
|
|
expect(getByTestId('success')).toHaveClass(
|
2023-07-17 23:00:16 +02:00
|
|
|
'mm-box--background-color-success-muted',
|
2022-12-08 19:25:19 +01:00
|
|
|
);
|
|
|
|
});
|
2023-04-21 17:51:34 +02:00
|
|
|
it('should forward a ref to the root html element', () => {
|
2023-07-26 23:18:36 +02:00
|
|
|
const ref = React.createRef<HTMLDivElement>();
|
2023-04-21 17:51:34 +02:00
|
|
|
render(<AvatarIcon iconName={IconName.SwapHorizontal} ref={ref} />);
|
|
|
|
expect(ref.current).not.toBeNull();
|
2023-07-26 23:18:36 +02:00
|
|
|
if (ref.current) {
|
|
|
|
expect(ref.current.nodeName).toBe('DIV');
|
|
|
|
}
|
2023-04-21 17:51:34 +02:00
|
|
|
});
|
2022-12-08 19:25:19 +01:00
|
|
|
});
|