Skip to content

Commit d1fa069

Browse files
author
Emmanouil Konstantinidis
committed
Init NotificationsStore test
1 parent 4ebcb02 commit d1fa069

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Github Notifications on your menu bar.",
55
"main": "main.js",
66
"scripts": {
7-
"build-js": "npm run mkdir -p build/js && browserify -t reactify src/js/app.js -o build/js/app.js",
7+
"build-js": "mkdir -p build/js && browserify -t reactify src/js/app.js -o build/js/app.js",
88
"build": "npm install && mkdir -p build/js && grunt build && npm run build-js",
99
"watch-js": "watchify -t reactify src/js/app.js -o build/js/app.js -v",
1010
"watch": "grunt build && npm build && npm run watch-js | grunt watch",
@@ -65,7 +65,8 @@
6565
"src/js/actions/actions.js": true,
6666
"src/js/components/navigation.js": true,
6767
"src/js/components/footer.js": true,
68-
"src/js/stores/auth.js": true
68+
"src/js/stores/auth.js": true,
69+
"src/js/stores/notifications.js": true
6970
},
7071
"unmockedModulePathPatterns": [
7172
"node_modules/react",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*global jest, describe, it, expect, spyOn, beforeEach */
2+
3+
'use strict';
4+
5+
jest.dontMock('reflux');
6+
jest.dontMock('../../stores/notifications.js');
7+
jest.dontMock('../../utils/api-requests.js');
8+
jest.dontMock('../../actions/actions.js');
9+
10+
describe('Tests for NotificationsStore', function () {
11+
12+
var NotificationsStore, Actions, apiRequests;
13+
14+
beforeEach(function () {
15+
16+
// Mock Electron's window.require
17+
window.require = function () {
18+
return {
19+
sendChannel: function () {
20+
return;
21+
}
22+
};
23+
};
24+
25+
// Mock localStorage
26+
window.localStorage = {
27+
item: false,
28+
getItem: function () {
29+
return this.item;
30+
}
31+
};
32+
33+
Actions = require('../../actions/actions.js');
34+
apiRequests = require('../../utils/api-requests.js');
35+
NotificationsStore = require('../../stores/notifications.js');
36+
});
37+
38+
it('should get the notifications from the GitHub API', function () {
39+
40+
spyOn(NotificationsStore, 'trigger');
41+
42+
var response = [{
43+
'id': '1',
44+
'repository': {
45+
'id': 1296269,
46+
'owner': {
47+
'login': 'octocat',
48+
'id': 1,
49+
'avatar_url': 'https://github.com/images/error/octocat_happy.gif',
50+
'gravatar_id': '',
51+
'url': 'https://api.github.com/users/octocat',
52+
'html_url': 'https://github.com/octocat',
53+
'followers_url': 'https://api.github.com/users/octocat/followers',
54+
'following_url': 'https://api.github.com/users/octocat/following{/other_user}',
55+
'gists_url': 'https://api.github.com/users/octocat/gists{/gist_id}',
56+
'starred_url': 'https://api.github.com/users/octocat/starred{/owner}{/repo}',
57+
'subscriptions_url': 'https://api.github.com/users/octocat/subscriptions',
58+
'organizations_url': 'https://api.github.com/users/octocat/orgs',
59+
'repos_url': 'https://api.github.com/users/octocat/repos',
60+
'events_url': 'https://api.github.com/users/octocat/events{/privacy}',
61+
'received_events_url': 'https://api.github.com/users/octocat/received_events',
62+
'type': 'User',
63+
'site_admin': false
64+
},
65+
'name': 'Hello-World',
66+
'full_name': 'octocat/Hello-World',
67+
'description': 'This your first repo!',
68+
'private': false,
69+
'fork': false,
70+
'url': 'https://api.github.com/repos/octocat/Hello-World',
71+
'html_url': 'https://github.com/octocat/Hello-World'
72+
},
73+
'subject': {
74+
'title': 'Greetings',
75+
'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123',
76+
'latest_comment_url': 'https://api.github.com/repos/octokit/octokit.rb/issues/comments/123',
77+
'type': 'Issue'
78+
},
79+
'reason': 'subscribed',
80+
'unread': true,
81+
'updated_at': '2014-11-07T22:01:45Z',
82+
'last_read_at': '2014-11-07T22:01:45Z',
83+
'url': 'https://api.github.com/notifications/threads/1'
84+
}];
85+
86+
var superagent = require('superagent');
87+
superagent.__setResponse(200, 'ok', response, false);
88+
89+
Actions.getNotifications();
90+
91+
jest.runAllTimers();
92+
93+
var repository = NotificationsStore._notifications[0][0].repository;
94+
expect(repository.full_name).toBe('octocat/Hello-World');
95+
expect(NotificationsStore.trigger).toHaveBeenCalled();
96+
97+
});
98+
99+
});

0 commit comments

Comments
 (0)