diff --git a/README.md b/README.md index a712fb6a..52955873 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [ngCordova](http://ngcordova.com/) + ========== [![Travis](https://img.shields.io/travis/driftyco/ng-cordova.svg?style=flat)](https://travis-ci.org/driftyco/ng-cordova) [![Bower](https://img.shields.io/badge/bower-ngCordova-FFCC2F.svg?style=flat)](http://bower.io/search/?q=ngCordova) @@ -61,6 +62,7 @@ $ bower install ngCordova - [Facebook AudienceNetwork Ads](https://github.com/floatinghotpot/cordova-plugin-facebookads) (:warning: share % Ad revenue) - [File](https://github.com/apache/cordova-plugin-file) * - [File Transfer](https://github.com/apache/cordova-plugin-file-transfer) * +- [Fingerprint](https://github.com/NiklasMerz/cordova-plugin-fingerprint-aio) * - [Flashlight](https://github.com/EddyVerbruggen/Flashlight-PhoneGap-Plugin) - [Flurry Ads](https://github.com/floatinghotpot/cordova-plugin-flurry) (:warning: share % Ad revenue) - [Geolocation](https://github.com/apache/cordova-plugin-geolocation) * @@ -103,6 +105,7 @@ $ bower install ngCordova - [Touchid](https://github.com/leecrossley/cordova-plugin-touchid) - [Vibration](https://github.com/apache/cordova-plugin-vibration) * - [Video Capture Plus](https://github.com/EddyVerbruggen/VideoCapturePlus-PhoneGap-Plugin) * +- [Web Intent](https://github.com/Initsogar/cordova-webintent) - [Zip](https://github.com/MobileChromeApps/cordova-plugin-zip) `* official Apache Cordova Plugin` diff --git a/dist/ng-cordova.js b/dist/ng-cordova.js index b8c1c53d..4471b800 100644 --- a/dist/ng-cordova.js +++ b/dist/ng-cordova.js @@ -5732,6 +5732,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.progressIndicator', 'ngCordova.plugins.push', 'ngCordova.plugins.push_v5', + 'ngCordova.plugins.recentsControl', 'ngCordova.plugins.sms', 'ngCordova.plugins.socialSharing', 'ngCordova.plugins.spinnerDialog', @@ -7358,4 +7359,4 @@ angular.module('ngCordova.plugins.zip', []) }; }]); -})(); \ No newline at end of file +})(); diff --git a/package.json b/package.json index 96f86c31..4c690658 100644 --- a/package.json +++ b/package.json @@ -27,17 +27,24 @@ "minimist": "^0.1.0", "phantomjs-prebuilt": "^2.1.4" }, - "licenses": [ - { - "type": "MIT" - } + + "keywords": [ + "ngCordova", + "ng-cordova", + "ngcordova", + "ng cordova", + "cordova", + "phonegap", + "angular", + "angularjs", + "ionic", + "cordova plugin" ], "scripts": { "test": "gulp lint && gulp karma --browsers=PhantomJS --reporters=progress" }, "dependencies": { "conventional-changelog": "0.0.11", - "fs": "0.0.2", "gulp-git": "^1.2.4", "q": "^1.1.2" } diff --git a/src/mocks/googleAnalytics.js b/src/mocks/googleAnalytics.js index 4d15e8de..90d72bb5 100644 --- a/src/mocks/googleAnalytics.js +++ b/src/mocks/googleAnalytics.js @@ -13,7 +13,7 @@ ngCordovaMocks.factory('$cordovaGoogleAnalytics', ['$q', function ($q) { /** * @ngdoc property * @name throwsError - * @propertyOf ngCordovaMocks.cordovaGeolocation + * @propertyOf ngCordovaMocks.cordovaGoogleAnalytics * * @description * A flag that signals whether a promise should be rejected or not. @@ -24,14 +24,20 @@ ngCordovaMocks.factory('$cordovaGoogleAnalytics', ['$q', function ($q) { var methodsName = [ 'startTrackerWithId', 'setUserId', + 'setAppVersion', 'debugMode', + 'setAllowIDFACollection', 'trackView', 'addCustomDimension', 'trackEvent', + 'trackMetric', 'trackException', 'trackTiming', 'addTransaction', - 'addTransactionItem' + 'addTransactionItem', + 'setAnonymizeIp', + 'setAllowIDFACollection', + 'enableUncaughtExceptionReporting' ]; methodsName.forEach(function (funcName) { diff --git a/src/mocks/instagram.js b/src/mocks/instagram.js new file mode 100644 index 00000000..0bdca5ef --- /dev/null +++ b/src/mocks/instagram.js @@ -0,0 +1,53 @@ +/** + * @ngdoc service + * @name ngCordovaMocks.cordovaInstagram + * + * @description + * A service for testing instagram features + * in an app build with ngCordova. + **/ +ngCordovaMocks.factory('$cordovaInstagram', ['$q', function ($q) { + var throwsError = false; + var returnIsInstalled = true; + + return { + + /** + * @ngdoc property + * @name throwsError + * @propertyOf ngCordovaMocks.cordovaInstagram + * + * @description + * A flag that signals whether a promise should be rejected or not. + * This property should only be used in automated tests. + **/ + throwsError: throwsError, + + /** + * @ngdoc property + * @name returnIsInstalled + * @propertyOf ngCordovaMocks.cordovaInstagram + * + * @description + * A flag that signals whether the mock should simulate that the instagram app + * is installed or not. + * This property should only be used in automated tests. + **/ + returnIsInstalled: returnIsInstalled, + + share: function (options) { + if(this.throwsError) { + return $q.reject('an error occurred'); + } + return $q.when(true); + }, + + + isInstalled: function () { + if(this.throwsError) { + return $q.reject('an error occurred'); + } + return $q.when(this.returnIsInstalled); + } + } +}]); diff --git a/src/mocks/webIntent.js b/src/mocks/webIntent.js new file mode 100644 index 00000000..ccf126f2 --- /dev/null +++ b/src/mocks/webIntent.js @@ -0,0 +1,75 @@ +ngCordovaMocks.factory('$webIntent', ['$q', '$rootScope', function($q, $rootScope) { + var scope = $rootScope.$new(); + var has = true; + var url = "http://url.mock/ressource"; + var throwsError = false; + + return{ + has: has, + url: url, + throwsError: throwsError, + + startActivity: function (params) { + var q = $q.defer(); + if(this.throwsError) { + q.reject(new Error()); + } else { + q.resolve(); + } + return q.promise; + }, + hasExtra: function (params) { + var q = $q.defer(); + if(this.throwsError) { + q.reject(new Error()); + } else { + q.resolve(has); + } + return q.promise; + }, + getUri: function () { + var q = $q.defer(); + if(this.throwsError) { + q.reject(new Error()); + } else { + q.resolve(url); + } + return q.promise; + }, + getExtra: function (params) { + var q = $q.defer(); + if(this.throwsError) { + q.reject(new Error()); + } else { + q.resolve(url); + } + return q.promise; + }, + onNewIntent: function (callback) { + scope.$on('newIntent', function() { + callback(url); + }); + }, + newIntent: function() { + scope.$broadcast('newIntent') + }, + sendBroadcast: function (params) { + var q = $q.defer(); + if(this.throwsError) { + q.reject(new Error()); + } else { + q.resolve(); + } + return q.promise; + }, + actionSend: function() {return "actionSend"}, + actionView: function() {return "actionView"}, + actionCall: function() {return "actionCall"}, + actionSendTo: function() {return "actionSendTo"}, + extraText: function() {return "extraText"}, + extraSubject: function() {return "extraSubject"}, + extraStream: function() {return "extraStream"}, + extraEmail: function() {return "extraEmail"} + } + +}]); diff --git a/src/plugins/3dtouch.js b/src/plugins/3dtouch.js index 9313569f..9338a79b 100644 --- a/src/plugins/3dtouch.js +++ b/src/plugins/3dtouch.js @@ -3,11 +3,11 @@ angular.module('ngCordova.plugins.3dtouch', []) - .factory('$cordova3DTouch', ['$q', function($q) { + .factory('$cordova3DTouch', ['$q', function ($q) { var quickActions = []; var quickActionHandler = {}; - var createQuickActionHandler = function(quickActionHandler) { + var createQuickActionHandler = function (quickActionHandler) { return function (payload) { for (var key in quickActionHandler) { if (payload.type === key) { @@ -52,7 +52,7 @@ angular.module('ngCordova.plugins.3dtouch', []) * @param function callback (optional) * @return promise */ - addQuickAction: function(type, title, iconType, iconTemplate, subtitle, callback) { + addQuickAction: function (type, title, iconType, iconTemplate, subtitle, callback) { var deferred = $q.defer(); var quickAction = { @@ -69,14 +69,14 @@ angular.module('ngCordova.plugins.3dtouch', []) quickAction.iconTemplate = iconTemplate; } - this.isAvailable().then(function() { + this.isAvailable().then(function () { quickActions.push(quickAction); quickActionHandler[type] = callback; window.ThreeDeeTouch.configureQuickActions(quickActions); window.ThreeDeeTouch.onHomeIconPressed = createQuickActionHandler(quickActionHandler); deferred.resolve(quickActions); }, - function(err) { + function (err) { deferred.reject(err); }); @@ -90,15 +90,15 @@ angular.module('ngCordova.plugins.3dtouch', []) * @param function callback * @return promise */ - addQuickActionHandler: function(type, callback) { + addQuickActionHandler: function (type, callback) { var deferred = $q.defer(); - this.isAvailable().then(function() { + this.isAvailable().then(function () { quickActionHandler[type] = callback; window.ThreeDeeTouch.onHomeIconPressed = createQuickActionHandler(quickActionHandler); deferred.resolve(true); }, - function(err) { + function (err) { deferred.reject(err); }); @@ -110,14 +110,14 @@ angular.module('ngCordova.plugins.3dtouch', []) * * @return bool */ - enableLinkPreview: function() { + enableLinkPreview: function () { var deferred = $q.defer(); - this.isAvailable().then(function() { + this.isAvailable().then(function () { window.ThreeDeeTouch.enableLinkPreview(); deferred.resolve(true); }, - function(err) { + function (err) { deferred.reject(err); }); @@ -130,14 +130,14 @@ angular.module('ngCordova.plugins.3dtouch', []) * @param function callback * @return promise */ - addForceTouchHandler: function(callback) { + addForceTouchHandler: function (callback) { var deferred = $q.defer(); - this.isAvailable().then(function() { + this.isAvailable().then(function () { window.ThreeDeeTouch.watchForceTouches(callback); deferred.resolve(true); }, - function(err) { + function (err) { deferred.reject(err); }); diff --git a/src/plugins/appRate.js b/src/plugins/appRate.js index b649f445..b238c9b9 100644 --- a/src/plugins/appRate.js +++ b/src/plugins/appRate.js @@ -30,7 +30,7 @@ angular.module('ngCordova.plugins.appRate', []) AppRate.preferences.displayAppName = defaults.appName || ''; AppRate.preferences.promptAgainForEachNewVersion = defaults.promptForNewVersion || true; AppRate.preferences.openStoreInApp = defaults.openStoreInApp || false; - AppRate.preferences.usesUntilPrompt = defaults.usesUntilPrompt || 3; + AppRate.preferences.usesUntilPrompt = (typeof defaults.usesUntilPrompt === 'undefined'|| defaults.usesUntilPrompt===null)?3:defaults.usesUntilPrompt; AppRate.preferences.useCustomRateDialog = defaults.useCustomRateDialog || false; AppRate.preferences.storeAppURL.ios = defaults.iosURL || null; AppRate.preferences.storeAppURL.android = defaults.androidURL || null; diff --git a/src/plugins/fingerprint.js b/src/plugins/fingerprint.js new file mode 100644 index 00000000..5d72969c --- /dev/null +++ b/src/plugins/fingerprint.js @@ -0,0 +1,41 @@ +// install : cordova plugin add https://github.com/NiklasMerz/cordova-plugin-fingerprint-aio +// link : https://github.com/NiklasMerz/cordova-plugin-fingerprint-aio + +/* globals Fingerprint: true */ +angular.module('ngCordova.plugins.fingerprint', []) + + .factory('$cordovaFingerprint', ['$q', function ($q) { + + return { + isAvailable: function () { + var defer = $q.defer(); + if (!window.cordova) { + defer.reject('Not supported without cordova.js'); + } else { + Fingerprint.isAvailable(function (value) { + defer.resolve(value); + }, function (err) { + defer.reject(err); + }); + } + + return defer.promise; + }, + + show: function (options) { + var defer = $q.defer(); + if (!window.cordova) { + defer.reject('Not supported without cordova.js'); + } else { + Fingerprint.show(options, + function (value) { + defer.resolve(value); + }, function (err) { + defer.reject(err); + }); + } + + return defer.promise; + } + }; + }]); diff --git a/src/plugins/googleAnalytics.js b/src/plugins/googleAnalytics.js index 1bec1adf..58c5ae7b 100755 --- a/src/plugins/googleAnalytics.js +++ b/src/plugins/googleAnalytics.js @@ -9,7 +9,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) startTrackerWithId: function (id) { var d = $q.defer(); - $window.analytics.startTrackerWithId(id, function (response) { + $window.ga.startTrackerWithId(id, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -21,7 +21,19 @@ angular.module('ngCordova.plugins.googleAnalytics', []) setUserId: function (id) { var d = $q.defer(); - $window.analytics.setUserId(id, function (response) { + $window.ga.setUserId(id, function (response) { + d.resolve(response); + }, function (error) { + d.reject(error); + }); + + return d.promise; + }, + + setAppVersion: function (version) { + var d = $q.defer(); + + $window.ga.setAppVersion(version, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -33,7 +45,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) debugMode: function () { var d = $q.defer(); - $window.analytics.debugMode(function (response) { + $window.ga.debugMode(function (response) { d.resolve(response); }, function () { d.reject(); @@ -45,7 +57,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) trackView: function (screenName) { var d = $q.defer(); - $window.analytics.trackView(screenName, function (response) { + $window.ga.trackView(screenName, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -62,7 +74,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) d.reject('Parameter "key" must be an integer.'); } - $window.analytics.addCustomDimension(parsedKey, value, function () { + $window.ga.addCustomDimension(parsedKey, value, function () { d.resolve(); }, function (error) { d.reject(error); @@ -74,7 +86,19 @@ angular.module('ngCordova.plugins.googleAnalytics', []) trackEvent: function (category, action, label, value) { var d = $q.defer(); - $window.analytics.trackEvent(category, action, label, value, function (response) { + $window.ga.trackEvent(category, action, label, value, function (response) { + d.resolve(response); + }, function (error) { + d.reject(error); + }); + + return d.promise; + }, + + trackMetric: function (key, value) { + var d = $q.defer(); + + $window.ga.trackMetric(key, value, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -86,7 +110,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) trackException: function (description, fatal) { var d = $q.defer(); - $window.analytics.trackException(description, fatal, function (response) { + $window.ga.trackException(description, fatal, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -98,7 +122,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) trackTiming: function (category, milliseconds, variable, label) { var d = $q.defer(); - $window.analytics.trackTiming(category, milliseconds, variable, label, function (response) { + $window.ga.trackTiming(category, milliseconds, variable, label, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -110,7 +134,7 @@ angular.module('ngCordova.plugins.googleAnalytics', []) addTransaction: function (transactionId, affiliation, revenue, tax, shipping, currencyCode) { var d = $q.defer(); - $window.analytics.addTransaction(transactionId, affiliation, revenue, tax, shipping, currencyCode, function (response) { + $window.ga.addTransaction(transactionId, affiliation, revenue, tax, shipping, currencyCode, function (response) { d.resolve(response); }, function (error) { d.reject(error); @@ -122,7 +146,47 @@ angular.module('ngCordova.plugins.googleAnalytics', []) addTransactionItem: function (transactionId, name, sku, category, price, quantity, currencyCode) { var d = $q.defer(); - $window.analytics.addTransactionItem(transactionId, name, sku, category, price, quantity, currencyCode, function (response) { + $window.ga.addTransactionItem(transactionId, name, sku, category, price, quantity, currencyCode, function (response) { + d.resolve(response); + }, function (error) { + d.reject(error); + }); + + return d.promise; + }, + + setAnonymizeIp: function (anonymize) { + var d = $q.defer(); + + $window.ga.setAnonymizeIp(anonymize, function (response) { + d.resolve(response); + }, function (error) { + d.reject(error); + }); + + return d.promise; + }, + + setAllowIDFACollection: function (enable) { + var d = $q.defer(); + + $window.ga.setAllowIDFACollection(enable, function (response) { + d.resolve(response); + }, function (error) { + d.reject(error); + }); + + return d.promise; + }, + + enableUncaughtExceptionReporting: function (enable) { + var d = $q.defer(); + + if(typeof(enable) === 'undefined') { + enable = true; + } + + $window.ga.enableUncaughtExceptionReporting(enable, function (response) { d.resolve(response); }, function (error) { d.reject(error); diff --git a/src/plugins/keyboard.js b/src/plugins/keyboard.js index 0ac5e41a..d7adf572 100644 --- a/src/plugins/keyboard.js +++ b/src/plugins/keyboard.js @@ -5,15 +5,15 @@ angular.module('ngCordova.plugins.keyboard', []) .factory('$cordovaKeyboard', ['$rootScope', function ($rootScope) { - var keyboardShowEvent = function () { + var keyboardShowEvent = function (ev) { $rootScope.$evalAsync(function () { - $rootScope.$broadcast('$cordovaKeyboard:show'); + $rootScope.$broadcast('$cordovaKeyboard:show', { ev: ev }); }); }; - var keyboardHideEvent = function () { + var keyboardHideEvent = function (ev) { $rootScope.$evalAsync(function () { - $rootScope.$broadcast('$cordovaKeyboard:hide'); + $rootScope.$broadcast('$cordovaKeyboard:hide', { ev: ev }); }); }; diff --git a/src/plugins/media.js b/src/plugins/media.js index 93ec8ee8..a9b23d07 100644 --- a/src/plugins/media.js +++ b/src/plugins/media.js @@ -5,26 +5,27 @@ angular.module('ngCordova.plugins.media', []) .service('NewMedia', ['$q', '$interval', function ($q, $interval) { - var q, q2, q3, mediaStatus = null, mediaPosition = -1, mediaTimer, mediaDuration = -1; - function setTimer(media) { - if (angular.isDefined(mediaTimer)) { + // + // Privates functions + function setTimer(player) { + if (angular.isDefined(player.mediaTimer)) { return; } - mediaTimer = $interval(function () { - if (mediaDuration < 0) { - mediaDuration = media.getDuration(); - if (q && mediaDuration > 0) { - q.notify({duration: mediaDuration}); + player.mediaTimer = $interval(function () { + if (player.mediaDuration < 0) { + player.mediaDuration = player.media.getDuration(); + if (player.$defer && player.mediaDuration > 0) { + player.$defer.notify({duration: player.mediaDuration}); } } - media.getCurrentPosition( + player.media.getCurrentPosition( // success callback function (position) { if (position > -1) { - mediaPosition = position; + player.mediaPosition = position; } }, // error callback @@ -32,38 +33,36 @@ angular.module('ngCordova.plugins.media', []) console.log('Error getting pos=' + e); }); - if (q) { - q.notify({position: mediaPosition}); - } + player.$defer.notify({position: player.mediaPosition}); }, 1000); } - function clearTimer() { - if (angular.isDefined(mediaTimer)) { - $interval.cancel(mediaTimer); - mediaTimer = undefined; + function clearTimer(player) { + if (angular.isDefined(player.mediaTimer)) { + $interval.cancel(player.mediaTimer); + player.mediaTimer = undefined; } } - function resetValues() { - mediaPosition = -1; - mediaDuration = -1; - } + // + // Public API function NewMedia(src) { + var self=this; + this.$defer=$q.defer(); + this.mediaPosition = -1; + this.mediaDuration = -1; + this.mediaTimer = undefined; + this.media = new Media(src, function (success) { - clearTimer(); - resetValues(); - q.resolve(success); + self.$defer.resolve(success); }, function (error) { - clearTimer(); - resetValues(); - q.reject(error); + self.$defer.reject(error); }, function (status) { - mediaStatus = status; - q.notify({status: mediaStatus}); + self.media.mediaStatus = status; + self.$defer.notify({status: self.media.mediaStatus}); }); } @@ -71,7 +70,6 @@ angular.module('ngCordova.plugins.media', []) // - myMedia.play({ numberOfLoops: 2 }) -> looping // - myMedia.play({ playAudioWhenScreenIsLocked : false }) NewMedia.prototype.play = function (options) { - q = $q.defer(); if (typeof options !== 'object') { options = {}; @@ -79,23 +77,27 @@ angular.module('ngCordova.plugins.media', []) this.media.play(options); - setTimer(this.media); + setTimer(this); - return q.promise; + return this.$defer.promise; }; NewMedia.prototype.pause = function () { - clearTimer(); + clearTimer(this); this.media.pause(); }; NewMedia.prototype.stop = function () { + clearTimer(this); this.media.stop(); }; NewMedia.prototype.release = function () { + clearTimer(this); this.media.release(); this.media = undefined; + this.mediaPosition = -1; + this.mediaDuration = -1; }; NewMedia.prototype.seekTo = function (timing) { @@ -115,19 +117,19 @@ angular.module('ngCordova.plugins.media', []) }; NewMedia.prototype.currentTime = function () { - q2 = $q.defer(); + var q = $q.defer(); this.media.getCurrentPosition(function (position){ - q2.resolve(position); + q.resolve(position); }); - return q2.promise; + return q.promise; }; NewMedia.prototype.getDuration = function () { - q3 = $q.defer(); + var q = $q.defer(); this.media.getDuration(function (duration){ - q3.resolve(duration); + q.resolve(duration); }); - return q3.promise; + return q.promise; }; return NewMedia; diff --git a/src/plugins/module.js b/src/plugins/module.js index 829e90fe..328c71ae 100644 --- a/src/plugins/module.js +++ b/src/plugins/module.js @@ -29,6 +29,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.file', 'ngCordova.plugins.fileTransfer', 'ngCordova.plugins.fileOpener2', + 'ngCordova.plugins.fingerprint', 'ngCordova.plugins.flashlight', 'ngCordova.plugins.flurryAds', 'ngCordova.plugins.ga', @@ -61,6 +62,7 @@ angular.module('ngCordova.plugins', [ 'ngCordova.plugins.progressIndicator', 'ngCordova.plugins.push', 'ngCordova.plugins.push_v5', + 'ngCordova.plugins.screensize', 'ngCordova.plugins.sms', 'ngCordova.plugins.socialSharing', 'ngCordova.plugins.spinnerDialog', diff --git a/src/plugins/push_v5.js b/src/plugins/push_v5.js index 02706e9c..dcdb555f 100644 --- a/src/plugins/push_v5.js +++ b/src/plugins/push_v5.js @@ -14,6 +14,13 @@ angular.module('ngCordova.plugins.push_v5', []) q.resolve(push); return q.promise; }, + hasPermission : function () { + var q = $q.defer(); + PushNotification.hasPermission(function(response) { + q.resolve(response); + }); + return q.promise; + }, onNotification : function () { $timeout(function () { push.on('notification', function (notification) { diff --git a/src/plugins/screensize.js b/src/plugins/screensize.js new file mode 100644 index 00000000..3f487474 --- /dev/null +++ b/src/plugins/screensize.js @@ -0,0 +1,16 @@ +angular.module('ngCordova.plugins.screensize', []) + + .factory('$cordovaScreenSize', ['$q', '$window', function ($q, $window) { + return { + + get: function () { + var q = $q.defer(); + $window.plugins.screensize.get(function (result) { + q.resolve(result); + }, function (error) { + q.reject(error); + }); + return q.promise; + } + }; + }]); diff --git a/src/plugins/serial.js b/src/plugins/serial.js index 14bd286f..a732be4d 100644 --- a/src/plugins/serial.js +++ b/src/plugins/serial.js @@ -20,7 +20,7 @@ angular.module('ngCordova.plugins.serial', []) return q.promise; }; - serialService.open = function(options) { + serialService.open = function (options) { var q = $q.defer(); serial.open(options, function success() { @@ -32,7 +32,7 @@ angular.module('ngCordova.plugins.serial', []) return q.promise; }; - serialService.write = function(data) { + serialService.write = function (data) { var q = $q.defer(); serial.write(data, function success() { @@ -44,7 +44,7 @@ angular.module('ngCordova.plugins.serial', []) return q.promise; }; - serialService.writeHex = function(data) { + serialService.writeHex = function (data) { var q = $q.defer(); serial.writeHex(data, function success() { @@ -56,7 +56,7 @@ angular.module('ngCordova.plugins.serial', []) return q.promise; }; - serialService.read = function() { + serialService.read = function () { var q = $q.defer(); serial.read(function success(buffer) { @@ -69,14 +69,14 @@ angular.module('ngCordova.plugins.serial', []) return q.promise; }; - serialService.registerReadCallback = function(successCallback, errorCallback) { + serialService.registerReadCallback = function (successCallback, errorCallback) { serial.registerReadCallback(function success(buffer) { var view = new Uint8Array(buffer); successCallback(view); }, errorCallback); }; - serialService.close = function() { + serialService.close = function () { var q = $q.defer(); serial.close(function success() { diff --git a/src/plugins/sqlite.js b/src/plugins/sqlite.js index dba8e3b3..7e6a74a0 100644 --- a/src/plugins/sqlite.js +++ b/src/plugins/sqlite.js @@ -23,40 +23,70 @@ angular.module('ngCordova.plugins.sqlite', []) execute: function (db, query, binding) { var q = $q.defer(); - db.transaction(function (tx) { - tx.executeSql(query, binding, function (tx, result) { - q.resolve(result); - }, - function (transaction, error) { - q.reject(error); - }); + db.executeSql(query, binding, function (result) { + q.resolve(result); + }, + function (error) { + q.reject(error); + }); + return q.promise; + }, + + batch: function (db, queries) { + var q = $q.defer(); + db.sqlBatch(queries, function () { + q.resolve(); + }, + function (error) { + q.reject(error); }); return q.promise; }, insertCollection: function (db, query, bindings) { + if (!bindings || bindings.constructor !== Array) { + throw new Error('insertCollection expects an array'); + } + var q = $q.defer(); - var coll = bindings.slice(0); // clone collection - db.transaction(function (tx) { - (function insertOne() { - var record = coll.splice(0, 1)[0]; // get the first record of coll and reduce coll by one - try { - tx.executeSql(query, record, function (tx, result) { - if (coll.length === 0) { - q.resolve(result); - } else { - insertOne(); - } - }, function (transaction, error) { - q.reject(error); - return; - }); - } catch (exception) { - q.reject(exception); - } - })(); - }); + if (db.sqlBatch) { + var queryBatch = [], i = 0, len = bindings.length; + + for (i; i < len; i++) { + queryBatch.push([query, bindings[i]]); + } + + db.sqlBatch(queryBatch, + function() { + q.resolve(); + }, function(error) { + q.reject(error); + }); + } else { + var coll = bindings.slice(0); // clone collection + + db.transaction(function (tx) { + (function insertOne() { + var record = coll.splice(0, 1)[0]; // get the first record of coll and reduce coll by one + try { + tx.executeSql(query, record, function (tx, result) { + if (coll.length === 0) { + q.resolve(result); + } else { + insertOne(); + } + }, function (transaction, error) { + q.reject(error); + return; + }); + } catch (exception) { + q.reject(exception); + } + })(); + }); + } + return q.promise; }, @@ -78,6 +108,18 @@ angular.module('ngCordova.plugins.sqlite', []) return q.promise; }, + closeDB: function (db) { + var q = $q.defer(); + + db.close(function (success) { + q.resolve(success); + }, function (error) { + q.reject(error); + }); + + return q.promise; + }, + deleteDB: function (dbName) { var q = $q.defer(); diff --git a/src/plugins/webIntent.js b/src/plugins/webIntent.js new file mode 100644 index 00000000..ae7b1442 --- /dev/null +++ b/src/plugins/webIntent.js @@ -0,0 +1,133 @@ +// install : cordova plugin add https://github.com/Initsogar/cordova-webintent.git +// link : https://github.com/Initsogar/cordova-webintent + +angular.module('ngCordova.plugins.webIntent', []) + + .factory('$webIntent', ['$q', '$window', function ($q, $window) { + + return { + startActivity: function (params) { + var q = $q.defer(); + + if (!$window.cordova) { + q.reject('Not supported without cordova.js'); + } else { + $window.plugins.webintent.startActivity(params, function (result) { + q.resolve(result); + }, function (err) { + q.reject(err); + }); + } + + return q.promise; + }, + hasExtra: function(params) { + var q = $q.defer(); + + if (!$window.cordova) { + q.reject('Not supported without cordova.js'); + } else { + $window.plugins.webintent.hasExtra(params, function (result) { + q.resolve(result); + }, function (err) { + q.reject(err); + }); + } + + return q.promise; + }, + getUri: function() { + var q = $q.defer(); + + if (!$window.cordova) { + q.reject('Not supported without cordova.js'); + } else { + $window.plugins.webintent.getUri(function (result) { + q.resolve(result); + }, function (err) { + q.reject(err); + }); + } + + return q.promise; + }, + getExtra: function(params) { + var q = $q.defer(); + + if (!$window.cordova) { + q.reject('Not supported without cordova.js'); + } else { + $window.plugins.webintent.getExtra(params, function (result) { + q.resolve(result); + }, function (err) { + q.reject(err); + }); + } + + return q.promise; + }, + onNewIntent: function(callback) { + if ($window.plugins) { + $window.plugins.webintent.onNewIntent(callback); + } + }, + sendBroadcast: function(params) { + var q = $q.defer(); + + if (!$window.cordova) { + q.reject('Not supported without cordova.js'); + } else { + $window.plugins.webintent.sendBroadcast(params, function (result) { + q.resolve(result); + }, function (err) { + q.reject(err); + }); + } + + return q.promise; + }, + + actionSend: function() { + if ($window.plugins) { + return $window.plugins.webintent.ACTION_SEND; + } + }, + actionView: function() { + if ($window.plugins) { + return $window.plugins.webintent.ACTION_VIEW; + } + }, + actionCall: function() { + if ($window.plugins) { + return $window.plugins.webintent.ACTION_CALL; + } + }, + actionSendTo: function() { + if ($window.plugins) { + return $window.plugins.webintent.ACTION_SENDTO; + } + }, + extraText: function() { + if ($window.plugins) { + return $window.plugins.webintent.EXTRA_TEXT; + } + }, + extraSubject: function() { + if ($window.plugins) { + return $window.plugins.webintent.EXTRA_SUBJECT; + } + }, + extraStream: function() { + if ($window.plugins) { + return $window.plugins.webintent.EXTRA_STREAM; + } + }, + extraEmail: function() { + if ($window.plugins) { + return $window.plugins.webintent.EXTRA_EMAIL; + } + } + + + }; + }] ); diff --git a/test/mocks/googleAnalytics.spec.js b/test/mocks/googleAnalytics.spec.js index 23a4442d..fa027f70 100644 --- a/test/mocks/googleAnalytics.spec.js +++ b/test/mocks/googleAnalytics.spec.js @@ -31,7 +31,7 @@ describe('ngCordovaMocks', function() { $timeout.flush(); }; - it('should start tracker', function () { + it('should start tracker', function() { testPromises('startTrackerWithId'); }); @@ -39,6 +39,10 @@ describe('ngCordovaMocks', function() { testPromises('setUserId'); }); + it('should set App version', function() { + testPromises('setAppVersion'); + }); + it('should set debug mode.', function() { testPromises('debugMode'); }); @@ -55,6 +59,10 @@ describe('ngCordovaMocks', function() { testPromises('trackEvent'); }); + it('should track metric', function() { + testPromises('trackMetric'); + }); + it('should track exception.', function() { testPromises('trackException'); }); @@ -70,5 +78,17 @@ describe('ngCordovaMocks', function() { it('should add add a transaction item.', function() { testPromises('addTransactionItem'); }); + + it('should set Anonymize Ip', function() { + testPromises('setAnonymizeIp'); + }); + + it('should set Allow IDFA Collection', function() { + testPromises('setAllowIDFACollection'); + }); + + it('should enable Uncaught Exception Reporting', function() { + testPromises('enableUncaughtExceptionReporting'); + }); }); }) \ No newline at end of file diff --git a/test/mocks/instagram.spec.js b/test/mocks/instagram.spec.js new file mode 100644 index 00000000..60cd0eed --- /dev/null +++ b/test/mocks/instagram.spec.js @@ -0,0 +1,79 @@ +describe('ngCordovaMocks', function() { + beforeEach(function() { + module('ngCordovaMocks'); + }); + + describe('cordovaInstagram', function () { + var $rootScope = null; + var $cordovaInstagram = null; + var shareOptions = {}; + + beforeEach(inject(function (_$cordovaInstagram_, _$rootScope_) { + $cordovaInstagram = _$cordovaInstagram_; + $rootScope = _$rootScope_; + })); + + it('should share', function (done) { + $cordovaInstagram.share(shareOptions) + .then( + function() { expect(true).toBe(true); }, + function() { expect(false).toBe(true); } + ) + .finally(done) + ; + + $rootScope.$digest(); + }); + + it('should throw an error while sharing.', function(done) { + $cordovaInstagram.throwsError = true; + $cordovaInstagram.share(shareOptions) + .then( + function() { expect(true).toBe(false); }, + function() { expect(true).toBe(true); } + ) + .finally(done) + ; + + $rootScope.$digest(); + }); + + it('should return is installed', function (done) { + $cordovaInstagram.isInstalled() + .then( + function(isInstalled) { expect(isInstalled).toBe(true); }, + function() { expect(false).toBe(true); } + ) + .finally(done) + ; + + $rootScope.$digest(); + }); + + it('should throw an error while checking isInstalled.', function(done) { + $cordovaInstagram.throwsError = true; + $cordovaInstagram.isInstalled() + .then( + function() { expect(true).toBe(false); }, + function() { expect(true).toBe(true); } + ) + .finally(done) + ; + + $rootScope.$digest(); + }); + + it('should return isInstalled as false', function(done) { + $cordovaInstagram.returnIsInstalled = false; + $cordovaInstagram.isInstalled() + .then( + function(isInstalled) { expect(isInstalled).toBe(false); }, + function() { expect(true).toBe(true); } + ) + .finally(done) + ; + + $rootScope.$digest(); + }); + }); +}); diff --git a/test/mocks/webIntent.spec.js b/test/mocks/webIntent.spec.js new file mode 100644 index 00000000..74ed3bf6 --- /dev/null +++ b/test/mocks/webIntent.spec.js @@ -0,0 +1,178 @@ +describe('ngCordovaMocks', function() { + + beforeEach(function() { + module('ngCordovaMocks'); + }); + + describe('webIntent', function () { + var $webIntent = null; + var $rootScope = null; + var spy = {}; + + //beforeEach(module('ngCordova.plugins.webIntent')); + + beforeEach(inject(function (_$webIntent_, _$rootScope_) { + $webIntent = _$webIntent_; + $rootScope = _$rootScope_; + + spy.success = jasmine.createSpy('success'); + spy.fail = function() {};//jasmine.createSpy('fail'); + + spyOn(spy, 'fail').and.callThrough(); + })); + + it('should return actionSend on actionSend', function() { + expect($webIntent.actionSend()).toBe("actionSend"); + }); + + it('should return actionView on actionView', function() { + expect($webIntent.actionView()).toBe("actionView"); + }); + + it('should return extraText on extraText', function() { + expect($webIntent.extraText()).toBe("extraText"); + }); + + it('should return extraSubject on extraSubject', function() { + expect($webIntent.extraSubject()).toBe("extraSubject"); + }); + + it('should return extraStream on extraStream', function() { + expect($webIntent.extraStream()).toBe("extraStream"); + }); + + it('should return extraEmail on extraEmail', function() { + expect($webIntent.extraEmail()).toBe("extraEmail"); + }); + + it('should return actionCall on actionCall', function() { + expect($webIntent.actionCall()).toBe("actionCall"); + }); + + it('should return actionSendTo on actionSendTo', function() { + expect($webIntent.actionSendTo()).toBe("actionSendTo"); + }); + + describe('startActivity', function() { + it('should call the success callback', function(done) { + $webIntent.startActivity("myFile") + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.success).toHaveBeenCalled(); + expect(spy.fail).not.toHaveBeenCalled(); + }).finally(done); + + $rootScope.$apply(); + }); + + it('should call the fail callback', function(done) { + $webIntent.throwsError = true; + $webIntent.startActivity("myFile") + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.fail).toHaveBeenCalled(); + expect(spy.success).not.toHaveBeenCalled(); + }).finally(done); + $rootScope.$apply(); + }); + }); + + describe('hasExtra', function() { + it('should call the success callback', function(done) { + $webIntent.hasExtra("extraText") + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.success).toHaveBeenCalledWith($webIntent.has); + expect(spy.fail).not.toHaveBeenCalled(); + }).finally(done); + + $rootScope.$apply(); + }); + + it('should call the fail callback', function(done) { + $webIntent.throwsError = true; + $webIntent.hasExtra("extraText") + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.fail).toHaveBeenCalled(); + expect(spy.success).not.toHaveBeenCalled(); + }).finally(done); + $rootScope.$apply(); + }); + }); + + describe('getExtra', function() { + it('should call the success callback', function(done) { + $webIntent.getExtra("extraText") + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.success).toHaveBeenCalledWith($webIntent.url); + expect(spy.fail).not.toHaveBeenCalled(); + }).finally(done); + + $rootScope.$apply(); + }); + + it('should call the fail callback', function(done) { + $webIntent.throwsError = true; + $webIntent.getExtra("extraText") + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.fail).toHaveBeenCalled(); + expect(spy.success).not.toHaveBeenCalled(); + }).finally(done); + $rootScope.$apply(); + }); + }); + + describe('getUri', function() { + it('should call the success callback', function(done) { + $webIntent.getUri() + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.success).toHaveBeenCalledWith($webIntent.url); + expect(spy.fail).not.toHaveBeenCalled(); + }).finally(done); + + $rootScope.$apply(); + }); + + it('should call the fail callback', function(done) { + $webIntent.throwsError = true; + $webIntent.getUri() + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.fail).toHaveBeenCalled(); + expect(spy.success).not.toHaveBeenCalled(); + }).finally(done); + $rootScope.$apply(); + }); + }); + + describe('onNewIntent', function() { + it('should call the success callback', function() { + $webIntent.onNewIntent(spy.success); + $webIntent.newIntent(); + + expect(spy.success).toHaveBeenCalled(); + }); + }); + + describe('sendBroadcast', function() { + it('should call the success callback', function(done) { + $webIntent.sendBroadcast() + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.success).toHaveBeenCalled(); + expect(spy.fail).not.toHaveBeenCalled(); + }).finally(done); + + $rootScope.$apply(); + }); + + it('should call the fail callback', function(done) { + $webIntent.throwsError = true; + $webIntent.sendBroadcast() + .then(spy.success).catch(spy.fail).then(function() { + expect(spy.fail).toHaveBeenCalled(); + expect(spy.success).not.toHaveBeenCalled(); + }).finally(done); + $rootScope.$apply(); + }); + }); + + + + }); +}); diff --git a/test/plugins/fingerprint.spec.js b/test/plugins/fingerprint.spec.js new file mode 100644 index 00000000..60d8241b --- /dev/null +++ b/test/plugins/fingerprint.spec.js @@ -0,0 +1,112 @@ +describe('Service: $cordovaFingerprint', function() { + + var $cordovaTouchID, $rootScope; + + beforeEach(module('ngCordova.plugins.fingerprint')); + + beforeEach(inject(function (_$cordovaFingerprint_, _$q_, _$rootScope_) { + $cordovaFingerprint = _$cordovaFingerprint_; + $rootScope = _$rootScope_; + + window.Fingerprint = { + isAvailable: angular.noop, + show: angular.noop + }; + })); + + it("calls isAvailable", function() { + var result; + + spyOn(window.Fingerprint, 'isAvailable') + .and.callFake(function(successCb, errCb) { + successCb(); + }); + + $cordovaFingerprint.isAvailable() + .then(function() { + result = true; + }); + $rootScope.$digest(); + expect(result).toBe(true); + expect(window.Fingerprint.isAvailable).toHaveBeenCalledWith( + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it("rejects isAvailable on err callback", function() { + var errorResult; + + spyOn(window.Fingerprint, 'isAvailable') + .and.callFake(function(successCb, errCb) { + errCb("Not available in test"); + }); + + $cordovaFingerprint.isAvailable() + .then(angular.noop, + function(err) { + errorResult = false; + } + ); + $rootScope.$digest(); + expect(errorResult).toBe(false); + }); + + it("rejects checkSupport when window.cordova is not present", function() { + var errorResult; + _cordova = window.cordova; + window.cordova = null; + + $cordovaFingerprint.isAvailable() + .then(angular.noop, + function(err) { + errorResult = false; + } + ); + $rootScope.$digest(); + expect(errorResult).toBe(false); + + window.cordova = _cordova + }); + + it("calls show with options", function() { + var result; + var options = { + clientId: "ngCordova", + clientSecret: "test" + }; + + spyOn(window.Fingerprint, 'show') + .and.callFake(function(options, successCb, errCb) { + successCb(); + }); + + $cordovaFingerprint.show(options) + .then(function() { + result = true; + }); + $rootScope.$digest(); + expect(result).toBe(true); + expect(window.Fingerprint.show).toHaveBeenCalledWith( + options, + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it("rejects show when window.cordova is not present", function() { + var errorResult; + _cordova = window.cordova; + window.cordova = null; + + $cordovaFingerprint.show() + .then(angular.noop, + function(err) { + errorResult = false; + } + ); + $rootScope.$digest(); + expect(errorResult).toBe(false); + window.cordova = _cordova + }); +}); diff --git a/test/plugins/googleAnalytics.spec.js b/test/plugins/googleAnalytics.spec.js index c8430f0e..c8b9342d 100644 --- a/test/plugins/googleAnalytics.spec.js +++ b/test/plugins/googleAnalytics.spec.js @@ -9,25 +9,30 @@ describe('Service: $cordovaGoogleAnalytics', function() { $window = _$window_; $rootScope = _$rootScope_; - $window.analytics = { + $window.ga = { startTrackerWithId: angular.noop, setUserId: angular.noop, + setAppVersion: angular.noop, debugMode: angular.noop, trackView: angular.noop, addCustomDimension: angular.noop, trackEvent: angular.noop, + trackMetric: angular.noop, trackException: angular.noop, trackTiming: angular.noop, addTransaction: angular.noop, addTransactionItem: angular.noop, + setAnonymizeIp: angular.noop, + setAllowIDFACollection: angular.noop, + enableUncaughtExceptionReporting: angular.noop }; })); - it('should call $window\'s analytics.startTrackerWithId method', function() { + it('should call $window\'s ga.startTrackerWithId method', function() { var result; - spyOn($window.analytics, 'startTrackerWithId') + spyOn($window.ga, 'startTrackerWithId') .and.callFake(function (id, successCb, errorCb) { successCb('tracker started'); }); @@ -41,14 +46,14 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('tracker started'); - expect($window.analytics.startTrackerWithId.calls.argsFor(0)[0]).toBe('UA-000000-01'); + expect($window.ga.startTrackerWithId.calls.argsFor(0)[0]).toBe('UA-000000-01'); }); - it('should call errorCb when in $window\'s analytics.startTrackerWithId a error orccurs', function() { + it('should call errorCb when in $window\'s ga.startTrackerWithId a error orccurs', function() { var result; - spyOn($window.analytics, 'startTrackerWithId') + spyOn($window.ga, 'startTrackerWithId') .and.callFake(function (id, successCb, errorCb) { errorCb('tracker id is not valid'); }); @@ -63,11 +68,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('tracker id is not valid'); }); - it('should call $window\'s analytics.setUserId method', function() { + it('should call $window\'s ga.setUserId method', function() { var result; - spyOn($window.analytics, 'setUserId') + spyOn($window.ga, 'setUserId') .and.callFake(function (id, successCb, errorCb) { successCb('Set user id: ' + id); }); @@ -81,14 +86,14 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Set user id: USER_ID'); - expect($window.analytics.setUserId.calls.argsFor(0)[0]).toBe('USER_ID'); + expect($window.ga.setUserId.calls.argsFor(0)[0]).toBe('USER_ID'); }); - it('should call errorCb when in $window\'s analytics.setUserId a error orccurs', function() { + it('should call errorCb when in $window\'s ga.setUserId a error orccurs', function() { var result; - spyOn($window.analytics, 'setUserId') + spyOn($window.ga, 'setUserId') .and.callFake(function (id, successCb, errorCb) { errorCb('Tracker not started'); }); @@ -103,11 +108,55 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Tracker not started'); }); - it('should call $window\'s analytics.debugMode method', function() { + it('should call $window\'s ga.setAppVersion method', function () { var result; - spyOn($window.analytics, 'debugMode') + spyOn($window.ga, 'setAppVersion') + .and.callFake(function (version, successCb, errorCb) { + successCb('Set app version: ' + version); + }); + + $cordovaGoogleAnalytics + .setAppVersion('VERSION') + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('Set app version: VERSION'); + expect($window.ga.setAppVersion).toHaveBeenCalledWith( + 'VERSION', + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it('should call errorCb when in $window\'s ga.setAppVersion a error orccurs', function() { + + var result; + + spyOn($window.ga, 'setAppVersion') + .and.callFake(function (version, successCb, errorCb) { + errorCb('error orccurs'); + }); + + $cordovaGoogleAnalytics.setAppVersion() + .then(angular.noop, function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('error orccurs'); + }); + + it('should call $window\'s ga.debugMode method', function() { + + var result; + + spyOn($window.ga, 'debugMode') .and.callFake(function (successCb, errorCb) { successCb('debugMode enabled'); }); @@ -123,11 +172,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('debugMode enabled'); }); - it('should call errorCb when in $window\'s analytics.debugMode a error orccurs', function() { + it('should call errorCb when in $window\'s ga.debugMode a error orccurs', function() { var result; - spyOn($window.analytics, 'debugMode') + spyOn($window.ga, 'debugMode') .and.callFake(function (successCb, errorCb) { errorCb(); }); @@ -142,11 +191,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('error orccurs'); }); - it('should call $window\'s analytics.trackView method', function() { + it('should call $window\'s ga.trackView method', function() { var result; - spyOn($window.analytics, 'trackView') + spyOn($window.ga, 'trackView') .and.callFake(function (screenName, successCb, errorCb) { successCb('Track Screen: ' + screenName); }); @@ -160,14 +209,14 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Track Screen: Home Screen'); - expect($window.analytics.trackView.calls.argsFor(0)[0]).toBe('Home Screen'); + expect($window.ga.trackView.calls.argsFor(0)[0]).toBe('Home Screen'); }); - it('should call errorCb when in $window\'s analytics.trackView a error orccurs', function() { + it('should call errorCb when in $window\'s ga.trackView a error orccurs', function() { var result; - spyOn($window.analytics, 'trackView') + spyOn($window.ga, 'trackView') .and.callFake(function (screenName, successCb, errorCb) { errorCb('Expected one non-empty string argument'); }); @@ -182,11 +231,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Expected one non-empty string argument'); }); - it('should call $window\'s analytics.addCustomDimension method', function() { + it('should call $window\'s ga.addCustomDimension method', function() { var result; - spyOn($window.analytics, 'addCustomDimension') + spyOn($window.ga, 'addCustomDimension') .and.callFake(function (key, value, successCb, errorCb) { successCb(); }); @@ -200,15 +249,15 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('success'); - expect($window.analytics.addCustomDimension.calls.argsFor(0)[0]).toBe(1); - expect($window.analytics.addCustomDimension.calls.argsFor(0)[1]).toBe('Level 1'); + expect($window.ga.addCustomDimension.calls.argsFor(0)[0]).toBe(1); + expect($window.ga.addCustomDimension.calls.argsFor(0)[1]).toBe('Level 1'); }); - it('should call errorCb when in $window\'s analytics.addCustomDimension a error orccurs', function() { + it('should call errorCb when in $window\'s ga.addCustomDimension a error orccurs', function() { var result; - spyOn($window.analytics, 'addCustomDimension') + spyOn($window.ga, 'addCustomDimension') .and.callFake(function (key, value, successCb, errorCb) { errorCb('Parameter "key" must be an integer.'); }); @@ -223,11 +272,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Parameter "key" must be an integer.'); }); - it('should call $window\'s analytics.trackEvent method', function() { + it('should call $window\'s ga.trackEvent method', function() { var result; - spyOn($window.analytics, 'trackEvent') + spyOn($window.ga, 'trackEvent') .and.callFake(function (category, action, label, value, successCb, errorCb) { successCb('Track Event: ' + category); }); @@ -241,18 +290,18 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Track Event: Videos'); - expect($window.analytics.trackEvent).toHaveBeenCalledWith( + expect($window.ga.trackEvent).toHaveBeenCalledWith( 'Videos', 'Video Load Time', 'Gone With the Wind', 100, jasmine.any(Function), jasmine.any(Function) ); }); - it('should call errorCb when in $window\'s analytics.trackEvent a error orccurs', function() { + it('should call errorCb when in $window\'s ga.trackEvent a error orccurs', function() { var result; - spyOn($window.analytics, 'trackEvent') + spyOn($window.ga, 'trackEvent') .and.callFake(function (category, action, label, value, successCb, errorCb) { errorCb('Tracker not started'); }); @@ -268,11 +317,56 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Tracker not started'); }); - it('should call $window\'s analytics.trackException method', function() { + it('should call $window\'s ga.trackMetric method', function() { + + var result; + + spyOn($window.ga, 'trackMetric') + .and.callFake(function (key, value, successCb, errorCb) { + successCb('Track Metric: ' + key); + }); + + $cordovaGoogleAnalytics + .trackMetric('Custom', 1) + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('Track Metric: Custom'); + expect($window.ga.trackMetric).toHaveBeenCalledWith( + 'Custom', 1, + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it('should call errorCb when in $window\'s ga.trackMetric a error orccurs', function() { var result; - spyOn($window.analytics, 'trackException') + spyOn($window.ga, 'trackMetric') + .and.callFake(function (key, value, successCb, errorCb) { + errorCb('Tracker not started'); + }); + + $cordovaGoogleAnalytics + .trackMetric() + .then(angular.noop, function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('Tracker not started'); + }); + + it('should call $window\'s ga.trackException method', function() { + + var result; + + spyOn($window.ga, 'trackException') .and.callFake(function (description, fatal, successCb, errorCb) { successCb('Track Exception: ' + description); }); @@ -286,18 +380,18 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Track Exception: Video player exception'); - expect($window.analytics.trackException).toHaveBeenCalledWith( + expect($window.ga.trackException).toHaveBeenCalledWith( 'Video player exception', false, jasmine.any(Function), jasmine.any(Function) ); }); - it('should call errorCb when in $window\'s analytics.trackException a error orccurs', function() { + it('should call errorCb when in $window\'s ga.trackException a error orccurs', function() { var result; - spyOn($window.analytics, 'trackException') + spyOn($window.ga, 'trackException') .and.callFake(function (description, fatal, successCb, errorCb) { errorCb('Tracker not started'); }); @@ -313,11 +407,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Tracker not started'); }); - it('should call $window\'s analytics.trackTiming method', function() { + it('should call $window\'s ga.trackTiming method', function() { var result; - spyOn($window.analytics, 'trackTiming') + spyOn($window.ga, 'trackTiming') .and.callFake(function (category, milliseconds, variable, label, successCb, errorCb) { successCb('Track Timing: ' + category); }); @@ -331,18 +425,18 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Track Timing: Videos'); - expect($window.analytics.trackTiming).toHaveBeenCalledWith( + expect($window.ga.trackTiming).toHaveBeenCalledWith( 'Videos', 100, 'Video Load Time', 'Gone With the Wind', jasmine.any(Function), jasmine.any(Function) ); }); - it('should call errorCb when in $window\'s analytics.trackTiming a error orccurs', function() { + it('should call errorCb when in $window\'s ga.trackTiming a error orccurs', function() { var result; - spyOn($window.analytics, 'trackTiming') + spyOn($window.ga, 'trackTiming') .and.callFake(function (category, milliseconds, variable, label, successCb, errorCb) { errorCb('Tracker not started'); }); @@ -358,11 +452,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Tracker not started'); }); - it('should call $window\'s analytics.addTransaction method', function() { + it('should call $window\'s ga.addTransaction method', function() { var result; - spyOn($window.analytics, 'addTransaction') + spyOn($window.ga, 'addTransaction') .and.callFake(function (transactionId, affiliation, revenue, tax, shipping, currencyCode, successCb, errorCb) { successCb('Add Transaction: ' + transactionId); }); @@ -376,18 +470,18 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Add Transaction: 1234'); - expect($window.analytics.addTransaction).toHaveBeenCalledWith( + expect($window.ga.addTransaction).toHaveBeenCalledWith( '1234', 'Acme Clothing', '11.99', '5', '1.29', 'EUR', jasmine.any(Function), jasmine.any(Function) ); }); - it('should call errorCb when in $window\'s analytics.addTransaction a error orccurs', function() { + it('should call errorCb when in $window\'s ga.addTransaction a error orccurs', function() { var result; - spyOn($window.analytics, 'addTransaction') + spyOn($window.ga, 'addTransaction') .and.callFake(function (transactionId, affiliation, revenue, tax, shipping, currencyCode, successCb, errorCb) { errorCb('Tracker not started'); }); @@ -402,11 +496,11 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Tracker not started'); }); - it('should call $window\'s analytics.addTransactionItem method', function() { + it('should call $window\'s ga.addTransactionItem method', function() { var result; - spyOn($window.analytics, 'addTransactionItem') + spyOn($window.ga, 'addTransactionItem') .and.callFake(function (transactionId, name ,sku, category, price, quantity, currencyCode, successCb, errorCb) { successCb('Add Transaction Item: ' + transactionId); }); @@ -420,18 +514,18 @@ describe('Service: $cordovaGoogleAnalytics', function() { $rootScope.$digest(); expect(result).toBe('Add Transaction Item: 1234'); - expect($window.analytics.addTransactionItem).toHaveBeenCalledWith( + expect($window.ga.addTransactionItem).toHaveBeenCalledWith( '1234', 'Fluffy Pink Bunnies', 'DD23444', 'Party Toys', '11.99', '1', 'GBP', jasmine.any(Function), jasmine.any(Function) ); }); - it('should call errorCb when in $window\'s analytics.addTransactionItem a error orccurs', function() { + it('should call errorCb when in $window\'s ga.addTransactionItem a error orccurs', function() { var result; - spyOn($window.analytics, 'addTransactionItem') + spyOn($window.ga, 'addTransactionItem') .and.callFake(function (transactionId, name ,sku, category, price, quantity, currencyCode, successCb, errorCb) { errorCb('Tracker not started'); }); @@ -446,4 +540,135 @@ describe('Service: $cordovaGoogleAnalytics', function() { expect(result).toBe('Tracker not started'); }); + it('should call $window\'s ga.setAnonymizeIp method', function() { + + var result; + + spyOn($window.ga, 'setAnonymizeIp') + .and.callFake(function (anonymize, successCb, errorCb) { + successCb('Set anonymize: ' + anonymize); + }); + + $cordovaGoogleAnalytics + .setAnonymizeIp(true) + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('Set anonymize: true'); + expect($window.ga.setAnonymizeIp).toHaveBeenCalledWith( + true, + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it('should call errorCb when in $window\'s ga.setAnonymizeIp a error orccurs', function() { + + var result; + + spyOn($window.ga, 'setAnonymizeIp') + .and.callFake(function (anonymize, successCb, errorCb) { + errorCb('error orccurs'); + }); + + $cordovaGoogleAnalytics.setAnonymizeIp() + .then(angular.noop, function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('error orccurs'); + }); + + it('should call $window\'s ga.setAllowIDFACollection method', function() { + + var result; + + spyOn($window.ga, 'setAllowIDFACollection') + .and.callFake(function (enable, successCb, errorCb) { + successCb('Set allow IDFA collection: ' + enable); + }); + + $cordovaGoogleAnalytics + .setAllowIDFACollection(true) + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('Set allow IDFA collection: true'); + expect($window.ga.setAllowIDFACollection).toHaveBeenCalledWith( + true, + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it('should call errorCb when in $window\'s ga.setAllowIDFACollection a error orccurs', function() { + + var result; + + spyOn($window.ga, 'setAllowIDFACollection') + .and.callFake(function (enable, successCb, errorCb) { + errorCb('error orccurs'); + }); + + $cordovaGoogleAnalytics.setAllowIDFACollection() + .then(angular.noop, function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('error orccurs'); + }); + + it('should call $window\'s ga.enableUncaughtExceptionReporting method', function() { + + var result; + + spyOn($window.ga, 'enableUncaughtExceptionReporting') + .and.callFake(function (enable, successCb, errorCb) { + successCb('Enable uncaught exception reporting: ' + enable); + }); + + $cordovaGoogleAnalytics + .enableUncaughtExceptionReporting(true) + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('Enable uncaught exception reporting: true'); + expect($window.ga.enableUncaughtExceptionReporting).toHaveBeenCalledWith( + true, + jasmine.any(Function), + jasmine.any(Function) + ); + }); + + it('should call errorCb when in $window\'s ga.enableUncaughtExceptionReporting a error orccurs', function() { + + var result; + + spyOn($window.ga, 'enableUncaughtExceptionReporting') + .and.callFake(function (enable, successCb, errorCb) { + errorCb('error orccurs'); + }); + + $cordovaGoogleAnalytics.enableUncaughtExceptionReporting() + .then(angular.noop, function (response) { + result = response; + }); + + $rootScope.$digest(); + + expect(result).toBe('error orccurs'); + }); }); diff --git a/test/plugins/push_V5.spec.js b/test/plugins/push_V5.spec.js new file mode 100644 index 00000000..6896e5bb --- /dev/null +++ b/test/plugins/push_V5.spec.js @@ -0,0 +1,53 @@ +describe('Service: $cordovaPushV5', function() { + + var $cordovaPushV5, $rootScope; + + beforeEach(module('ngCordova.plugins.push_v5')); + + beforeEach(inject(function (_$cordovaPushV5_, _$rootScope_) { + $cordovaPushV5 = _$cordovaPushV5_; + $rootScope = _$rootScope_; + + + window.PushNotification = { + init: angular.noop, + hasPermission: angular.noop, + }; + })); + + it('should call the PushNotification.init method', function() { + + var result; + var config = { someConfig: 1 }; + + spyOn(window.PushNotification, 'init').and.returnValue(true); + + $cordovaPushV5.initialize(config) + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + expect(window.PushNotification.init.calls.argsFor(0)[0]).toBe(config); + expect(result).toBe(true); + }); + + it('should call the PushNotification.hasPermission method', function() { + + var result; + + spyOn(window.PushNotification, 'hasPermission') + .and.callFake(function (successCb) { + successCb({ isEnabled: true }); + }); + + $cordovaPushV5.hasPermission() + .then(function (response) { + result = response; + }); + + $rootScope.$digest(); + expect(window.PushNotification.hasPermission).toHaveBeenCalled; + expect(result.isEnabled).toBe(true); + }); +}); diff --git a/test/plugins/sqlite.spec.js b/test/plugins/sqlite.spec.js index e99d04b5..1d1e3c0a 100644 --- a/test/plugins/sqlite.spec.js +++ b/test/plugins/sqlite.spec.js @@ -70,7 +70,7 @@ describe('Service: $cordovaSQLite', function() { expect(result).toBe(true); }); - it('should call errorCb when in window\'s sqlitePlugin.deleteDatabase a error orccurs', function() { + it('should call errorCb when in window\'s sqlitePlugin.deleteDatabase an error orccurs', function() { var result; var errorObj = { someError: 1 }; @@ -90,5 +90,4 @@ describe('Service: $cordovaSQLite', function() { expect(result).toBe(errorObj); }); - }); diff --git a/test/plugins/webIntent.spec.js b/test/plugins/webIntent.spec.js new file mode 100644 index 00000000..697114fd --- /dev/null +++ b/test/plugins/webIntent.spec.js @@ -0,0 +1,92 @@ +describe('Service: $webIntent', function() { + + var $webIntent, $rootScope; + + beforeEach(module('ngCordova.plugins.webIntent')); + + beforeEach(inject(function (_$webIntent_, _$q_, _$rootScope_) { + $webIntent = _$webIntent_; + $rootScope = _$rootScope_; + + window.plugins.webintent = { + ACTION_SEND: "actionSend", + ACTION_VIEW: "actionView", + EXTRA_TEXT: "extraText", + EXTRA_SUBJECT: "extraSubject", + EXTRA_STREAM: "extraStream", + EXTRA_EMAIL: "extraEmail", + ACTION_CALL: "actionCall", + ACTION_SENDTO: "actionSendTo", + startActivity: jasmine.createSpy(), + hasExtra: jasmine.createSpy(), + getUri: jasmine.createSpy(), + getExtra: jasmine.createSpy(), + onNewIntent: jasmine.createSpy(), + sendBroadcast: jasmine.createSpy() + }; + })); + + it('should return window.plugins.webintent.ACTION_SEND on actionSend', function() { + expect($webIntent.actionSend()).toBe(window.plugins.webintent.ACTION_SEND); + }); + + it('should return window.plugins.webintent.ACTION_VIEW on actionView', function() { + expect($webIntent.actionView()).toBe(window.plugins.webintent.ACTION_VIEW); + }); + + it('should return window.plugins.webintent.EXTRA_TEXT on extraText', function() { + expect($webIntent.extraText()).toBe(window.plugins.webintent.EXTRA_TEXT); + }); + + it('should return window.plugins.webintent.EXTRA_SUBJECT on extraSubject', function() { + expect($webIntent.extraSubject()).toBe(window.plugins.webintent.EXTRA_SUBJECT); + }); + + it('should return window.plugins.webintent.EXTRA_STREAM on extraStream', function() { + expect($webIntent.extraStream()).toBe(window.plugins.webintent.EXTRA_STREAM); + }); + + it('should return window.plugins.webintent.EXTRA_EMAIL on extraEmail', function() { + expect($webIntent.extraEmail()).toBe(window.plugins.webintent.EXTRA_EMAIL); + }); + + it('should return window.plugins.webintent.ACTION_CALL on actionCall', function() { + expect($webIntent.actionCall()).toBe(window.plugins.webintent.ACTION_CALL); + }); + + it('should return window.plugins.webintent.ACTION_SENDTO on actionSendTo', function() { + expect($webIntent.actionSendTo()).toBe(window.plugins.webintent.ACTION_SENDTO); + }); + + + it('should call window.plugins.webintent.startActivity on startActivity', function() { + $webIntent.startActivity("myFile"); + expect(window.plugins.webintent.startActivity).toHaveBeenCalled(); + }); + + it('should call window.plugins.webintent.hasExtra on hasExtra', function() { + $webIntent.hasExtra($webIntent.extraText()); + expect(window.plugins.webintent.hasExtra).toHaveBeenCalled(); + }); + + it('should call window.plugins.webintent.getExtra on getExtra', function() { + $webIntent.getExtra($webIntent.extraText()); + expect(window.plugins.webintent.getExtra).toHaveBeenCalled(); + }); + + it('should call window.plugins.webintent.getUri on getUri', function() { + $webIntent.getUri(); + expect(window.plugins.webintent.getUri).toHaveBeenCalled(); + }); + + it('should call window.plugins.webintent.onNewIntent on onNewIntent', function() { + $webIntent.onNewIntent(function() {}); + expect(window.plugins.webintent.onNewIntent).toHaveBeenCalled(); + }); + + it('should call window.plugins.webintent.sendBroadcast on sendBroadcast', function() { + $webIntent.sendBroadcast("myFile"); + expect(window.plugins.webintent.sendBroadcast).toHaveBeenCalled(); + }); + +});