settings: fix angular test 1

This commit is contained in:
Manuel Araoz 2014-09-05 15:54:44 -07:00
commit 6bdeaadb94
5 changed files with 132 additions and 95 deletions

View file

@ -1,10 +1,12 @@
'use strict';
angular.module('copayApp.directives')
.directive('validAddress', ['$rootScope', function($rootScope) {
var bitcore = require('bitcore');
var Address = bitcore.Address;
var bignum = bitcore.Bignum;
var preconditions = require('preconditions').singleton();
angular.module('copayApp.directives')
irective('validAddress', ['$rootScope', function($rootScope) {
return {
require: 'ngModel',
@ -46,8 +48,10 @@ angular.module('copayApp.directives')
}])
.directive('enoughAmount', ['$rootScope',
function($rootScope) {
var bitcore = require('bitcore');
var w = $rootScope.wallet;
preconditions.checkState(w);
preconditions.checkState(w.settings.unitToSatoshi);
var feeSat = Number(bitcore.TransactionBuilder.FEE_PER_1000B_SAT);
return {
require: 'ngModel',

View file

@ -6,8 +6,7 @@ if (is_browser) {
}
var Wallet = copay.Wallet;
var FakePrivateKey = function () {
};
var FakePrivateKey = function() {};
FakePrivateKey.prototype.toObj = function() {
return extendedPublicKeyString = 'privHex';
@ -37,12 +36,20 @@ var FakeWallet = function() {
}
};
this.blockchain = {
getSubscriptions: function(){ return []; },
getSubscriptions: function() {
return [];
},
subscribe: function() {}
};
this.privateKey = new FakePrivateKey();
this.settings = {};
this.settings = {
unitName: 'bits',
unitToSatoshi: 100,
unitDecimals: 2,
alternativeName: 'US Dollar',
alternativeIsoCode: 'USD',
};
};
FakeWallet.prototype.createTx = function(toAddress, amountSatStr, comment, opts, cb) {
@ -99,8 +106,7 @@ FakeWallet.prototype.getBalance = function(cb) {
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
};
FakeWallet.prototype.removeTxWithSpentInputs = function (cb) {
};
FakeWallet.prototype.removeTxWithSpentInputs = function(cb) {};
FakeWallet.prototype.setEnc = function(enc) {
this.enc = enc;
@ -110,8 +116,7 @@ FakeWallet.prototype.toEncryptedObj = function() {
return this.enc;
};
FakeWallet.prototype.close = function() {
};
FakeWallet.prototype.close = function() {};
// TODO a try catch was here
module.exports = FakeWallet;

View file

@ -8,17 +8,23 @@ describe("Unit: Testing Directives", function() {
beforeEach(module('copayApp.directives'));
beforeEach(function() {
config.unitToSatoshi = 100;
config.unitName = 'bits';
});
var walletConfig = {
requiredCopayers: 3,
totalCopayers: 5,
spendUnconfirmed: 1,
reconnectDelay: 100,
networkName: 'testnet',
alternativeName: 'lol currency',
alternativeIsoCode: 'LOL'
};
describe('Check config', function() {
it('unit should be set to BITS in config.js', function() {
expect(config.unitToSatoshi).to.equal(100);
expect(config.unitName).to.equal('bits');
});
});
beforeEach(inject(function($rootScope) {
$rootScope.wallet = new FakeWallet(walletConfig);
var w = $rootScope.wallet;
w.settings.unitToSatoshi = 100;
w.settings.unitName = 'bits';
}));
describe('Validate Address', function() {
beforeEach(inject(function($compile, $rootScope) {
@ -94,9 +100,12 @@ describe("Unit: Testing Directives", function() {
describe('Unit: BTC', function() {
beforeEach(inject(function($compile, $rootScope) {
config.unitToSatoshi = 100000000;
config.unitName = 'BTC';
$scope = $rootScope;
var w = new FakeWallet(walletConfig);
w.settings.unitToSatoshi = 100000000;
w.settings.unitName = 'BTC';
$rootScope.wallet = w;
$rootScope.availableBalance = 0.04;
var element = angular.element(
'<form name="form">' +

View file

@ -5,6 +5,15 @@
describe('Unit: Testing Filters', function() {
beforeEach(module('copayApp.filters'));
var walletConfig = {
requiredCopayers: 3,
totalCopayers: 5,
spendUnconfirmed: 1,
reconnectDelay: 100,
networkName: 'testnet',
alternativeName: 'lol currency',
alternativeIsoCode: 'LOL'
};
describe('limitAddress', function() {
@ -103,11 +112,14 @@ describe('Unit: Testing Filters', function() {
}));
});
describe('noFractionNumber', function() {
describe('noFractionNumber bits', function() {
beforeEach(function() {
config.unitToSatoshi = 100;
config.unitName = 'bits';
});
beforeEach(inject(function($rootScope) {
$rootScope.wallet = new FakeWallet(walletConfig);
var w = $rootScope.wallet;
w.settings.unitToSatoshi = 100;
w.settings.unitName = 'bits';
}));
it('should format number to display correctly', inject(function($filter) {
var noFraction = $filter('noFractionNumber');
expect(noFraction(3100)).to.equal('3,100');
@ -121,10 +133,12 @@ describe('Unit: Testing Filters', function() {
});
describe('noFractionNumber BTC', function() {
beforeEach(function() {
config.unitToSatoshi = 100000000;
config.unitName = 'BTC';
});
beforeEach(inject(function($rootScope) {
$rootScope.wallet = new FakeWallet(walletConfig);
var w = $rootScope.wallet;
w.settings.unitToSatoshi = 100000000;
w.settings.unitName = 'BTC';
}));
it('should format number to display correctly', inject(function($filter) {
var noFraction = $filter('noFractionNumber');
expect(noFraction(0.30000000)).to.equal(0.3);
@ -139,10 +153,12 @@ describe('Unit: Testing Filters', function() {
});
describe('noFractionNumber mBTC', function() {
beforeEach(function() {
config.unitToSatoshi = 100000;
config.unitName = 'mBTC';
});
beforeEach(inject(function($rootScope) {
$rootScope.wallet = new FakeWallet(walletConfig);
var w = $rootScope.wallet;
w.settings.unitToSatoshi = 100000;
w.settings.unitName = 'mBTC';
}));
it('should format number to display correctly', inject(function($filter) {
var noFraction = $filter('noFractionNumber');
expect(noFraction(0.30000)).to.equal(0.3);
@ -168,3 +184,4 @@ describe('Unit: Testing Filters', function() {
});
});
});

View file

@ -15,7 +15,9 @@ var getCommitHash = function() {
//exec git command to get the hash of the current commit
//git rev-parse HEAD
var hash = shell.exec('git rev-parse HEAD',{silent:true}).output.trim().substr(0,7);
var hash = shell.exec('git rev-parse HEAD', {
silent: true
}).output.trim().substr(0, 7);
return hash;
}
@ -43,9 +45,9 @@ var createBundle = function(opts) {
b.require('browser-request', {
expose: 'request'
});
b.require('underscore', {
expose: 'underscore'
});
b.require('underscore');
b.require('assert');
b.require('preconditions');
b.require('./copay', {
expose: 'copay'