diff --git a/package.json b/package.json index 334fd0eb7..c63b53c69 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "watch": "grunt build && npm build && npm run watch-js | grunt watch", "start": "electron .", "dist": "rm -rf Gitify.app/ && electron-packager . Gitify --platform=darwin --arch=x64 --version=0.27.2 --icon=images/app-icon.icns --prune --ignore=src", - "test": "jsxhint --reporter node_modules/jshint-stylish/stylish.js 'src/**/*.js', 'index.js' --exclude 'Gruntfile.js' && jscs 'src/js/' && jest", - "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" + "test": "jsxhint --reporter node_modules/jshint-stylish/stylish.js 'src/**/*.js', 'index.js' --exclude 'Gruntfile.js' && jscs 'src/js/' && jest" }, "jshintConfig": { "browserify": true, @@ -76,7 +75,8 @@ "src/js/stores/auth.js": true, "src/js/stores/notifications.js": true, "src/js/stores/search.js": true, - "src/js/stores/settings.js": true + "src/js/stores/settings.js": true, + "src/js/stores/sound-notification.js": true }, "unmockedModulePathPatterns": [ "node_modules/react", diff --git a/src/js/__tests__/components/notification.js b/src/js/__tests__/components/notification.js index a789dcf4c..8d6ae2b32 100644 --- a/src/js/__tests__/components/notification.js +++ b/src/js/__tests__/components/notification.js @@ -34,6 +34,9 @@ describe('Test for Notification Component', function () { item: false, getItem: function () { return this.item; + }, + setItem: function (item) { + this.item = item; } }; diff --git a/src/js/__tests__/components/notifications.js b/src/js/__tests__/components/notifications.js index 7b69d6463..abc5c59ff 100644 --- a/src/js/__tests__/components/notifications.js +++ b/src/js/__tests__/components/notifications.js @@ -34,6 +34,9 @@ describe('Test for Notifications Component', function () { item: false, getItem: function () { return this.item; + }, + setItem: function (item) { + this.item = item; } }; diff --git a/src/js/__tests__/components/settings.js b/src/js/__tests__/components/settings.js index da9177a7b..dd334f8ef 100644 --- a/src/js/__tests__/components/settings.js +++ b/src/js/__tests__/components/settings.js @@ -28,6 +28,9 @@ describe('Test for Settings Component', function () { item: false, getItem: function () { return this.item; + }, + setItem: function (item) { + this.item = item; } }; diff --git a/src/js/__tests__/stores/notifications.js b/src/js/__tests__/stores/notifications.js index 53fc68c15..25d51ac3b 100644 --- a/src/js/__tests__/stores/notifications.js +++ b/src/js/__tests__/stores/notifications.js @@ -27,17 +27,26 @@ describe('Tests for NotificationsStore', function () { item: false, getItem: function () { return this.item; + }, + setItem: function (item) { + this.item = item; } }; // Mock Audio - window.Audio = function (src) { - console.log('Loading Audio: ' + src); + window.Audio = function () { return { play: function () {} }; }; + // Mock Notifications + window.Notification = function () { + return { + onClick: function () {} + }; + }; + Actions = require('../../actions/actions.js'); apiRequests = require('../../utils/api-requests.js'); NotificationsStore = require('../../stores/notifications.js'); diff --git a/src/js/__tests__/stores/sound-notification.js b/src/js/__tests__/stores/sound-notification.js new file mode 100644 index 000000000..cedc6d5cc --- /dev/null +++ b/src/js/__tests__/stores/sound-notification.js @@ -0,0 +1,77 @@ +/*global jest, describe, it, expect, spyOn, beforeEach */ + +'use strict'; + +jest.dontMock('reflux'); +jest.dontMock('../../stores/sound-notification.js'); +jest.dontMock('../../utils/api-requests.js'); +jest.dontMock('../../actions/actions.js'); + +describe('Tests for SoundNotificationStore', function () { + + var SoundNotificationStore, Actions; + + beforeEach(function () { + + // Mock Electron's window.require + window.require = function () { + return { + sendChannel: function () { + return; + } + }; + }; + + // Mock localStorage + window.localStorage = { + item: false, + getItem: function () { + return this.item; + }, + setItem: function (item) { + this.item = item; + } + }; + + // Mock Audio + window.Audio = function () { + return { + play: function () {} + }; + }; + + // Mock Notifications + window.Notification = function () { + return { + onClick: function () {} + }; + }; + + Actions = require('../../actions/actions.js'); + SoundNotificationStore = require('../../stores/sound-notification.js'); + }); + + it('should get a payload and check if it should play sound & show notification.', function () { + + spyOn(SoundNotificationStore, 'showNotification'); + + var payload = [{ + 'id': '1', + 'repository': { + 'id': 1296269, + 'full_name': 'octocat/Hello-World', + 'description': 'This your first repo!' + }, + 'subject': { + 'title': 'Greetings', + 'url': 'https://api.github.com/repos/octokit/octokit.rb/issues/123' + } + }]; + + SoundNotificationStore.onIsNewNotification(payload); + + expect(SoundNotificationStore.showNotification).toHaveBeenCalled(); + + }); + +}); diff --git a/src/js/actions/actions.js b/src/js/actions/actions.js index d26dab6eb..6c476429e 100644 --- a/src/js/actions/actions.js +++ b/src/js/actions/actions.js @@ -5,6 +5,7 @@ var Actions = Reflux.createActions({ 'login': {}, 'logout': {}, 'getNotifications': {asyncResult: true}, + 'isNewNotification': {}, 'updateSearchTerm': {}, 'clearSearchTerm': {}, 'setSetting': {} diff --git a/src/js/components/settings.js b/src/js/components/settings.js index bba22e1ab..8d98f0e3b 100644 --- a/src/js/components/settings.js +++ b/src/js/components/settings.js @@ -11,7 +11,8 @@ var SettingsPage = React.createClass({ var settings = SettingsStore.getSettings(); return { participating: settings.participating, - playSound: settings.playSound + playSound: settings.playSound, + showNotifications: settings.showNotifications }; }, @@ -42,6 +43,14 @@ var SettingsPage = React.createClass({ onChange={this.toggleSetting.bind(this, 'playSound')} /> +
+
Show notifications
+
+ +
+