-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathavatar.test.tsx
More file actions
59 lines (49 loc) · 1.93 KB
/
Copy pathavatar.test.tsx
File metadata and controls
59 lines (49 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from 'react';
import { render } from '@testing-library/react';
import { AVATAR_MARK, markComponent } from '../../_utils/component-markers';
import Avatar from '../index';
describe('<Avatar />', () => {
it('should match the snapshot', () => {
const { asFragment } = render(<Avatar>A</Avatar>);
expect(asFragment()).toMatchSnapshot();
});
it('should render correctly', () => {
const { container } = render(<Avatar>A</Avatar>);
expect(container.firstChild).toHaveClass('ty-avatar');
});
it('should render circle shape by default', () => {
const { container } = render(<Avatar>A</Avatar>);
expect(container.firstChild).toHaveClass('ty-avatar_circle');
});
it('should render square shape', () => {
const { container } = render(<Avatar shape="square">A</Avatar>);
expect(container.firstChild).toHaveClass('ty-avatar_square');
});
it('should render with image', () => {
const { container } = render(<Avatar src="test.jpg" />);
expect(container.querySelector('img')).toBeTruthy();
});
it('should render text content', () => {
const { getByText } = render(<Avatar>AB</Avatar>);
expect(getByText('AB')).toBeInTheDocument();
});
it('should render with custom size', () => {
const { container } = render(<Avatar size={50}>A</Avatar>);
expect(container.firstChild).toHaveStyle({ width: '50px', height: '50px' });
});
it('should recognize marker-based avatar wrappers in Avatar.Group', () => {
const WrappedAvatar = markComponent(
(props: React.ComponentProps<typeof Avatar>) => <Avatar {...props} />,
AVATAR_MARK
);
const { container } = render(
<Avatar.Group gap={-10}>
<WrappedAvatar>A</WrappedAvatar>
<WrappedAvatar>B</WrappedAvatar>
</Avatar.Group>
);
const avatars = container.querySelectorAll('.ty-avatar');
expect(avatars).toHaveLength(2);
expect(avatars[1]).toHaveStyle({ marginLeft: '-10px' });
});
});