Skip to content

Commit

Permalink
test: Coverage for Notification delegate shim
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Jan 6, 2020
1 parent 46fe475 commit 63bb984
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/tab-manager/__tests__/browser-notification-shim.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
describe('Browser Notification Shim test suite', () => {
test('Native Notification should be shimmed and used as delegate', () => {
// Given
const NativeNotification = jest.fn();
NativeNotification.maxActions = jest.fn();
NativeNotification.permission = jest.fn();
NativeNotification.requestPermission = jest.fn();
NativeNotification.prototype = {
actions: 'Actions', badge: 'Badge', body: 'Body', data: 'Data', dir: 'Dir', lang: 'Lang', tag: 'Tag', icon: 'Icon',
image: 'Image', renotify: 'Renotify', requireInteraction: 'RequireInteraction', silent: 'Silent',
timestamp: 'Timestamp', title: 'Title', vibrate: 'Vibrate', close: jest.fn()
};
window.Notification = NativeNotification;
require('../browser-notification-shim');
// When
const notification = new Notification();
Notification.maxActions();
Notification.permission();
Notification.requestPermission();
// Then
expect(window.Notification).not.toBe(NativeNotification);
expect(NativeNotification).toHaveBeenCalledTimes(1);
expect(NativeNotification.maxActions).toHaveBeenCalledTimes(1);
expect(NativeNotification.permission).toHaveBeenCalledTimes(1);
expect(NativeNotification.requestPermission).toHaveBeenCalledTimes(1);
expect(notification.actions).toBe('Actions');
expect(notification.badge).toBe('Badge');
expect(notification.body).toBe('Body');
expect(notification.data).toBe('Data');
expect(notification.dir).toBe('Dir');
expect(notification.lang).toBe('Lang');
expect(notification.tag).toBe('Tag');
expect(notification.icon).toBe('Icon');
expect(notification.image).toBe('Image');
expect(notification.renotify).toBe('Renotify');
expect(notification.requireInteraction).toBe('RequireInteraction');
expect(notification.silent).toBe('Silent');
expect(notification.timestamp).toBe('Timestamp');
expect(notification.title).toBe('Title');
expect(notification.vibrate).toBe('Vibrate');
notification.close();
expect(NativeNotification.prototype.close).toHaveBeenCalledTimes(1);
});
});
6 changes: 5 additions & 1 deletion src/tab-manager/browser-notification-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
limitations under the License.
*/
/* eslint-disable no-global-assign,no-native-reassign */

// Delegate for Notification API as specified in: https://notifications.spec.whatwg.org/

const {ipcRenderer} = require('electron');
const {APP_EVENTS} = require('../constants');

Expand Down Expand Up @@ -96,10 +99,11 @@ Notification = function() {
delegate.onshow = func;
},
get close() {
return delegate.close();
return delegate.close;
}
};
};

Notification.maxActions = NativeNotification.maxActions;
Notification.permission = NativeNotification.permission;
Notification.requestPermission = NativeNotification.requestPermission;

0 comments on commit 63bb984

Please sign in to comment.