-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy pathAvatarWithFallback.test.tsx
67 lines (51 loc) · 2.09 KB
/
AvatarWithFallback.test.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
62
63
64
65
66
67
import { render, screen } from '@testing-library/react';
import { type Link, Size } from '../../types';
import {
AvatarWithFallback,
type IAvatarWithFallback,
} from './AvatarWithFallback';
describe('renderer/components/avatars/AvatarWithFallback.tsx', () => {
const props: IAvatarWithFallback = {
src: 'https://avatars.githubusercontent.com/u/133795385?s=200&v=4' as Link,
alt: 'gitify-app',
name: '@gitify-app',
size: Size.MEDIUM,
userType: 'User',
};
it('should render avatar - human user', () => {
const tree = render(<AvatarWithFallback {...props} />);
expect(tree).toMatchSnapshot();
});
it('should render avatar - non-human user', () => {
const tree = render(
<AvatarWithFallback {...props} userType={'Organization'} />,
);
expect(tree).toMatchSnapshot();
});
it('renders the fallback icon when no src url - human user', () => {
const tree = render(<AvatarWithFallback {...props} src={null} />);
expect(tree).toMatchSnapshot();
});
it('renders the fallback icon when no src url - non human user', () => {
const tree = render(
<AvatarWithFallback {...props} src={null} userType="Bot" />,
);
expect(tree).toMatchSnapshot();
});
it('renders the fallback icon when the image fails to load (isBroken = true) - human user', () => {
render(<AvatarWithFallback {...props} />);
// Find the avatar element by its alt text
const avatar = screen.getByAltText('gitify-app') as HTMLImageElement;
// Simulate an error event on the image element
avatar.dispatchEvent(new Event('error'));
expect(screen.getByTestId('avatar')).toMatchSnapshot();
});
it('renders the fallback icon when the image fails to load (isBroken = true) - non human user', () => {
render(<AvatarWithFallback {...props} userType={'Bot'} />);
// Find the avatar element by its alt text
const avatar = screen.getByAltText('gitify-app') as HTMLImageElement;
// Simulate an error event on the image element
avatar.dispatchEvent(new Event('error'));
expect(screen.getByTestId('avatar')).toMatchSnapshot();
});
});