updates karma tests

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

View File

@ -147,7 +147,8 @@ angular.module('copayApp.controllers').controller('HistoryController',
_.each(res, function(r) {
var tx = index[r.ts];
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() {
$scope.$digest();

View File

@ -1,5 +1,5 @@
'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.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) {
if (!w) return;
$scope.loading = w.id;
identityService.deleteWallet(w.id,function() {
identityService.deleteWallet(w, function(err) {
$scope.loading = false;
if (err) {
log.warn(err);
}
});
};

View File

@ -19,6 +19,7 @@ angular.module('copayApp.services')
var r = {};
r.totalBalance = $filter('noFractionNumber')(balanceSat * satToUnit);
r.totalBalanceBTC = (balanceSat / COIN);
var availableBalanceNr = safeBalanceSat * satToUnit;
r.availableBalance = $filter('noFractionNumber')(safeBalanceSat * satToUnit);
r.availableBalanceBTC = (safeBalanceSat / COIN);
r.safeUnspentCount = safeUnspentCount;
@ -29,7 +30,7 @@ angular.module('copayApp.services')
if (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 = {};

View File

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

View File

@ -15,6 +15,8 @@ saveAs = function(blob, filename) {
describe("Unit: Controllers", function() {
config.plugins.LocalStorage = true;
config.plugins.GoogleDrive = null;
config.plugins.InsightStorage = null;
config.plugins.EncryptedInsightStorage= null;
var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy';
var anAmount = 1000;
@ -254,13 +256,13 @@ describe("Unit: Controllers", function() {
sendForm.amount.$setViewValue(anAmount);
sendForm.comment.$setViewValue(aComment);
scope.loadTxs = sinon.spy();
scope.updateTxs = sinon.spy();
var w = scope.wallet;
scope.submitForm(sendForm);
sinon.assert.callCount(w.spend, 1);
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];
spendArgs.toAddress.should.equal(anAddr);
spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi);
@ -275,7 +277,7 @@ describe("Unit: Controllers", function() {
sendForm.amount.$setViewValue(100);
sendForm.address.$setViewValue(anAddr);
scope.loadTxs = sinon.spy();
scope.updateTxs = sinon.spy();
scope.submitForm(sendForm);
var w = scope.wallet;
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() {
var w = scope.wallet;
scope.deleteWallet(w);
scope.$digest();
expect(scope.wallet).equal(null);
scope.deleteWallet(w, function() {
scope.$digest();
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;
expect(controllerUtils.updateBalance).not.to.equal(null);
expect(balanceService.update).not.to.equal(null);
var Waddr = Object.keys($rootScope.wallet.balanceByAddr)[0];
var a = {};
a[Waddr] = 200;
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)
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($rootScope.availableBalanceBTC).to.be.equal(0.90000002);
expect($rootScope.lockedBalanceBTC).to.be.equal(0.09999999);
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;
expect(b.balanceByAddr[Waddr]).to.equal(2);
expect(b.safeUnspentCount).to.equal(5);
expect(b.topAmount).to.equal(899800.02);
},false);
}));
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() {