forked from gitify-app/gitify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepository.test.tsx
84 lines (67 loc) · 2.33 KB
/
Repository.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React from 'react';
import TestRenderer from 'react-test-renderer';
import { render, fireEvent } from '@testing-library/react';
import { AppContext } from '../context/App';
import { mockedGithubNotifications } from '../__mocks__/mockedData';
import { RepositoryNotifications } from './Repository';
const { shell } = require('electron');
jest.mock('./NotificationRow', () => ({
NotificationRow: () => <div>NotificationRow</div>,
}));
describe('components/Repository.tsx', () => {
const markRepoNotifications = jest.fn();
const markRepoNotificationsDone = jest.fn();
const props = {
hostname: 'github.com',
repoName: 'manosim/gitify',
repoNotifications: mockedGithubNotifications,
};
beforeEach(() => {
markRepoNotifications.mockReset();
jest.spyOn(shell, 'openExternal');
});
it('should render itself & its children', () => {
const tree = TestRenderer.create(
<AppContext.Provider value={{}}>
<RepositoryNotifications {...props} />
</AppContext.Provider>,
);
expect(tree).toMatchSnapshot();
});
it('should open the browser when clicking on the repo name', () => {
const { getByText } = render(
<AppContext.Provider value={{}}>
<RepositoryNotifications {...props} />
</AppContext.Provider>,
);
fireEvent.click(getByText(props.repoName));
expect(shell.openExternal).toHaveBeenCalledTimes(1);
expect(shell.openExternal).toHaveBeenCalledWith(
'https://github.com/manosim/notifications-test',
);
});
it('should mark a repo as read', function () {
const { getByTitle } = render(
<AppContext.Provider value={{ markRepoNotifications }}>
<RepositoryNotifications {...props} />
</AppContext.Provider>,
);
fireEvent.click(getByTitle('Mark Repository as Read'));
expect(markRepoNotifications).toHaveBeenCalledWith(
'manosim/notifications-test',
'github.com',
);
});
it('should mark a repo as done', function () {
const { getByTitle } = render(
<AppContext.Provider value={{ markRepoNotificationsDone }}>
<RepositoryNotifications {...props} />
</AppContext.Provider>,
);
fireEvent.click(getByTitle('Mark Repository as Done'));
expect(markRepoNotificationsDone).toHaveBeenCalledWith(
'manosim/notifications-test',
'github.com',
);
});
});