Skip to content

Commit 62532c9

Browse files
author
Emmanouil Konstantinidis
committed
Tests for 'sound-notification' store
1 parent 06093ae commit 62532c9

File tree

4 files changed

+80
-16
lines changed

4 files changed

+80
-16
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
"src/js/stores/auth.js": true,
7777
"src/js/stores/notifications.js": true,
7878
"src/js/stores/search.js": true,
79-
"src/js/stores/settings.js": true
79+
"src/js/stores/settings.js": true,
80+
"src/js/stores/sound-notification.js": true
8081
},
8182
"unmockedModulePathPatterns": [
8283
"node_modules/react",

src/js/__tests__/stores/notifications.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,6 @@ describe('Tests for NotificationsStore', function () {
3333
}
3434
};
3535

36-
// Mock Audio
37-
window.Audio = function () {
38-
return {
39-
play: function () {}
40-
};
41-
};
42-
43-
// Mock Notifications
44-
window.Notification = function () {
45-
return {
46-
onClick: function () {}
47-
};
48-
};
49-
5036
Actions = require('../../actions/actions.js');
5137
apiRequests = require('../../utils/api-requests.js');
5238
NotificationsStore = require('../../stores/notifications.js');
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*global jest, describe, it, expect, spyOn, beforeEach */
2+
3+
'use strict';
4+
5+
jest.dontMock('reflux');
6+
jest.dontMock('../../stores/sound-notification.js');
7+
jest.dontMock('../../utils/api-requests.js');
8+
jest.dontMock('../../actions/actions.js');
9+
10+
describe('Tests for SoundNotificationStore', function () {
11+
12+
var SoundNotificationStore, Actions;
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+
setItem: function (item) {
32+
this.item = item;
33+
}
34+
};
35+
36+
// Mock Audio
37+
window.Audio = function () {
38+
return {
39+
play: function () {}
40+
};
41+
};
42+
43+
// Mock Notifications
44+
window.Notification = function () {
45+
return {
46+
onClick: function () {}
47+
};
48+
};
49+
50+
Actions = require('../../actions/actions.js');
51+
SoundNotificationStore = require('../../stores/sound-notification.js');
52+
});
53+
54+
it('should get a payload and check if it should play sound & show notification.', function () {
55+
56+
spyOn(SoundNotificationStore, 'showNotification');
57+
58+
var payload = [{
59+
'id': '1',
60+
'repository': {
61+
'id': 1296269,
62+
'full_name': 'octocat/Hello-World',
63+
'description': 'This your first repo!'
64+
},
65+
'subject': {
66+
'title': 'Greetings',
67+
'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123'
68+
}
69+
}];
70+
71+
SoundNotificationStore.onIsNewNotification(payload);
72+
73+
expect(SoundNotificationStore.showNotification).toHaveBeenCalled();
74+
75+
});
76+
77+
});

src/js/stores/sound-notification.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var Reflux = require('reflux');
33
var _ = require('underscore');
44

55
var Actions = require('../actions/actions');
6-
var SettingsStore = require('../settings');
6+
var SettingsStore = require('../stores/settings');
77

88
var SoundNotificationStore = Reflux.createStore({
99
listenables: Actions,

0 commit comments

Comments
 (0)