updates karma tests

This commit is contained in:
Matias Alejo Garcia 2014-11-30 23:08:16 -03:00
commit f490f4a661
6 changed files with 37 additions and 46 deletions

View file

@ -147,7 +147,8 @@ angular.module('copayApp.controllers').controller('HistoryController',
_.each(res, function(r) { _.each(res, function(r) {
var tx = index[r.ts]; var tx = index[r.ts];
tx.alternativeAmount = $filter('noFractionNumber')( tx.alternativeAmount = $filter('noFractionNumber')(
(r.rate != null ? tx.amountSat * rateService.SAT_TO_BTC * r.rate : null); (r.rate != null ? tx.amountSat * rateService.SAT_TO_BTC * r.rate : null))
;
}); });
setTimeout(function() { setTimeout(function() {
$scope.$digest(); $scope.$digest();

View file

@ -1,5 +1,5 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, backupService) { angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, backupService, identityService) {
$scope.username = $rootScope.iden.getName(); $scope.username = $rootScope.iden.getName();
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
@ -16,10 +16,11 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
$scope.deleteWallet = function(w) { $scope.deleteWallet = function(w) {
if (!w) return; if (!w) return;
$scope.loading = w.id; identityService.deleteWallet(w, function(err) {
identityService.deleteWallet(w.id,function() {
$scope.loading = false; $scope.loading = false;
if (err) {
log.warn(err);
}
}); });
}; };

View file

@ -19,6 +19,7 @@ angular.module('copayApp.services')
var r = {}; var r = {};
r.totalBalance = $filter('noFractionNumber')(balanceSat * satToUnit); r.totalBalance = $filter('noFractionNumber')(balanceSat * satToUnit);
r.totalBalanceBTC = (balanceSat / COIN); r.totalBalanceBTC = (balanceSat / COIN);
var availableBalanceNr = safeBalanceSat * satToUnit;
r.availableBalance = $filter('noFractionNumber')(safeBalanceSat * satToUnit); r.availableBalance = $filter('noFractionNumber')(safeBalanceSat * satToUnit);
r.availableBalanceBTC = (safeBalanceSat / COIN); r.availableBalanceBTC = (safeBalanceSat / COIN);
r.safeUnspentCount = safeUnspentCount; r.safeUnspentCount = safeUnspentCount;
@ -29,7 +30,7 @@ angular.module('copayApp.services')
if (r.safeUnspentCount) { if (r.safeUnspentCount) {
var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount); var estimatedFee = copay.Wallet.estimatedFee(r.safeUnspentCount);
r.topAmount = (((r.availableBalance * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi); r.topAmount = (((availableBalanceNr * w.settings.unitToSatoshi).toFixed(0) - estimatedFee) / w.settings.unitToSatoshi);
} }
var balanceByAddr = {}; var balanceByAddr = {};

View file

@ -87,8 +87,8 @@ angular.module('copayApp.services')
}); });
}; };
root.deleteWallet = function($scope, iden, w) { root.deleteWallet = function(w, cb) {
$rootScope.iden.deleteWallet(w.id); $rootScope.iden.deleteWallet(w.id, cb);
}; };
root.isFocused = function(wid) { root.isFocused = function(wid) {

View file

@ -15,6 +15,8 @@ saveAs = function(blob, filename) {
describe("Unit: Controllers", function() { describe("Unit: Controllers", function() {
config.plugins.LocalStorage = true; config.plugins.LocalStorage = true;
config.plugins.GoogleDrive = null; config.plugins.GoogleDrive = null;
config.plugins.InsightStorage = null;
config.plugins.EncryptedInsightStorage= null;
var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'; var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy';
var anAmount = 1000; var anAmount = 1000;
@ -254,13 +256,13 @@ describe("Unit: Controllers", function() {
sendForm.amount.$setViewValue(anAmount); sendForm.amount.$setViewValue(anAmount);
sendForm.comment.$setViewValue(aComment); sendForm.comment.$setViewValue(aComment);
scope.loadTxs = sinon.spy(); scope.updateTxs = sinon.spy();
var w = scope.wallet; var w = scope.wallet;
scope.submitForm(sendForm); scope.submitForm(sendForm);
sinon.assert.callCount(w.spend, 1); sinon.assert.callCount(w.spend, 1);
sinon.assert.callCount(w.broadcastTx, 0); sinon.assert.callCount(w.broadcastTx, 0);
sinon.assert.callCount(scope.loadTxs, 1); sinon.assert.callCount(scope.updateTxs, 1);
var spendArgs = w.spend.getCall(0).args[0]; var spendArgs = w.spend.getCall(0).args[0];
spendArgs.toAddress.should.equal(anAddr); spendArgs.toAddress.should.equal(anAddr);
spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi); spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi);
@ -275,7 +277,7 @@ describe("Unit: Controllers", function() {
sendForm.amount.$setViewValue(100); sendForm.amount.$setViewValue(100);
sendForm.address.$setViewValue(anAddr); sendForm.address.$setViewValue(anAddr);
scope.loadTxs = sinon.spy(); scope.updateTxs = sinon.spy();
scope.submitForm(sendForm); scope.submitForm(sendForm);
var w = scope.wallet; var w = scope.wallet;
w.spend.getCall(0).args[0].amountSat.should.equal(100 * scope.wallet.settings.unitToSatoshi); w.spend.getCall(0).args[0].amountSat.should.equal(100 * scope.wallet.settings.unitToSatoshi);
@ -602,9 +604,10 @@ describe("Unit: Controllers", function() {
it('Delete a wallet', function() { it('Delete a wallet', function() {
var w = scope.wallet; var w = scope.wallet;
scope.deleteWallet(w); scope.deleteWallet(w, function() {
scope.$digest(); scope.$digest();
expect(scope.wallet).equal(null); expect(scope.wallet).equal(null);
});
}); });
}); });

View file

@ -65,49 +65,34 @@ describe("Angular services", function() {
describe("Unit: controllerUtils", function() { describe("Unit: balanceService", function() {
it('should updateBalance in bits', inject(function(controllerUtils, $rootScope) { it('should updateBalance in bits', inject(function(balanceService, $rootScope) {
var w = $rootScope.wallet; var w = $rootScope.wallet;
expect(balanceService.update).not.to.equal(null);
expect(controllerUtils.updateBalance).not.to.equal(null);
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0]; var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
var a = {}; var a = {};
a[Waddr] = 200; a[Waddr] = 200;
w.getBalance = sinon.stub().yields(null, 100000001, a, 90000002, 5); w.getBalance = sinon.stub().yields(null, 100000001, a, 90000002, 5);
var orig =controllerUtils.isFocusedWallet;
controllerUtils.isFocusedWallet = sinon.stub().returns(true);
//retuns values in DEFAULT UNIT(bits) //retuns values in DEFAULT UNIT(bits)
controllerUtils.updateBalance(null, function() { balanceService.update(w, function() {
var b = w.balanceInfo;
expect(b.totalBalanceBTC).to.be.equal(1.00000001);
expect(b.availableBalanceBTC).to.be.equal(0.90000002);
expect(b.lockedBalanceBTC).to.be.equal(0.09999999);
expect(b.totalBalance).to.be.equal('1,000,000.01');
expect(b.availableBalance).to.be.equal('900,000.02');
expect(b.lockedBalance).to.be.equal(99999.99);
expect($rootScope.totalBalanceBTC).to.be.equal(1.00000001); expect(b.balanceByAddr[Waddr]).to.equal(2);
expect($rootScope.availableBalanceBTC).to.be.equal(0.90000002); expect(b.safeUnspentCount).to.equal(5);
expect($rootScope.lockedBalanceBTC).to.be.equal(0.09999999); expect(b.topAmount).to.equal(899800.02);
},false);
expect($rootScope.totalBalance).to.be.equal(1000000.01);
expect($rootScope.availableBalance).to.be.equal(900000.02);
expect($rootScope.lockedBalance).to.be.equal(99999.99);
expect($rootScope.balanceByAddr[Waddr]).to.equal(2);
expect($rootScope.safeUnspentCount).to.equal(5);
expect($rootScope.topAmount).to.equal(899800.02);
});
controllerUtils.isFocusedWallet = orig;
})); }));
it('should set the rootScope', inject(function(controllerUtils, $rootScope) {
controllerUtils.setupGlobalVariables(function() {
expect($rootScope.txAlertCount).to.be.equal(0);
expect($rootScope.insightError).to.be.equal(0);
expect($rootScope.isCollapsed).to.be.equal(0);
expect($rootScope.unitName).to.be.equal('bits');
});
}));
}); });
describe("Unit: Notification Service", function() { describe("Unit: Notification Service", function() {