|
| 1 | +describe('Service: $cordovaPushV5', function() { |
| 2 | + |
| 3 | + var $cordovaPushV5, $rootScope; |
| 4 | + |
| 5 | + beforeEach(module('ngCordova.plugins.push_v5')); |
| 6 | + |
| 7 | + beforeEach(inject(function (_$cordovaPushV5_, _$rootScope_) { |
| 8 | + $cordovaPushV5 = _$cordovaPushV5_; |
| 9 | + $rootScope = _$rootScope_; |
| 10 | + |
| 11 | + |
| 12 | + window.PushNotification = { |
| 13 | + init: angular.noop, |
| 14 | + hasPermission: angular.noop, |
| 15 | + }; |
| 16 | + })); |
| 17 | + |
| 18 | + it('should call the PushNotification.init method', function() { |
| 19 | + |
| 20 | + var result; |
| 21 | + var config = { someConfig: 1 }; |
| 22 | + |
| 23 | + spyOn(window.PushNotification, 'init').and.returnValue(true); |
| 24 | + |
| 25 | + $cordovaPushV5.initialize(config) |
| 26 | + .then(function (response) { |
| 27 | + result = response; |
| 28 | + }); |
| 29 | + |
| 30 | + $rootScope.$digest(); |
| 31 | + expect(window.PushNotification.init.calls.argsFor(0)[0]).toBe(config); |
| 32 | + expect(result).toBe(true); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should call the PushNotification.hasPermission method', function() { |
| 36 | + |
| 37 | + var result; |
| 38 | + |
| 39 | + spyOn(window.PushNotification, 'hasPermission') |
| 40 | + .and.callFake(function (successCb) { |
| 41 | + successCb({ isEnabled: true }); |
| 42 | + }); |
| 43 | + |
| 44 | + $cordovaPushV5.hasPermission() |
| 45 | + .then(function (response) { |
| 46 | + result = response; |
| 47 | + }); |
| 48 | + |
| 49 | + $rootScope.$digest(); |
| 50 | + expect(window.PushNotification.hasPermission).toHaveBeenCalled; |
| 51 | + expect(result.isEnabled).toBe(true); |
| 52 | + }); |
| 53 | +}); |
0 commit comments