Skip to content

Commit 5c3309c

Browse files
author
Emmanouil Konstantinidis
committed
Init test for 'notification' component
1 parent aeaa39e commit 5c3309c

File tree

3 files changed

+139
-4
lines changed

3 files changed

+139
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"collectCoverageOnlyFrom": {
6666
"src/js/actions/actions.js": true,
6767
"src/js/components/navigation.js": true,
68+
"src/js/components/notification.js": true,
6869
"src/js/components/notifications.js": true,
6970
"src/js/components/repository.js": true,
7071
"src/js/components/footer.js": true,
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/* global jest, describe, beforeEach, it, expect */
2+
3+
jest.dontMock('reflux');
4+
jest.dontMock('../../actions/actions.js');
5+
jest.dontMock('../../utils/api-requests');
6+
jest.dontMock('../../components/notification.js');
7+
jest.dontMock('../../stores/auth.js');
8+
jest.dontMock('../../stores/notifications.js');
9+
10+
var React = require('react/addons');
11+
var TestUtils = React.addons.TestUtils;
12+
13+
describe('Test for Notification Component', function () {
14+
15+
var apiRequests, Actions, AuthStore, SingleNotification, NotificationsStore;
16+
17+
beforeEach(function () {
18+
// Mock Electron's window.require
19+
// and remote.require('shell')
20+
window.require = function () {
21+
return {
22+
require: function () {
23+
return {
24+
openExternal: function () {
25+
return {};
26+
}
27+
};
28+
}
29+
};
30+
};
31+
32+
// Mock localStorage
33+
window.localStorage = {
34+
item: false,
35+
getItem: function () {
36+
return this.item;
37+
}
38+
};
39+
40+
apiRequests = require('../../utils/api-requests.js');
41+
Actions = require('../../actions/actions.js');
42+
AuthStore = require('../../stores/auth.js');
43+
SingleNotification = require('../../components/notification.js');
44+
NotificationsStore = require('../../stores/notifications.js');
45+
});
46+
47+
it('Should render a notification component (Issue)', function () {
48+
49+
var notification = {
50+
'id': '123123123',
51+
'repository': {
52+
'full_name': 'ekonstantinidis/gitify',
53+
'owner': {
54+
'avatar_url': 'http://avatar.url'
55+
}
56+
},
57+
'subject': {
58+
'type': 'Issue',
59+
'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
60+
}
61+
};
62+
63+
var instance = TestUtils.renderIntoDocument(
64+
<SingleNotification
65+
notification={notification}
66+
key={notification.id} />);
67+
68+
expect(instance.state.readClass).toBe('row notification');
69+
expect(instance.state.read).toBeFalsy();
70+
expect(instance.openBrowser).toBeDefined();
71+
expect(instance.markAsRead).toBeDefined();
72+
73+
// Open Browser
74+
instance.openBrowser();
75+
76+
});
77+
78+
it('Should render a notification component (PullRequest)', function () {
79+
80+
var notification = {
81+
'id': '123123123',
82+
'repository': {
83+
'full_name': 'ekonstantinidis/gitify',
84+
'owner': {
85+
'avatar_url': 'http://avatar.url'
86+
}
87+
},
88+
'subject': {
89+
'type': 'PullRequest',
90+
'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
91+
}
92+
};
93+
94+
var instance = TestUtils.renderIntoDocument(
95+
<SingleNotification
96+
notification={notification}
97+
key={notification.id} />);
98+
99+
expect(instance.state.readClass).toBe('row notification');
100+
expect(instance.state.read).toBeFalsy();
101+
expect(instance.openBrowser).toBeDefined();
102+
expect(instance.markAsRead).toBeDefined();
103+
104+
});
105+
106+
it('Should render a notification component (OtherType)', function () {
107+
108+
var notification = {
109+
'id': '123123123',
110+
'repository': {
111+
'full_name': 'ekonstantinidis/gitify',
112+
'owner': {
113+
'avatar_url': 'http://avatar.url'
114+
}
115+
},
116+
'subject': {
117+
'type': 'OtherType',
118+
'url': 'http://www.github.com/ekonstantinidis/gitify/pulls/26/'
119+
}
120+
};
121+
122+
var instance = TestUtils.renderIntoDocument(
123+
<SingleNotification
124+
notification={notification}
125+
key={notification.id} />);
126+
127+
expect(instance.state.readClass).toBe('row notification');
128+
expect(instance.state.read).toBeFalsy();
129+
expect(instance.openBrowser).toBeDefined();
130+
expect(instance.markAsRead).toBeDefined();
131+
132+
});
133+
134+
});

src/js/__tests__/components/notifications.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
jest.dontMock('reflux');
44
jest.dontMock('../../actions/actions.js');
55
jest.dontMock('../../utils/api-requests');
6-
jest.dontMock('../../components/notification.js');
6+
jest.dontMock('../../components/notifications.js');
77
jest.dontMock('../../stores/auth.js');
88
jest.dontMock('../../stores/notifications.js');
99

@@ -12,7 +12,7 @@ var TestUtils = React.addons.TestUtils;
1212

1313
describe('Test for Notifications Component', function () {
1414

15-
var Actions, AuthStore, Notification, NotificationsStore;
15+
var Actions, AuthStore, Notifications, NotificationsStore;
1616

1717
beforeEach(function () {
1818
// Mock Electron's window.require
@@ -39,7 +39,7 @@ describe('Test for Notifications Component', function () {
3939

4040
Actions = require('../../actions/actions.js');
4141
AuthStore = require('../../stores/auth.js');
42-
Notification = require('../../components/notifications.js');
42+
Notifications = require('../../components/notifications.js');
4343
NotificationsStore = require('../../stores/notifications.js');
4444
});
4545

@@ -49,7 +49,7 @@ describe('Test for Notifications Component', function () {
4949
return true;
5050
};
5151

52-
var instance = TestUtils.renderIntoDocument(<Notification />);
52+
var instance = TestUtils.renderIntoDocument(<Notifications />);
5353
expect(instance.state.loading).toBeTruthy();
5454

5555
var response = [[{

0 commit comments

Comments
 (0)