2022-10-07 17:53:40 +02:00
|
|
|
/* eslint-disable jest/require-top-level-describe */
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
2023-03-10 21:12:55 +01:00
|
|
|
import { AvatarAccount, AvatarAccountSize, AvatarAccountVariant } from '.';
|
2022-10-07 17:53:40 +02:00
|
|
|
import 'jest-canvas-mock';
|
|
|
|
|
|
|
|
describe('AvatarAccount', () => {
|
2023-01-10 01:38:43 +01:00
|
|
|
it('should render correctly', () => {
|
|
|
|
const { getByTestId, container } = render(
|
2023-03-10 21:12:55 +01:00
|
|
|
<AvatarAccount
|
|
|
|
data-testid="avatar-account"
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
|
|
|
/>,
|
2022-10-07 17:53:40 +02:00
|
|
|
);
|
|
|
|
expect(getByTestId('avatar-account')).toBeDefined();
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(container.querySelector('svg')).toBeDefined();
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName('mm-avatar-account__jazzicon'),
|
|
|
|
).toBeDefined();
|
2023-01-10 01:38:43 +01:00
|
|
|
expect(container).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render Jazzicon correctly', () => {
|
2023-03-10 21:12:55 +01:00
|
|
|
const { container } = render(
|
|
|
|
<AvatarAccount
|
|
|
|
data-testid="avatar-account"
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
|
|
|
variant={AvatarAccountVariant.Jazzicon}
|
|
|
|
/>,
|
2023-01-10 01:38:43 +01:00
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(container.querySelector('svg')).toBeDefined();
|
2022-10-07 17:53:40 +02:00
|
|
|
});
|
2023-01-10 01:38:43 +01:00
|
|
|
|
2023-03-10 21:12:55 +01:00
|
|
|
it('should render Blockies correctly', () => {
|
|
|
|
const { container } = render(
|
|
|
|
<AvatarAccount
|
|
|
|
data-testid="avatar-account"
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
|
|
|
variant={AvatarAccountVariant.Blockies}
|
|
|
|
/>,
|
2023-01-10 01:38:43 +01:00
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(container.querySelector('canvas')).toBeDefined();
|
|
|
|
expect(container.querySelector('img')).toBeDefined();
|
2023-01-10 01:38:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with custom classname', () => {
|
2022-10-07 17:53:40 +02:00
|
|
|
const { getByTestId } = render(
|
2023-01-10 01:38:43 +01:00
|
|
|
<AvatarAccount
|
|
|
|
className="mm-avatar-account--test"
|
2023-03-10 21:12:55 +01:00
|
|
|
data-testid="test"
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>,
|
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(getByTestId('test')).toHaveClass('mm-avatar-account--test');
|
2023-01-10 01:38:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with address', () => {
|
|
|
|
const container = (
|
|
|
|
<AvatarAccount
|
|
|
|
className="mm-avatar-account--test"
|
2023-03-10 21:12:55 +01:00
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>
|
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(container.props.address).toStrictEqual(
|
|
|
|
'0x5CfE73b6021E818B776b421B1c4Db2474086a7e1',
|
|
|
|
);
|
2023-01-10 01:38:43 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render with different size classes', () => {
|
|
|
|
const { getByTestId } = render(
|
|
|
|
<>
|
|
|
|
<AvatarAccount
|
2023-03-10 21:12:55 +01:00
|
|
|
size={AvatarAccountSize.Xs}
|
|
|
|
data-testid={AvatarAccountSize.Xs}
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarAccount
|
2023-03-10 21:12:55 +01:00
|
|
|
size={AvatarAccountSize.Sm}
|
|
|
|
data-testid={AvatarAccountSize.Sm}
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarAccount
|
2023-03-10 21:12:55 +01:00
|
|
|
size={AvatarAccountSize.Md}
|
|
|
|
data-testid={AvatarAccountSize.Md}
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarAccount
|
2023-03-10 21:12:55 +01:00
|
|
|
size={AvatarAccountSize.Lg}
|
|
|
|
data-testid={AvatarAccountSize.Lg}
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>
|
|
|
|
<AvatarAccount
|
2023-03-10 21:12:55 +01:00
|
|
|
size={AvatarAccountSize.Xl}
|
|
|
|
data-testid={AvatarAccountSize.Xl}
|
|
|
|
address="0x5CfE73b6021E818B776b421B1c4Db2474086a7e1"
|
2023-01-10 01:38:43 +01:00
|
|
|
/>
|
|
|
|
</>,
|
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(getByTestId(AvatarAccountSize.Xs)).toHaveClass(
|
|
|
|
'mm-avatar-base--size-xs',
|
2023-01-10 01:38:43 +01:00
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(getByTestId(AvatarAccountSize.Sm)).toHaveClass(
|
|
|
|
'mm-avatar-base--size-sm',
|
2023-01-10 01:38:43 +01:00
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(getByTestId(AvatarAccountSize.Md)).toHaveClass(
|
|
|
|
'mm-avatar-base--size-md',
|
2023-01-10 01:38:43 +01:00
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(getByTestId(AvatarAccountSize.Lg)).toHaveClass(
|
|
|
|
'mm-avatar-base--size-lg',
|
2023-01-10 01:38:43 +01:00
|
|
|
);
|
2023-03-10 21:12:55 +01:00
|
|
|
expect(getByTestId(AvatarAccountSize.Xl)).toHaveClass(
|
|
|
|
'mm-avatar-base--size-xl',
|
2022-10-07 17:53:40 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|