summaryrefslogtreecommitdiff
path: root/plugins/phonegap-plugin-push/spec
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/phonegap-plugin-push/spec')
-rw-r--r--plugins/phonegap-plugin-push/spec/helper/cordova.js83
-rw-r--r--plugins/phonegap-plugin-push/spec/index.spec.js160
2 files changed, 0 insertions, 243 deletions
diff --git a/plugins/phonegap-plugin-push/spec/helper/cordova.js b/plugins/phonegap-plugin-push/spec/helper/cordova.js
deleted file mode 100644
index 02bdee5f..00000000
--- a/plugins/phonegap-plugin-push/spec/helper/cordova.js
+++ /dev/null
@@ -1,83 +0,0 @@
-/* global cordova:true */
-
-/*!
- * Module dependencies.
- */
-
-/**
- * cordova.js for node.
- *
- * Think of this as cordova-node, which would be simliar to cordova-android
- * or cordova-browser. The purpose of this module is to enable testing
- * of a plugin's JavaScript interface.
- *
- * When this module is first required, it will insert a global cordova
- * instance, which can hijack cordova-specific commands within the pluin's
- * implementation.
- *
- * Remember to require this module before the plugin that you want to test.
- *
- * Example:
- *
- * var cordova = require('./helper/cordova'),
- * myPlugin = require('../www/myPlugin');
- */
-
-module.exports = global.cordova = cordova = {
-
- /**
- * cordova.require Mock.
- *
- * Hijacks all cordova.requires. By default, it returns an empty function.
- * You can define your own implementation of each required module before
- * or after it has been required.
- *
- * See `cordova.required` to learn how to add your own module implemtnation.
- */
-
- require: function(moduleId) {
- // define a default function if it doesn't exist
- if (!cordova.required[moduleId]) {
- cordova.required[moduleId] = function() {};
- }
- // create a new module mapping between the module Id and cordova.required.
- return new ModuleMap(moduleId);
- },
-
- /**
- * Cordova module implementations.
- *
- * A key-value hash, where the key is the module such as 'cordova/exec'
- * and the value is the function or object returned.
- *
- * For example:
- *
- * var exec = require('cordova/exec');
- *
- * Will map to:
- *
- * cordova.required['cordova/exec'];
- */
-
- required: {
- // populated at runtime
- }
-};
-
-/**
- * Module Mapper.
- *
- * Returns a function that when executed will lookup the implementation
- * in cordova.required[id].
- *
- * @param {String} moduleId is the module name/path, such as 'cordova/exec'
- * @return {Function}.
- */
-
-function ModuleMap(moduleId) {
- return function() {
- // lookup and execute the module's mock implementation, passing
- // in any parameters that were provided.
- return cordova.required[moduleId].apply(this, arguments);
- };
-}
diff --git a/plugins/phonegap-plugin-push/spec/index.spec.js b/plugins/phonegap-plugin-push/spec/index.spec.js
deleted file mode 100644
index f794fae5..00000000
--- a/plugins/phonegap-plugin-push/spec/index.spec.js
+++ /dev/null
@@ -1,160 +0,0 @@
-/*!
- * 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();
- });
- });
- });
- });
-});