Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit a38470e

Browse files
moskeyombusgortok
authored andcommitted
added hasPermission method to cordovaPushV5 and created initial spec suite (#1335)
1 parent b041f80 commit a38470e

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/plugins/push_v5.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ angular.module('ngCordova.plugins.push_v5', [])
1414
q.resolve(push);
1515
return q.promise;
1616
},
17+
hasPermission : function () {
18+
var q = $q.defer();
19+
PushNotification.hasPermission(function(response) {
20+
q.resolve(response);
21+
});
22+
return q.promise;
23+
},
1724
onNotification : function () {
1825
$timeout(function () {
1926
push.on('notification', function (notification) {

test/plugins/push_V5.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)