forked from terrestris/react-geo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserChip.spec.tsx
61 lines (50 loc) · 1.95 KB
/
UserChip.spec.tsx
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
60
61
import testImage from '../../assets/user.png';
import UserChip from './UserChip';
import { render, screen } from '@testing-library/react';
import * as React from 'react';
import userEvent from '@testing-library/user-event';
describe('<UserChip />', () => {
it('is defined', () => {
expect(UserChip).not.toBeUndefined();
});
it('can be rendered', () => {
const { container } = render(<UserChip />);
expect(container).toBeVisible();
});
it('determines initials from given user name', () => {
render(<UserChip userName="Shinji Kagawa" />);
const chip = screen.getByText('SK');
expect(chip).toBeVisible();
});
it('uses imageSrc if image is given', () => {
render(<UserChip imageSrc={testImage} />);
const userImage = screen.getByRole('img');
expect(userImage).toBeVisible();
expect(userImage).toHaveAttribute('src', testImage);
});
it('uses initials if image is not given', () => {
render(<UserChip userName="Shinji Kagawa" />);
const image = screen.queryByRole('img');
expect(image).not.toBeInTheDocument();
});
it('should render a dropdown', async () => {
render(<UserChip userName="Shinji Kagawa" userMenu={<div role="menu">Example menu</div>} />);
const chip = screen.getByText('SK').parentElement;
userEvent.click(chip);
const menu = screen.getByText('Example menu');
// `toBeVisible` does not work because antd seems to be in the way
expect(menu).toBeInTheDocument();
});
it('should not render a dropdown for invalid configuration', () => {
render(<UserChip userName="Shinji Kagawa" userMenu={null} />);
const menu = screen.queryByRole('menu');
expect(menu).not.toBeInTheDocument();
});
it('should pass style prop', () => {
render(<UserChip userName="Shinji Kagawa" style={{ backgroundColor: 'yellow' }} />);
const chip = screen.getByText('Shinji Kagawa').parentElement;
expect(chip).toHaveStyle({
backgroundColor: 'yellow'
});
});
});