From bfcd106b6f47daa5851644d05eebf5459fea24a8 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 9 Dec 2014 16:55:32 -0300 Subject: [PATCH] fix karma tests --- js/controllers/send.js | 29 +++++++++++++---------- test/unit/controllers/controllersSpec.js | 30 ++++++++++++------------ test/unit/directives/directivesSpec.js | 9 ------- views/home.html | 2 +- 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 8bf5c57fe..3e8b3a377 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -5,10 +5,10 @@ var preconditions = require('preconditions').singleton(); angular.module('copayApp.controllers').controller('SendController', function($scope, $rootScope, $window, $timeout, $modal, $filter, notification, isMobile, rateService, txStatus) { - var satToUnit, unitToSat, w; + var satToUnit; $scope.init = function() { - w = $rootScope.wallet; + var w = $rootScope.wallet; preconditions.checkState(w); preconditions.checkState(w.settings.unitToSatoshi); @@ -16,7 +16,6 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loading = false; $scope.error = $scope.success = null; - unitToSat = w.settings.unitToSatoshi; satToUnit = 1 / w.settings.unitToSatoshi; $scope.alternativeName = w.settings.alternativeName; @@ -32,7 +31,7 @@ angular.module('copayApp.controllers').controller('SendController', $timeout(function() { $scope.setFromUri($rootScope.pendingPayment) $rootScope.pendingPayment = null; - },100); + }, 100); } $scope.setInputs(); @@ -45,6 +44,8 @@ angular.module('copayApp.controllers').controller('SendController', } $scope.setInputs = function() { + var w = $rootScope.wallet; + var unitToSat = w.settings.unitToSatoshi; /** * Setting the two related amounts as properties prevents an infinite * recursion for watches while preserving the original angular updates @@ -75,7 +76,6 @@ angular.module('copayApp.controllers').controller('SendController', set: function(newValue) { this.__amount = newValue; if (typeof(newValue) === 'number' && $scope.isRateAvailable) { - this.__alternative = parseFloat( (rateService.toFiat(newValue * unitToSat, $scope.alternativeIsoCode)).toFixed(2), 10); } else { @@ -135,6 +135,8 @@ angular.module('copayApp.controllers').controller('SendController', }; $scope.submitForm = function(form) { + var w = $rootScope.wallet; + var unitToSat = w.settings.unitToSatoshi; if (form.$invalid) { $scope.error = 'Unable to send transaction proposal'; @@ -161,9 +163,6 @@ angular.module('copayApp.controllers').controller('SendController', if (err) return $scope.setError(err); - - console.log('[send.js.162:status:]', status); //TODO - $scope.resetForm(status); }); }; @@ -304,10 +303,13 @@ angular.module('copayApp.controllers').controller('SendController', } $scope.setTopAmount = function() { + var w = $rootScope.wallet; var form = $scope.sendForm; - form.amount.$setViewValue(w.balanceInfo.topAmount); - form.amount.$render(); - form.amount.$isValid = true; + if (form) { + form.amount.$setViewValue(w.balanceInfo.topAmount); + form.amount.$render(); + form.amount.$isValid = true; + } }; $scope.notifyStatus = function(status) { @@ -324,12 +326,13 @@ angular.module('copayApp.controllers').controller('SendController', if (msg) $scope.openTxStatusModal(msg); - else + else $scope.error = status; }; $scope.send = function(ntxid, cb) { + var w = $rootScope.wallet; $scope.error = $scope.success = null; $scope.loading = true; $rootScope.txAlertCount = 0; @@ -417,6 +420,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.setFromPayPro = function(uri) { + var w = $rootScope.wallet; $scope.fetchingURL = uri; $scope.loading = true; @@ -477,6 +481,7 @@ angular.module('copayApp.controllers').controller('SendController', }; $scope.openAddressBook = function() { + var w = $rootScope.wallet; var modalInstance = $modal.open({ templateUrl: 'views/modals/address-book.html', windowClass: 'large', diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 80c1151a4..627048d5b 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -189,16 +189,16 @@ describe("Unit: Controllers", function() { scope.model = { newaddress: null, newlabel: null, - address: null, - amount: null + _address: null, + _amount: null }; $compile(element)(scope); var element2 = angular.element( '
' + - '' + - '' + - '' + + '' + + '' + + '' + '' + '
' ); @@ -207,7 +207,7 @@ describe("Unit: Controllers", function() { $scope: scope, $modal: {}, }); - + scope.init(); scope.$digest(); form = scope.form; sendForm = scope.form2; @@ -215,11 +215,11 @@ describe("Unit: Controllers", function() { })); it('should have a SendController controller', function() { - expect(scope.loading).equal(false); + should.exist(scope.submitForm); }); it('should have a title', function() { - expect(scope.title).equal('Create Transaction Proposal'); + expect(scope.title); }); it('should validate address with network', function() { @@ -296,7 +296,8 @@ describe("Unit: Controllers", function() { scope.rateService.whenAvailable(function() { sendForm.amount.$setViewValue(1e6); scope.$digest(); - expect(scope.alternative).to.equal(2); + expect(scope._amount).to.equal(1e6); + expect(scope.__alternative).to.equal(2); done(); }); }); @@ -304,7 +305,8 @@ describe("Unit: Controllers", function() { scope.rateService.whenAvailable(function() { sendForm.alternative.$setViewValue(2); scope.$digest(); - expect(scope.amount).to.equal(1e6); + expect(scope.__alternative).to.equal(2); + expect(scope._amount).to.equal(1e6); done(); }); }); @@ -511,7 +513,7 @@ describe("Unit: Controllers", function() { }); }); - describe('UriPayment Controller', function() { + describe('paymentUriController Controller', function() { var what; beforeEach(inject(function($controller, $rootScope, $location) { scope = $rootScope.$new(); @@ -522,7 +524,7 @@ describe("Unit: Controllers", function() { amount: 0.1, message: "a bitcoin donation" }; - what = $controller('UriPaymentController', { + what = $controller('paymentUriController', { $scope: scope, $routeParams: routeParams, $location: { @@ -540,9 +542,7 @@ describe("Unit: Controllers", function() { it('should parse url correctly', function() { should.exist(what); should.exist(scope.pendingPayment); - scope.pendingPayment.address.data.should.equal('19mP9FKrXqL46Si58pHdhGKow88SUPy1V8'); - scope.pendingPayment.data.amount.should.equal(0.1); - scope.pendingPayment.data.message.should.equal('a bitcoin donation'); + scope.pendingPayment.should.equal('bitcoin:19mP9FKrXqL46Si58pHdhGKow88SUPy1V8?amount=0.1&message=a bitcoin donation'); }); }); diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index 65c9091de..d8d60c304 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -94,9 +94,6 @@ describe("Unit: Testing Directives", function() { form.amount.$setViewValue(800); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(900); - expect($scope.notValidAmount).to.equal(null); - form.amount.$setViewValue(0.44); - expect($scope.notValidAmount).to.equal(null); }); @@ -105,8 +102,6 @@ describe("Unit: Testing Directives", function() { expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(999999999999); expect(form.amount.$invalid).to.equal(true); - form.amount.$setViewValue(0.333); - expect($scope.notValidAmount).to.equal(true); }); }); @@ -134,19 +129,15 @@ describe("Unit: Testing Directives", function() { it('should validate', function() { form.amount.$setViewValue(0.01); - expect($scope.notValidAmount).to.equal(null); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(0.039); - expect($scope.notValidAmount).to.equal(null); expect(form.amount.$invalid).to.equal(false); form.amount.$setViewValue(100292.039); - expect($scope.notValidAmount).to.equal(null); expect(form.amount.$invalid).to.equal(false); }); it('should not validate', function() { form.amount.$setViewValue(0.039998888888888); - expect($scope.notValidAmount).to.equal(true); expect(form.amount.$invalid).to.equal(true); form.amount.$setViewValue(0); expect(form.amount.$invalid).to.equal(true); diff --git a/views/home.html b/views/home.html index e6d096795..6ecc217f4 100644 --- a/views/home.html +++ b/views/home.html @@ -162,7 +162,7 @@ -
+
* Using this device storage. Change to cloud storage on 'settings'.