From 0c03af53a89eb734016ea7e5ae92f1b2d19abb34 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 18 Jun 2014 13:01:50 -0300 Subject: [PATCH] fixed karma test bug --- js/controllers/header.js | 6 +++--- js/services/backupService.js | 5 +++-- js/services/controllerUtils.js | 8 ++++---- js/services/notifications.js | 17 +++++++++++------ js/services/video.js | 6 ++++-- karma.conf.js | 16 +++++++--------- package.json | 7 ++++--- test/unit/services/servicesSpec.js | 9 ++++++++- 8 files changed, 44 insertions(+), 30 deletions(-) diff --git a/js/controllers/header.js b/js/controllers/header.js index 1afd1ec80..ba4a0d521 100644 --- a/js/controllers/header.js +++ b/js/controllers/header.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('HeaderController', - function($scope, $rootScope, $location, $notification, $http, controllerUtils) { + function($scope, $rootScope, $location, notification, $http, controllerUtils) { $scope.menu = [ { 'title': 'Addresses', @@ -64,7 +64,7 @@ angular.module('copayApp.controllers').controller('HeaderController', } if (currentAddr) { //var beep = new Audio('sound/transaction.mp3'); - $notification.funds('Received fund', currentAddr, receivedFund); + notification.funds('Received fund', currentAddr, receivedFund); //beep.play(); } } @@ -72,7 +72,7 @@ angular.module('copayApp.controllers').controller('HeaderController', $rootScope.$watch('txAlertCount', function(txAlertCount) { if (txAlertCount && txAlertCount > 0) { - $notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount); + notification.info('New Transaction', ($rootScope.txAlertCount == 1) ? 'You have a pending transaction proposal' : 'You have ' + $rootScope.txAlertCount + ' pending transaction proposals', txAlertCount); } }); diff --git a/js/services/backupService.js b/js/services/backupService.js index 5485a0e12..572cad348 100644 --- a/js/services/backupService.js +++ b/js/services/backupService.js @@ -1,7 +1,8 @@ 'use strict'; -var BackupService = function($notification) { - this.notifications = $notification; + +var BackupService = function(notification) { + this.notifications = notification; }; BackupService.prototype.getName = function(wallet) { diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 5a7c6817d..66787d476 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -2,7 +2,7 @@ var bitcore = require('bitcore'); angular.module('copayApp.services') - .factory('controllerUtils', function($rootScope, $sce, $location, $notification, $timeout, Socket, video) { + .factory('controllerUtils', function($rootScope, $sce, $location, notification, $timeout, Socket, video) { var root = {}; root.getVideoMutedStatus = function(copayer) { @@ -87,7 +87,7 @@ angular.module('copayApp.services') $rootScope.$digest(); }; - $notification.enableHtml5Mode(); // for chrome: if support, enable it + notification.enableHtml5Mode(); // for chrome: if support, enable it w.on('badMessage', function(peerId) { $rootScope.$flashMessage = { @@ -126,11 +126,11 @@ angular.module('copayApp.services') switch (e.type) { case 'signed': var user = w.publicKeyRing.nicknameForCopayer(e.cId); - $notification.info('Transaction Update', 'A transaction was signed by ' + user); + notification.info('Transaction Update', 'A transaction was signed by ' + user); break; case 'rejected': var user = w.publicKeyRing.nicknameForCopayer(e.cId); - $notification.info('Transaction Update', 'A transaction was rejected by ' + user); + notification.info('Transaction Update', 'A transaction was rejected by ' + user); break; } }); diff --git a/js/services/notifications.js b/js/services/notifications.js index 1d75fb20c..8d390949f 100644 --- a/js/services/notifications.js +++ b/js/services/notifications.js @@ -1,9 +1,9 @@ 'use strict'; angular.module('copayApp.services'). - factory('$notification', ['$timeout',function($timeout){ + factory('notification', ['$timeout',function($timeout){ - var notifications = JSON.parse(localStorage.getItem('$notifications')) || [], + var notifications = JSON.parse(localStorage.getItem('notifications')) || [], queue = []; var settings = { @@ -186,7 +186,7 @@ angular.module('copayApp.services'). save: function(){ // Save all the notifications into localStorage if(settings.localStorage){ - localStorage.setItem('$notifications', JSON.stringify(notifications)); + localStorage.setItem('notifications', JSON.stringify(notifications)); } }, @@ -201,7 +201,7 @@ angular.module('copayApp.services'). }; }]). - directive('notifications', ['$notification', '$compile', function($notification, $compile){ + directive('notifications', function(notification, $compile){ /** * * It should also parse the arguments passed to it that specify @@ -245,7 +245,7 @@ angular.module('copayApp.services'). template: html, link: link, controller: ['$scope', function NotificationsCtrl( $scope ){ - $scope.queue = $notification.getQueue(); + $scope.queue = notification.getQueue(); $scope.removeNotification = function(noti){ $scope.queue.splice($scope.queue.indexOf(noti), 1); @@ -254,4 +254,9 @@ angular.module('copayApp.services'). ] }; - }]); + }); + + + + + diff --git a/js/services/video.js b/js/services/video.js index acff9327f..fce1ee2b6 100644 --- a/js/services/video.js +++ b/js/services/video.js @@ -7,7 +7,9 @@ var Video = function() { this.mediaConnections = {}; this.localStream = null; - this.onlineSound = new Audio('sound/online.wav'); + if (typeof Audio !== 'undefined') { + this.onlineSound = new Audio('sound/online.wav'); + } }; Video.prototype.setOwnPeer = function(peer, wallet, cb) { @@ -64,7 +66,7 @@ Video.prototype._addCall = function(mediaConnection, cb) { // Wait for stream on the call, then set peer video display mediaConnection.on('stream', function(stream) { - self.onlineSound.play(); + if (self.onlineSound) self.onlineSound.play(); cb(null, peerID, URL.createObjectURL(stream)); }); diff --git a/karma.conf.js b/karma.conf.js index 077882857..48b6655b3 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -39,15 +39,6 @@ module.exports = function(config) { 'lib/qrcode-decoder-js/lib/qrcode-decoder.min.js', 'js/copayBundle.js', - //Test-Specific Code - 'lib/chai/chai.js', - 'test/lib/chai-should.js', - 'test/lib/chai-expect.js', - 'test/mocks/FakeWallet.js', - - //Mocha stuff - 'test/mocha.conf.js', - //App-specific Code 'js/app.js', 'js/routes.js', @@ -57,6 +48,13 @@ module.exports = function(config) { 'js/controllers/*.js', 'js/init.js', + //Test-Specific Code + 'lib/chai/chai.js', + 'test/lib/chai-should.js', + 'test/lib/chai-expect.js', + 'test/mocks/FakeWallet.js', + + 'test/mocha.conf.js', //test files 'test/unit/**/*.js' diff --git a/package.json b/package.json index 92d07ce8b..bec53ce4f 100644 --- a/package.json +++ b/package.json @@ -34,9 +34,11 @@ "browserify": "3.32.1", "buffertools": "2.0.1", "chai": "1.9.1", + "cli-color": "0.3.2", "commander": "2.1.0", "coveralls": "2.10.0", "express": "4.0.0", + "github-releases": "0.2.0", "grunt-browserify": "2.0.8", "grunt-contrib-watch": "0.5.3", "grunt-markdown": "0.5.0", @@ -46,15 +48,14 @@ "karma": "0.12.9", "karma-chrome-launcher": "0.1.3", "karma-mocha": "0.1.3", + "karma-phantomjs-launcher": "^0.1.4", "mocha": "1.18.2", "mocha-lcov-reporter": "0.0.1", "node-cryptojs-aes": "0.4.0", "sinon": "1.9.1", "soop": "0.1.5", "travis-cov": "0.2.5", - "uglifyify": "1.2.3", - "github-releases": "0.2.0", - "cli-color": "0.3.2" + "uglifyify": "1.2.3" }, "dependencies": { "mocha": "^1.18.2", diff --git a/test/unit/services/servicesSpec.js b/test/unit/services/servicesSpec.js index 23086e7a9..615222b54 100644 --- a/test/unit/services/servicesSpec.js +++ b/test/unit/services/servicesSpec.js @@ -3,6 +3,8 @@ // // // +var sinon = require('sinon'); + describe('Check config', function() { it('unit should be set to BITS in config.js', function() { expect(config.unitToSatoshi).to.equal(100); @@ -87,9 +89,14 @@ describe("Unit: controllerUtils", function() { }); +describe("Unit: Notification Service", function() { + beforeEach(angular.mock.module('copayApp.services')); + it('should contain a notification service', inject(function(notification) { + expect(notification).not.to.equal(null); + })); +}); describe("Unit: Backup Service", function() { - var sinon = require('sinon'); beforeEach(angular.mock.module('copayApp.services')); it('should contain a backup service', inject(function(backupService) { expect(backupService).not.to.equal(null);