2022-10-13 01:22:21 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
|
2023-01-11 17:11:06 +01:00
|
|
|
import { AvatarFavicon, AVATAR_FAVICON_SIZES } from '.';
|
2022-10-13 01:22:21 +02:00
|
|
|
|
|
|
|
describe('AvatarFavicon', () => {
|
|
|
|
const args = {
|
2023-04-19 17:25:19 +02:00
|
|
|
src: './images/eth_logo.png',
|
2023-02-14 18:34:19 +01:00
|
|
|
name: 'test',
|
2022-10-13 01:22:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
it('should render correctly', () => {
|
2023-01-11 17:11:06 +01:00
|
|
|
const { getByTestId, container } = render(
|
2023-02-14 18:34:19 +01:00
|
|
|
<AvatarFavicon name="test" data-testid="avatar-favicon" />,
|
2022-10-13 01:22:21 +02:00
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-favicon')).toBeDefined();
|
2023-01-11 17:11:06 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
2022-10-13 01:22:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render image of Avatar Favicon', () => {
|
|
|
|
render(<AvatarFavicon data-testid="avatar-favicon" {...args} />);
|
|
|
|
const image = screen.getByRole('img');
|
|
|
|
expect(image).toBeDefined();
|
2023-01-11 17:11:06 +01:00
|
|
|
expect(image).toHaveAttribute('src', args.src);
|
2022-10-13 01:22:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render fallback image if no ImageSource is provided', () => {
|
|
|
|
const { container } = render(
|
2023-02-14 18:34:19 +01:00
|
|
|
<AvatarFavicon name="test" data-testid="avatar-favicon" />,
|
2022-10-13 01:22:21 +02:00
|
|
|
);
|
2022-11-23 18:58:43 +01:00
|
|
|
expect(container.getElementsByClassName('mm-icon')).toHaveLength(1);
|
2022-10-13 01:22:21 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render fallback image with custom fallbackIconProps if no ImageSource is provided', () => {
|
|
|
|
const container = (
|
|
|
|
<AvatarFavicon
|
2023-02-14 18:34:19 +01:00
|
|
|
name="test"
|
2022-10-13 01:22:21 +02:00
|
|
|
data-testid="avatar-favicon"
|
|
|
|
fallbackIconProps={{
|
|
|
|
'data-testid': 'fallback-icon',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(container.props.fallbackIconProps['data-testid']).toStrictEqual(
|
|
|
|
'fallback-icon',
|
|
|
|
);
|
|
|
|
});
|
2023-01-11 17:11:06 +01:00
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarFavicon
|
|
|
|
size={AVATAR_FAVICON_SIZES.XS}
|
|
|
|
data-testid={AVATAR_FAVICON_SIZES.XS}
|
|
|
|
{...args}
|
|
|
|
/>
|
|
|
|
<AvatarFavicon
|
|
|
|
size={AVATAR_FAVICON_SIZES.SM}
|
|
|
|
data-testid={AVATAR_FAVICON_SIZES.SM}
|
|
|
|
{...args}
|
|
|
|
/>
|
|
|
|
<AvatarFavicon
|
|
|
|
size={AVATAR_FAVICON_SIZES.MD}
|
|
|
|
data-testid={AVATAR_FAVICON_SIZES.MD}
|
|
|
|
{...args}
|
|
|
|
/>
|
|
|
|
<AvatarFavicon
|
|
|
|
size={AVATAR_FAVICON_SIZES.LG}
|
|
|
|
data-testid={AVATAR_FAVICON_SIZES.LG}
|
|
|
|
{...args}
|
|
|
|
/>
|
|
|
|
<AvatarFavicon
|
|
|
|
size={AVATAR_FAVICON_SIZES.XL}
|
|
|
|
data-testid={AVATAR_FAVICON_SIZES.XL}
|
|
|
|
{...args}
|
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
|
|
|
expect(getByTestId(AVATAR_FAVICON_SIZES.XS)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AVATAR_FAVICON_SIZES.XS}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(AVATAR_FAVICON_SIZES.SM)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AVATAR_FAVICON_SIZES.SM}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(AVATAR_FAVICON_SIZES.MD)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AVATAR_FAVICON_SIZES.MD}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(AVATAR_FAVICON_SIZES.LG)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AVATAR_FAVICON_SIZES.LG}`,
|
|
|
|
);
|
|
|
|
expect(getByTestId(AVATAR_FAVICON_SIZES.XL)).toHaveClass(
|
|
|
|
`mm-avatar-base--size-${AVATAR_FAVICON_SIZES.XL}`,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with custom classname', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<AvatarFavicon
|
|
|
|
className="mm-avatar-favicon--test"
|
2023-02-14 18:34:19 +01:00
|
|
|
name="test"
|
2023-01-11 17:11:06 +01:00
|
|
|
data-testid="classname"
|
|
|
|
{...args}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
expect(getByTestId('classname')).toHaveClass('mm-avatar-favicon--test');
|
|
|
|
});
|
2023-04-21 17:51:34 +02:00
|
|
|
it('should forward a ref to the root html element', () => {
|
|
|
|
const ref = React.createRef();
|
|
|
|
render(<AvatarFavicon name="test" ref={ref} />);
|
|
|
|
expect(ref.current).not.toBeNull();
|
|
|
|
expect(ref.current.nodeName).toBe('DIV');
|
|
|
|
});
|
2022-10-13 01:22:21 +02:00
|
|
|
});
|