diff --git a/js/controllers/copayers.js b/js/controllers/copayers.js index 91d3ecd14..9fc338ad0 100644 --- a/js/controllers/copayers.js +++ b/js/controllers/copayers.js @@ -3,6 +3,8 @@ angular.module('copayApp.controllers').controller('CopayersController', function($scope, $rootScope, $timeout, go, identityService, notification, isCordova) { var w = $rootScope.wallet; + + $scope.init = function() { $rootScope.title = 'Share this secret with your copayers'; $scope.loading = false; @@ -11,6 +13,7 @@ angular.module('copayApp.controllers').controller('CopayersController', w.on('publicKeyRingUpdated', $scope.updateList); w.on('ready', $scope.updateList); + $scope.updateList(); }; @@ -36,7 +39,9 @@ angular.module('copayApp.controllers').controller('CopayersController', $scope.loading = null; $scope.error = err.message || err; copay.logger.warn(err); - $timeout(function () { $scope.$digest(); }); + $timeout(function() { + $scope.$digest(); + }); } else { $scope.loading = false; if ($rootScope.wallet) { diff --git a/js/controllers/send.js b/js/controllers/send.js index 7989d1ac7..ad3e861b5 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -492,7 +492,7 @@ angular.module('copayApp.controllers').controller('SendController', return $scope.setFromPayPro(parsed.data.merchant); var amount = (parsed.data && parsed.data.amount) ? - ((parsed.data.amount * 100000000).toFixed(0) * satToUnit).toFixed(w.settings.unitDecimals): 0; + ((parsed.data.amount * 100000000).toFixed(0) * satToUnit).toFixed(w.settings.unitDecimals) : 0; $scope.setForm(addr, amount, parsed.data.message, true); return addr; diff --git a/karma.conf.js b/karma.conf.js index a194c5a3a..0390efd96 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -71,14 +71,19 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { + 'js/controllers/*.js': ['coverage'] + }, + coverageReporter: { + type: 'html', + dir: 'coverage/' }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], + reporters: ['progress', 'coverage'], // web server port diff --git a/package.json b/package.json index e5641ef84..2b07cdfa0 100644 --- a/package.json +++ b/package.json @@ -63,15 +63,16 @@ "grunt-contrib-cssmin": "^0.10.0", "grunt-contrib-uglify": "^0.5.1", "grunt-contrib-watch": "^0.5.3", + "grunt-exec": "*", "grunt-jsdoc": "^0.5.7", "grunt-markdown": "^0.5.0", "grunt-mocha-test": "^0.8.2", "grunt-release": "^0.7.0", - "grunt-exec": "*", "istanbul": "^0.2.10", "karma": "^0.12.9", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^0.1.3", + "karma-coverage": "^0.2.7", "karma-firefox-launcher": "^0.1", "karma-mocha": "^0.1.9", "karma-phantomjs-launcher": "^0.1.4", diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index ca9436c26..93a3c005e 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -106,12 +106,15 @@ describe("Unit: Controllers", function() { isChange: false }]); + var iden = {}; iden.getLastFocusedWallet = sinon.stub().returns(null); iden.getWallets = sinon.stub().returns([w]); iden.getWalletById = sinon.stub().returns(w); iden.getName = sinon.stub().returns('name'); iden.deleteWallet = sinon.stub(); + iden.close = sinon.stub().returns(null); + $rootScope.wallet = w; $rootScope.iden = iden; @@ -138,12 +141,73 @@ describe("Unit: Controllers", function() { scope.create(invalidForm); }); }); + }); + + + describe('Create Profile Controller', function() { + var c, confService, idenService; + beforeEach(inject(function($controller, $rootScope, configService, identityService) { + scope = $rootScope.$new(); + confService = configService; + idenService = identityService; + c = $controller('CreateProfileController', { + $scope: scope, + }); + })); + + it('should exist', function() { + should.exist(c); + }); + + it('#init', function() { + scope.init(); + }); + + it('#clear', function() { + scope.clear(); + }); + + it('#saveSettings', function() { + var old = confService.set; + confService.set = sinon.stub().returns(null); + scope.saveSettings(); + confService.set.calledOnce.should.be.true; + confService.set = old; + }); + + it('#createProfile', function() { + var old = scope.saveSettings; + scope.saveSettings = sinon.stub().returns(null); + scope.createProfile(); + scope.saveSettings.calledOnce.should.be.true; + scope.saveSettings = old; + }); + + it('#_doCreateProfile', function() { + var old = idenService.create; + idenService.create = sinon.stub().returns(null); + scope._doCreateProfile('myemail@domain.com', 'password'); + idenService.create.calledOnce.should.be.true; + idenService.create = old; + }); + + it('#createDefaultWallet', function() { + var old = idenService.createDefaultWallet; + idenService.createDefaultWallet = sinon.stub().returns(null); + scope.createDefaultWallet(); + idenService.createDefaultWallet.calledOnce.should.be.true; + idenService.createDefaultWallet = old; + }); + + }); describe('Receive Controller', function() { var c; + var rootScope; beforeEach(inject(function($controller, $rootScope) { + rootScope = $rootScope; scope = $rootScope.$new(); c = $controller('ReceiveController', { $scope: scope, @@ -202,6 +266,8 @@ describe("Unit: Controllers", function() { c.networkName = walletConfig.networkName; c.version = '0.0.1'; + c.generateAddress = sinon.stub().returns({}); + c.balanceInfo = {}; return new Wallet(c); @@ -215,6 +281,11 @@ describe("Unit: Controllers", function() { should.exist(c); }); + it('#init', function() { + scope.init(); + rootScope.title.should.be.equal('Receive'); + }); + it('should call setAddressList', function() { scope.setAddressList(); expect(scope.addresses).to.be.empty; @@ -222,6 +293,12 @@ describe("Unit: Controllers", function() { scope.setAddressList(); expect(scope.addresses).to.be.empty; }); + + it('#newAddr', function() { + rootScope.wallet.generateAddress = sinon.stub().returns({}); + scope.newAddr(); + rootScope.wallet.generateAddress.calledOnce.should.be.true; + }); }); describe('History Controller', function() { @@ -251,10 +328,109 @@ describe("Unit: Controllers", function() { }); }); + + + describe('Profile Controller', function() { + var ctrl, bkpService, idenService; + beforeEach(inject(function($controller, $rootScope, backupService, identityService) { + scope = $rootScope.$new(); + bkpService = backupService; + idenService = identityService; + ctrl = $controller('ProfileController', { + $scope: scope, + }); + })); + + it('should exist', function() { + should.exist(ctrl); + }); + + it('#downloadProfileBackup', function() { + var old = bkpService.profileDownload; + bkpService.profileDownload = sinon.stub().returns(null); + scope.downloadProfileBackup(); + bkpService.profileDownload.calledOnce.should.be.true; + bkpService.profileDownload = old; + }); + + it('#viewProfileBackup', function() { + var old = bkpService.profileEncrypted; + bkpService.profileEncrypted = sinon.stub().returns(null); + scope.viewProfileBackup(); + //bkpService.profileEncrypted.calledOnce.should.be.true; + bkpService.profileEncrypted = old; + }); + + it('#copyProfileBackup', function() { + var old = bkpService.profileEncrypted; + bkpService.profileEncrypted = sinon.stub().returns(null); + + window.cordova = { + plugins: { + clipboard: { + copy: function(e) { + return e; + } + } + } + }; + + window.plugins = { + toast: { + showShortCenter: function(e) { + return e; + } + } + }; + + scope.copyProfileBackup(); + bkpService.profileEncrypted.calledOnce.should.be.true; + bkpService.profileEncrypted = old; + }); + + it('#sendProfileBackup', function() { + var old = bkpService.profileEncrypted; + bkpService.profileEncrypted = sinon.stub().returns(null); + + window.plugin = { + email: { + open: function(e) { + return e; + } + } + }; + + window.plugins = { + toast: { + showShortCenter: function(e) { + return e; + } + } + }; + + scope.sendProfileBackup(); + bkpService.profileEncrypted.calledOnce.should.be.true; + bkpService.profileEncrypted = old; + }); + + it('#deleteProfile', function() { + var old = idenService.deleteProfile; + idenService.deleteProfile = sinon.stub().returns(null); + scope.deleteProfile(); + idenService.deleteProfile.calledOnce.should.be.true; + idenService.deleteProfile = old; + }); + + + }); + + + describe('Send Controller', function() { - var scope, form, sendForm, sendCtrl; + var scope, form, sendForm, sendCtrl, rootScope; beforeEach(angular.mock.inject(function($compile, $rootScope, $controller, rateService, notification) { scope = $rootScope.$new(); + rootScope = $rootScope; scope.rateService = rateService; var element = angular.element( '