summaryrefslogtreecommitdiff
path: root/plugins/phonegap-plugin-push/spec/index.spec.js
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-10-18 20:27:36 -0400
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-10-18 20:27:36 -0400
commitced14a385a8606319e5d7d604f65c7a33c8e1476 (patch)
treea146b48048b31fd36c6a0336052ee5d2c34093b4 /plugins/phonegap-plugin-push/spec/index.spec.js
parent50f2e00b5be8c0e13e5790c11cc2dc234577d447 (diff)
switched to new push plugin that works with JSON payloads
Diffstat (limited to 'plugins/phonegap-plugin-push/spec/index.spec.js')
-rw-r--r--plugins/phonegap-plugin-push/spec/index.spec.js160
1 files changed, 160 insertions, 0 deletions
diff --git a/plugins/phonegap-plugin-push/spec/index.spec.js b/plugins/phonegap-plugin-push/spec/index.spec.js
new file mode 100644
index 00000000..f794fae5
--- /dev/null
+++ b/plugins/phonegap-plugin-push/spec/index.spec.js
@@ -0,0 +1,160 @@
+/*!
+ * Module dependencies.
+ */
+
+var cordova = require('./helper/cordova'),
+ PushNotification = require('../www/push'),
+ execSpy,
+ execWin,
+ options;
+
+/*!
+ * Specification.
+ */
+
+describe('phonegap-plugin-push', function() {
+ beforeEach(function() {
+ options = { android: {}, ios: {}, windows: {} };
+ execWin = jasmine.createSpy();
+ execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
+ });
+
+ describe('PushNotification', function() {
+ it("should exist", function() {
+ expect(PushNotification).toBeDefined();
+ expect(typeof PushNotification == 'object').toBe(true);
+ });
+
+ it("should contain a init function", function() {
+ expect(PushNotification.init).toBeDefined();
+ expect(typeof PushNotification.init == 'function').toBe(true);
+ });
+
+ it("should contain a unregister function", function() {
+ var push = PushNotification.init({});
+ expect(push.unregister).toBeDefined();
+ expect(typeof push.unregister == 'function').toBe(true);
+ });
+
+ it("should contain a setApplicationIconBadgeNumber function", function() {
+ var push = PushNotification.init({});
+ expect(push.setApplicationIconBadgeNumber).toBeDefined();
+ expect(typeof push.setApplicationIconBadgeNumber == 'function').toBe(true);
+ });
+ });
+
+ describe('PushNotification instance', function() {
+ describe('cordova.exec', function() {
+ it('should call cordova.exec on next process tick', function(done) {
+ PushNotification.init(options);
+ setTimeout(function() {
+ expect(execSpy).toHaveBeenCalledWith(
+ jasmine.any(Function),
+ jasmine.any(Function),
+ 'PushNotification',
+ 'init',
+ jasmine.any(Object)
+ );
+ done();
+ }, 100);
+ });
+ });
+
+ describe('on "registration" event', function() {
+ it('should be emitted with an argument', function(done) {
+ execSpy.andCallFake(function(win, fail, service, id, args) {
+ win({ 'registrationId': 1 });
+ });
+ var push = PushNotification.init(options);
+ push.on('registration', function(data) {
+ expect(data.registrationId).toEqual(1);
+ done();
+ });
+ });
+ });
+
+ describe('on "notification" event', function() {
+ beforeEach(function() {
+ execSpy.andCallFake(function(win, fail, service, id, args) {
+ win({
+ message: 'Message',
+ title: 'Title',
+ count: 1,
+ sound: 'beep',
+ image: 'Image',
+ additionalData: {}
+ });
+ });
+ });
+
+ it('should be emitted on success', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ done();
+ });
+ });
+
+ it('should provide the data.message argument', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ expect(data.message).toEqual('Message');
+ done();
+ });
+ });
+
+ it('should provide the data.title argument', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ expect(data.title).toEqual('Title');
+ done();
+ });
+ });
+
+ it('should provide the data.count argument', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ expect(data.count).toEqual(1);
+ done();
+ });
+ });
+
+ it('should provide the data.sound argument', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ expect(data.sound).toEqual('beep');
+ done();
+ });
+ });
+
+ it('should provide the data.image argument', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ expect(data.image).toEqual('Image');
+ done();
+ });
+ });
+
+ it('should provide the data.additionalData argument', function(done) {
+ var push = PushNotification.init(options);
+ push.on('notification', function(data) {
+ expect(data.additionalData).toEqual({});
+ done();
+ });
+ });
+ });
+
+ describe('on "error" event', function() {
+ it('should be emitted with an Error', function(done) {
+ execSpy.andCallFake(function(win, fail, service, id, args) {
+ fail('something went wrong');
+ });
+ var push = PushNotification.init(options);
+ push.on('error', function(e) {
+ expect(e).toEqual(jasmine.any(Error));
+ expect(e.message).toEqual('something went wrong');
+ done();
+ });
+ });
+ });
+ });
+});