-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathAvatar.test.js
58 lines (49 loc) · 2.32 KB
/
Avatar.test.js
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
import {Avatar} from '../';
import React from 'react';
import {renderv3 as render, screen} from '@react-spectrum/test-utils-internal';
let isOldReact = parseInt(React.version, 10) < 18;
describe('Avatar', () => {
it('renders an avatar image', () => {
render(<Avatar src="http://localhost/some_image.png" />);
expect(screen.getByRole(isOldReact ? 'img' : 'presentation')).toBeInTheDocument();
expect(screen.getByRole(isOldReact ? 'img' : 'presentation')).toHaveAttribute('src', 'http://localhost/some_image.png');
});
it('can render an avatar image with an alt', () => {
render(<Avatar src="http://localhost/some_image.png" alt="Test avatar" />);
expect(screen.getByAltText(/test avatar/i)).toBeInTheDocument();
});
describe('when given a custom size', () => {
it('supports custom sizes in units, such as pixels', () => {
render(<Avatar src="http://localhost/some_image.png" size="80px" />);
expect(screen.getByRole(isOldReact ? 'img' : 'presentation')).toHaveStyle({
height: '80px',
width: '80px'
});
});
it('supports custom sizes in numbers', () => {
render(<Avatar src="http://localhost/some_image.png" size={80} />);
expect(screen.getByRole(isOldReact ? 'img' : 'presentation')).toHaveStyle({
height: '80px',
width: '80px'
});
});
});
it('supports custom class names', () => {
render(<Avatar src="http://localhost/some_image.png" UNSAFE_className="my-class" />);
expect(screen.getByRole(isOldReact ? 'img' : 'presentation')).toHaveAttribute('class', expect.stringContaining('my-class'));
});
it('supports style props', () => {
render(<Avatar src="http://localhost/some_image.png" isHidden />);
expect(screen.getByRole(isOldReact ? 'img' : 'presentation', {hidden: true})).toBeInTheDocument();
});
it('supports custom DOM props', () => {
render(<Avatar src="http://localhost/some_image.png" data-testid="Test avatar" />);
expect(screen.getByTestId(/test avatar/i)).toBeInTheDocument();
});
describe('when isDisabled = true', () => {
it('renders a disabled avatar image', () => {
render(<Avatar src="http://localhost/some_image.png" isDisabled />);
expect(screen.getByRole(isOldReact ? 'img' : 'presentation')).toHaveAttribute('class', expect.stringMatching(/disabled/i));
});
});
});