-
Notifications
You must be signed in to change notification settings - Fork 272
/
Copy pathlinks.test.ts
105 lines (92 loc) · 3.05 KB
/
links.test.ts
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
103
104
105
import { partialMockUser } from '../__mocks__/partial-mocks';
import { mockGitHubCloudAccount } from '../__mocks__/state-mocks';
import type { Hostname, Link } from '../types';
import { mockSingleNotification } from './api/__mocks__/response-mocks';
import * as authUtils from './auth/utils';
import * as comms from './comms';
import { Constants } from './constants';
import * as helpers from './helpers';
import {
openAccountProfile,
openDeveloperSettings,
openGitHubIssues,
openGitHubNotifications,
openGitHubParticipatingDocs,
openGitHubPulls,
openGitifyReleaseNotes,
openHost,
openNotification,
openUserProfile,
} from './links';
describe('renderer/utils/links.ts', () => {
const openExternalLinkMock = jest
.spyOn(comms, 'openExternalLink')
.mockImplementation();
afterEach(() => {
jest.clearAllMocks();
});
it('openGitifyReleaseNotes', () => {
openGitifyReleaseNotes('v1.0.0');
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/gitify-app/gitify/releases/tag/v1.0.0',
);
});
it('openGitHubNotifications', () => {
openGitHubNotifications(mockGitHubCloudAccount.hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/notifications',
);
});
it('openGitHubIssues', () => {
openGitHubIssues(mockGitHubCloudAccount.hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/issues',
);
});
it('openGitHubPulls', () => {
openGitHubPulls(mockGitHubCloudAccount.hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/pulls',
);
});
it('openAccountProfile', () => {
openAccountProfile(mockGitHubCloudAccount);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/octocat',
);
});
it('openUserProfile', () => {
const mockUser = partialMockUser('mock-user');
openUserProfile(mockUser);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/mock-user',
);
});
it('openHost', () => {
openHost('github.com' as Hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith('https://github.com');
});
it('openDeveloperSettings', () => {
const mockSettingsURL = 'https://github.com/settings/tokens' as Link;
jest
.spyOn(authUtils, 'getDeveloperSettingsURL')
.mockReturnValue(mockSettingsURL);
openDeveloperSettings(mockGitHubCloudAccount);
expect(openExternalLinkMock).toHaveBeenCalledWith(mockSettingsURL);
});
it('openNotification', async () => {
const mockNotificationUrl = mockSingleNotification.repository
.html_url as Link;
jest
.spyOn(helpers, 'generateGitHubWebUrl')
.mockResolvedValue(mockNotificationUrl);
await openNotification(mockSingleNotification);
expect(openExternalLinkMock).toHaveBeenCalledWith(mockNotificationUrl);
});
it('openParticipatingDocs', () => {
openGitHubParticipatingDocs();
expect(openExternalLinkMock).toHaveBeenCalledWith(
Constants.GITHUB_DOCS.PARTICIPATING_URL,
);
});
});