Skip to content

Commit 4e92fd9

Browse files
committed
more tests
1 parent 2da5466 commit 4e92fd9

File tree

6 files changed

+97
-32
lines changed

6 files changed

+97
-32
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ See [contributing guide](.github/CONTRIBUTING.md)
9393

9494
| Date | Version | Description |
9595
| ----------- | ------- | ----------- |
96-
| 2017-03-09 | v1.0.7 | Maintenance |
96+
| 2017-03-09 | v1.0.8 | Maintenance |
9797
| 2017-01-31 | v1.0.3 | Removed polyfill dependency |
9898
| 2017-01-22 | v1.0.2 | Maintenance |
9999
| 2017-01-22 | v1.0.0 | Official release |

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-web-notification",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Web Notifications made easy.",
55
"authors": [
66
"Sagie Gur-Ari <[email protected]>"

docs/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
| Date | Version | Description |
22
| ----------- | ------- | ----------- |
3-
| 2017-03-09 | v1.0.7 | Maintenance |
3+
| 2017-03-09 | v1.0.8 | Maintenance |
44
| 2017-01-31 | v1.0.3 | Removed polyfill dependency |
55
| 2017-01-22 | v1.0.2 | Maintenance |
66
| 2017-01-22 | v1.0.0 | Official release |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-web-notification",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Web Notifications made easy.",
55
"author": {
66
"name": "Sagie Gur-Ari",

test/spec/web-notification-spec.js

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,64 @@ describe('simple-web-notification', function () {
2929
window.webNotification.allowRequest = true;
3030
});
3131

32-
it('init test', function () {
33-
assert.isObject(window.webNotification);
34-
assert.isTrue(window.Notification.MOCK_NOTIFY);
35-
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
32+
describe('showNotification tests', function () {
33+
it('window', function () {
34+
assert.isObject(window.webNotification);
35+
assert.isFunction(window.webNotification.initWebNotificationFromContext);
36+
assert.isFunction(window.webNotification.showNotification);
37+
assert.isTrue(window.Notification.MOCK_NOTIFY);
38+
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
39+
});
40+
41+
it('global', function () {
42+
var global = {
43+
Notification: window.Notification
44+
};
45+
46+
window.webNotification.initWebNotificationFromContext(global);
47+
48+
assert.isObject(global.webNotification);
49+
assert.isFunction(global.webNotification.showNotification);
50+
});
51+
52+
it('define', function () {
53+
var global = {
54+
Notification: window.Notification
55+
};
56+
57+
window.define = function (factory) {
58+
var webNotification = factory();
59+
60+
assert.isObject(webNotification);
61+
assert.isFunction(webNotification.showNotification);
62+
63+
delete window.define;
64+
};
65+
window.define.amd = true;
66+
67+
window.webNotification.initWebNotificationFromContext(global);
68+
});
69+
70+
it('module', function () {
71+
var global = {
72+
Notification: window.Notification
73+
};
74+
75+
window.module = {
76+
exports: {}
77+
};
78+
79+
window.webNotification.initWebNotificationFromContext(global);
80+
81+
assert.isFunction(window.module.exports.showNotification);
82+
83+
delete window.module;
84+
});
3685
});
3786

38-
describe('showNotification tests', function () {
39-
describe('showNotification allowed tests', function () {
40-
it('showNotification all info test', function (done) {
87+
describe('showNotification', function () {
88+
describe('allowed', function () {
89+
it('all info', function (done) {
4190
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
4291
window.Notification.setAllowed(function (title, options) {
4392
assert.equal(title, 'Example Notification');
@@ -55,7 +104,7 @@ describe('simple-web-notification', function () {
55104
});
56105
});
57106

58-
it('showNotification with auto close test', function (done) {
107+
it('auto close', function (done) {
59108
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
60109
window.Notification.setAllowed(function (title, options) {
61110
assert.equal(title, 'Example Notification');
@@ -75,7 +124,7 @@ describe('simple-web-notification', function () {
75124
});
76125
});
77126

78-
it('showNotification no params test', function (done) {
127+
it('no params', function (done) {
79128
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
80129
window.Notification.setAllowed(emptyValuesValidation);
81130

@@ -84,14 +133,14 @@ describe('simple-web-notification', function () {
84133
});
85134
});
86135

87-
it('showNotification no input test', function () {
136+
it('no input', function () {
88137
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
89138
window.Notification.setAllowed(emptyValuesValidation);
90139

91140
window.webNotification.showNotification();
92141
});
93142

94-
it('showNotification too many args test', function (done) {
143+
it('too many args', function (done) {
95144
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
96145
window.Notification.setAllowed(emptyValuesValidation);
97146

@@ -104,7 +153,7 @@ describe('simple-web-notification', function () {
104153
}, 50);
105154
});
106155

107-
it('showNotification null info test', function (done) {
156+
it('null info', function (done) {
108157
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
109158
window.Notification.setAllowed(emptyValuesValidation);
110159

@@ -113,7 +162,7 @@ describe('simple-web-notification', function () {
113162
});
114163
});
115164

116-
it('showNotification no callback test', function (done) {
165+
it('no callback', function (done) {
117166
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
118167
window.Notification.setAllowed(function (title, options) {
119168
assert.equal(title, 'Example Notification');
@@ -131,7 +180,7 @@ describe('simple-web-notification', function () {
131180
setTimeout(done, 50);
132181
});
133182

134-
it('showNotification no title test', function (done) {
183+
it('no title', function (done) {
135184
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
136185
window.Notification.setAllowed(function (title, options) {
137186
assert.equal(title, '');
@@ -148,7 +197,7 @@ describe('simple-web-notification', function () {
148197
});
149198
});
150199

151-
it('showNotification with no icon test', function (done) {
200+
it('with no icon', function (done) {
152201
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
153202
window.Notification.setAllowed(function (title, options) {
154203
assert.equal(title, 'Example Notification');
@@ -165,7 +214,7 @@ describe('simple-web-notification', function () {
165214
});
166215
});
167216

168-
it('showNotification no options test', function (done) {
217+
it('no options', function (done) {
169218
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
170219
window.Notification.setAllowed(function (title, options) {
171220
assert.equal(title, 'no options');
@@ -179,7 +228,7 @@ describe('simple-web-notification', function () {
179228
});
180229
});
181230

182-
it('showNotification first time permissions test', function (done) {
231+
it('first time permissions', function (done) {
183232
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
184233
window.Notification.setNotAllowed(function (title, options) {
185234
assert.equal(title, 'first time');
@@ -202,7 +251,7 @@ describe('simple-web-notification', function () {
202251
});
203252
});
204253

205-
it('showNotification with onClick', function (done) {
254+
it('onClick', function (done) {
206255
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
207256
window.Notification.setAllowed(function (title, options) {
208257
assert.equal(title, 'Example Notification');
@@ -221,8 +270,8 @@ describe('simple-web-notification', function () {
221270
});
222271
});
223272

224-
describe('showNotification not allowed tests', function () {
225-
it('showNotification not allowed test', function (done) {
273+
describe('not allowed', function () {
274+
it('not allowed', function (done) {
226275
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
227276
window.Notification.setNotAllowed();
228277

@@ -231,7 +280,7 @@ describe('simple-web-notification', function () {
231280
});
232281
});
233282

234-
it('showNotification not allowed and not allowed to ask permissions test', function (done) {
283+
it('not allowed to ask permissions', function (done) {
235284
assert.isTrue(window.webNotification.lib.MOCK_NOTIFY);
236285
window.Notification.setNotAllowed();
237286
window.webNotification.allowRequest = false;

web-notification.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,30 @@
2525
* @private
2626
* @param {Object} global - The root context (window/global/...)
2727
* @param {function} factory - Returns a new instance of the API
28+
* @returns {Object} New instance of the API
2829
*/
2930
(function initWebNotification(global, factory) {
3031
'use strict';
3132

3233
/*istanbul ignore next*/
33-
var webNotification = factory(global.Notification || window.Notification);
34+
var NotificationAPI = global.Notification || window.Notification;
35+
36+
var webNotification = factory(NotificationAPI);
37+
38+
/**
39+
* Initializes the web notification API (only used for testing).
40+
*
41+
* @function
42+
* @memberof! webNotification
43+
* @alias webNotification.initWebNotificationFromContext
44+
* @private
45+
* @param {Object} context - The root context (window/global/...)
46+
* @returns {Object} New instance of the API
47+
*/
48+
webNotification.initWebNotificationFromContext = function (context) {
49+
return initWebNotification(context, factory);
50+
};
3451

35-
/*istanbul ignore next*/
3652
if ((typeof define === 'function') && define.amd) {
3753
define(function defineLib() {
3854
return webNotification;
@@ -44,7 +60,7 @@
4460
}
4561

4662
return webNotification;
47-
}(this, function initWebNotification(NotifyLib) {
63+
}(this, function initWebNotification(NotificationAPI) {
4864
'use strict';
4965

5066
var webNotification = {};
@@ -56,7 +72,7 @@
5672
* @alias webNotification.lib
5773
* @private
5874
*/
59-
webNotification.lib = NotifyLib;
75+
webNotification.lib = NotificationAPI;
6076

6177
/**
6278
* True to enable automatic requesting of permissions if needed.
@@ -79,7 +95,7 @@
7995
* @returns {Boolean} True if permission is granted, else false
8096
*/
8197
get: function getPermission() {
82-
var permission = NotifyLib.permission;
98+
var permission = NotificationAPI.permission;
8399

84100
/**
85101
* True if permission is granted, else false.
@@ -149,7 +165,7 @@
149165
options.icon = '/favicon.ico';
150166
}
151167

152-
var notification = new NotifyLib(title, options);
168+
var notification = new NotificationAPI(title, options);
153169

154170
//add onclick handler
155171
if (options.onClick && notification) {
@@ -268,7 +284,7 @@
268284
hideNotification = createAndDisplayNotification(title, options);
269285
callback(null, hideNotification);
270286
} else if (webNotification.allowRequest) {
271-
NotifyLib.requestPermission(function onRequestDone() {
287+
NotificationAPI.requestPermission(function onRequestDone() {
272288
if (isEnabled()) {
273289
hideNotification = createAndDisplayNotification(title, options);
274290
callback(null, hideNotification);

0 commit comments

Comments
 (0)