From 18034fd643daf0ddb2c3cd1185a704d758c12f4c Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Tue, 9 Dec 2014 19:29:56 -0300 Subject: [PATCH] fix karma by @matiu --- js/controllers/profile.js | 3 +- js/services/identityService.js | 2 +- test/unit/controllers/controllersSpec.js | 49 ++++++++++++++++++------ views/profile.html | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/js/controllers/profile.js b/js/controllers/profile.js index ca58d73f8..06fbf4e1a 100644 --- a/js/controllers/profile.js +++ b/js/controllers/profile.js @@ -57,7 +57,7 @@ angular.module('copayApp.controllers').controller('ProfileController', function( }); }; - $scope.walletInfo = function(w) { + $scope.showWalletInfo = function(w) { var ModalInstanceCtrl = function($scope, $modalInstance) { if (!w) return; $scope.isSafari = isMobile.Safari(); @@ -66,6 +66,7 @@ angular.module('copayApp.controllers').controller('ProfileController', function( $scope.success = null; $scope.deleteWallet = function() { + $scope.loading = true; identityService.deleteWallet($scope.item, function(err) { if (err) { diff --git a/js/services/identityService.js b/js/services/identityService.js index 5620e8e49..711d15301 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -120,7 +120,7 @@ angular.module('copayApp.services') }; root.deleteWallet = function(w, cb) { - $rootScope.iden.deleteWallet(w.id, cb); + $rootScope.iden.deleteWallet(w.getId(), cb); }; root.isFocused = function(wid) { diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 80c1151a4..606d9c1f3 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -16,7 +16,7 @@ describe("Unit: Controllers", function() { config.plugins.LocalStorage = true; config.plugins.GoogleDrive = null; config.plugins.InsightStorage = null; - config.plugins.EncryptedInsightStorage= null; + config.plugins.EncryptedInsightStorage = null; var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'; var anAmount = 1000; @@ -50,6 +50,10 @@ describe("Unit: Controllers", function() { $rootScope.safeUnspentCount = 1; $rootScope.pendingTxCount = 0; + // + // TODO Use the REAL wallet, and stub only networking and DB components! + // + var w = {}; w.id = 1234; w.isComplete = sinon.stub().returns(true); @@ -92,7 +96,9 @@ describe("Unit: Controllers", function() { 'e': 'errmsg', 'loading': false }); - w.sizes = sinon.stub().returns({tota:1234}); + w.sizes = sinon.stub().returns({ + tota: 1234 + }); w.getBalance = sinon.stub().returns(10000); w.publicKeyRing = sinon.stub().yields(null); w.publicKeyRing.nicknameForCopayer = sinon.stub().returns('nickcopayer'); @@ -103,11 +109,11 @@ describe("Unit: Controllers", function() { }]); var iden = {}; - iden.deleteWallet = sinon.stub().yields(null); iden.getLastFocusedWallet = sinon.stub().returns(null); iden.listWallets = sinon.stub().returns([w]); iden.getWalletById = sinon.stub().returns(w); iden.getName = sinon.stub().returns('name'); + iden.deleteWallet = sinon.stub(); $rootScope.wallet = w; $rootScope.iden = iden; @@ -561,20 +567,35 @@ describe("Unit: Controllers", function() { }); describe('Profile Controller', function() { - var ctrl, scope; + var ctrl, inScope, modalCtrl; beforeEach(inject(function($controller, $rootScope) { scope = $rootScope.$new(); ctrl = $controller('ProfileController', { $scope: scope, - $modal: {}, + $modal: { + open: function(opts) { + inScope = $rootScope.$new(); + modalCtrl = opts.controller(inScope, { + close: sinon.stub(), + }); + return { + result: { + then: sinon.stub(), + } + }; + }, + }, }); saveAsLastCall = null; + })); it('Backup Wallet controller #download', function() { var w = scope.wallet; expect(saveAsLastCall).equal(null); - scope.downloadWalletBackup(w); + scope.showWalletInfo(w); + inScope.downloadWalletBackup(); + expect(saveAsLastCall.blob.size).equal(7); expect(saveAsLastCall.blob.type).equal('text/plain;charset=utf-8'); }); @@ -582,7 +603,8 @@ describe("Unit: Controllers", function() { it('Backup Wallet controller should name backup correctly for multiple copayers', function() { var w = scope.wallet; expect(saveAsLastCall).equal(null); - scope.downloadWalletBackup(w); + scope.showWalletInfo(w); + inScope.downloadWalletBackup(); expect(saveAsLastCall.filename).equal('nickname-fakeWallet-keybackup.json.aes'); }); @@ -590,16 +612,19 @@ describe("Unit: Controllers", function() { var w = scope.wallet; expect(saveAsLastCall).equal(null); scope.wallet.totalCopayers = 1; - scope.downloadWalletBackup(w); + scope.showWalletInfo(w); + inScope.downloadWalletBackup(); expect(saveAsLastCall.filename).equal('fakeWallet-keybackup.json.aes'); }); it('Delete a wallet', function() { var w = scope.wallet; - scope.deleteWallet(w, function() { - scope.$digest(); - expect(scope.wallet).equal(null); - }); + + scope.showWalletInfo(w); + inScope.deleteWallet(); + scope.$digest(); + scope.iden.deleteWallet.calledOnce.should.equal(true); + scope.iden.deleteWallet.getCall(0).args[0].should.equal(w.getId()); }); }); diff --git a/views/profile.html b/views/profile.html index 9b39de6f7..bc43b74bf 100644 --- a/views/profile.html +++ b/views/profile.html @@ -68,7 +68,7 @@ + ng-click="showWalletInfo(item)">