-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathNotificationFooter.test.tsx
More file actions
102 lines (78 loc) · 3.12 KB
/
NotificationFooter.test.tsx
File metadata and controls
102 lines (78 loc) · 3.12 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { mockGitifyNotification } from '../../__mocks__/notifications-mocks';
import type { GitifyNotificationUser, Link } from '../../types';
import * as comms from '../../utils/system/comms';
import {
NotificationFooter,
type NotificationFooterProps,
} from './NotificationFooter';
describe('renderer/components/notifications/NotificationFooter.tsx', () => {
vi.spyOn(globalThis.Date, 'now').mockImplementation(() =>
new Date('2024').valueOf(),
);
it('should render itself & its children', async () => {
const props: NotificationFooterProps = {
notification: mockGitifyNotification,
};
const tree = renderWithAppContext(<NotificationFooter {...props} />);
expect(tree.container).toMatchSnapshot();
});
describe('security alerts should use github icon for avatar', () => {
it('Repository Dependabot Alerts Thread', async () => {
const mockNotification = mockGitifyNotification;
mockNotification.subject.type = 'RepositoryDependabotAlertsThread';
const props: NotificationFooterProps = {
notification: mockNotification,
};
const tree = renderWithAppContext(<NotificationFooter {...props} />);
expect(tree.container).toMatchSnapshot();
});
it('Repository Vulnerability Alert', async () => {
const mockNotification = mockGitifyNotification;
mockNotification.subject.type = 'RepositoryVulnerabilityAlert';
const props: NotificationFooterProps = {
notification: mockNotification,
};
const tree = renderWithAppContext(<NotificationFooter {...props} />);
expect(tree.container).toMatchSnapshot();
});
});
it('should default to known avatar if no user found', async () => {
const mockNotification = mockGitifyNotification;
mockNotification.subject.user = null;
const props: NotificationFooterProps = {
notification: mockNotification,
};
const tree = renderWithAppContext(<NotificationFooter {...props} />);
expect(tree.container).toMatchSnapshot();
});
it('should open notification user profile', async () => {
const openExternalLinkSpy = vi
.spyOn(comms, 'openExternalLink')
.mockImplementation(vi.fn());
const props: NotificationFooterProps = {
notification: {
...mockGitifyNotification,
subject: {
...mockGitifyNotification.subject,
user: {
login: 'some-user',
htmlUrl: 'https://github.com/some-user' as Link,
avatarUrl:
'https://avatars.githubusercontent.com/u/583231?v=4' as Link,
type: 'User' as GitifyNotificationUser['type'],
},
reviews: null,
},
},
};
renderWithAppContext(<NotificationFooter {...props} />);
await userEvent.click(screen.getByTestId('view-profile'));
expect(openExternalLinkSpy).toHaveBeenCalledTimes(1);
expect(openExternalLinkSpy).toHaveBeenCalledWith(
props.notification.subject.user.htmlUrl,
);
});
});