Skip to content

Commit ec48b24

Browse files
author
Emmanouil Konstantinidis
committed
Tests for Notifications Component
1 parent ed5d4b7 commit ec48b24

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"collectCoverageOnlyFrom": {
6565
"src/js/actions/actions.js": true,
6666
"src/js/components/navigation.js": true,
67+
"src/js/components/notifications.js": true,
6768
"src/js/components/footer.js": true,
6869
"src/js/stores/auth.js": true,
6970
"src/js/stores/notifications.js": true
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* global jest, describe, beforeEach, it, expect, spyOn */
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 Notifications Component', function () {
14+
15+
var Actions, AuthStore, Notification, 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+
Actions = require('../../actions/actions.js');
41+
AuthStore = require('../../stores/auth.js');
42+
Notification = require('../../components/notifications.js');
43+
NotificationsStore = require('../../stores/notifications.js');
44+
});
45+
46+
it('Should render the notifications component', function () {
47+
48+
AuthStore.authStatus = function () {
49+
return true;
50+
};
51+
52+
var instance = TestUtils.renderIntoDocument(<Notification />);
53+
expect(instance.state.loading).toBeTruthy();
54+
55+
var response = [[{
56+
'repository': {
57+
'full_name': 'ekonstantinidis/gitify',
58+
'owner': {
59+
'avatar_url': 'http://avatar.url'
60+
}
61+
},
62+
'subject': {
63+
'type': 'Issue'
64+
}
65+
}]];
66+
67+
NotificationsStore.trigger(response);
68+
expect(instance.state.notifications.length).toBe(1);
69+
70+
expect(instance.state.loading).toBeTruthy();
71+
instance.completedNotifications();
72+
expect(instance.state.loading).toBeFalsy();
73+
74+
});
75+
76+
});

src/js/components/notifications.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ var Notifications = React.createClass({
3434
render: function () {
3535
var notifications;
3636
var wrapperClass = 'container-fluid main-container notifications';
37-
var self = this;
3837

3938
if (_.isEmpty(this.state.notifications)) {
4039
wrapperClass += ' all-read';
@@ -47,7 +46,7 @@ var Notifications = React.createClass({
4746
);
4847
} else {
4948
notifications = (
50-
this.state.notifications.map(function (obj, i) {
49+
this.state.notifications.map(function (obj) {
5150
var repoFullName = obj[0].repository.full_name;
5251
return <Repository repo={obj} repoName={repoFullName} key={repoFullName} />;
5352
})

0 commit comments

Comments
 (0)