-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathNotificationHeader.test.tsx
More file actions
94 lines (74 loc) · 2.87 KB
/
NotificationHeader.test.tsx
File metadata and controls
94 lines (74 loc) · 2.87 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
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 { mockSettings } from '../../__mocks__/state-mocks';
import { GroupBy } from '../../types';
import * as comms from '../../utils/system/comms';
import {
NotificationHeader,
type NotificationHeaderProps,
} from './NotificationHeader';
describe('renderer/components/notifications/NotificationHeader.tsx', () => {
it('should render itself & its children - group by repositories', async () => {
const props: NotificationHeaderProps = {
notification: mockGitifyNotification,
};
const tree = renderWithAppContext(<NotificationHeader {...props} />, {
settings: { ...mockSettings, groupBy: GroupBy.REPOSITORY },
});
expect(tree.container).toMatchSnapshot();
});
describe('should render itself & its children - group by date', () => {
it('with notification number', async () => {
const props: NotificationHeaderProps = {
notification: mockGitifyNotification,
};
const tree = renderWithAppContext(<NotificationHeader {...props} />, {
settings: { ...mockSettings, groupBy: GroupBy.DATE },
});
expect(tree.container).toMatchSnapshot();
});
it('with showNumber setting disabled', async () => {
const props: NotificationHeaderProps = {
notification: mockGitifyNotification,
};
const tree = renderWithAppContext(<NotificationHeader {...props} />, {
settings: {
...mockSettings,
showNumber: false,
groupBy: GroupBy.DATE,
},
});
expect(tree.container).toMatchSnapshot();
});
it('without notification number', async () => {
const props: NotificationHeaderProps = {
notification: {
...mockGitifyNotification,
subject: { ...mockGitifyNotification.subject, number: null },
},
};
const tree = renderWithAppContext(<NotificationHeader {...props} />, {
settings: { ...mockSettings, groupBy: GroupBy.DATE },
});
expect(tree.container).toMatchSnapshot();
});
});
it('should open notification user profile - group by date', async () => {
const openExternalLinkSpy = vi
.spyOn(comms, 'openExternalLink')
.mockImplementation(vi.fn());
const props: NotificationHeaderProps = {
notification: mockGitifyNotification,
};
renderWithAppContext(<NotificationHeader {...props} />, {
settings: { ...mockSettings, groupBy: GroupBy.DATE },
});
await userEvent.click(screen.getByTestId('view-repository'));
expect(openExternalLinkSpy).toHaveBeenCalledTimes(1);
expect(openExternalLinkSpy).toHaveBeenCalledWith(
props.notification.repository.htmlUrl,
);
});
});