settings: fix angular test 1
This commit is contained in:
parent
69b70d7d2b
commit
6bdeaadb94
5 changed files with 132 additions and 95 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
var Address = bitcore.Address;
|
||||||
|
var bignum = bitcore.Bignum;
|
||||||
|
var preconditions = require('preconditions').singleton();
|
||||||
|
|
||||||
angular.module('copayApp.directives')
|
angular.module('copayApp.directives')
|
||||||
.directive('validAddress', ['$rootScope', function($rootScope) {
|
irective('validAddress', ['$rootScope', function($rootScope) {
|
||||||
var bitcore = require('bitcore');
|
|
||||||
var Address = bitcore.Address;
|
|
||||||
var bignum = bitcore.Bignum;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
|
|
@ -46,8 +48,10 @@ angular.module('copayApp.directives')
|
||||||
}])
|
}])
|
||||||
.directive('enoughAmount', ['$rootScope',
|
.directive('enoughAmount', ['$rootScope',
|
||||||
function($rootScope) {
|
function($rootScope) {
|
||||||
var bitcore = require('bitcore');
|
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
|
preconditions.checkState(w);
|
||||||
|
preconditions.checkState(w.settings.unitToSatoshi);
|
||||||
|
|
||||||
var feeSat = Number(bitcore.TransactionBuilder.FEE_PER_1000B_SAT);
|
var feeSat = Number(bitcore.TransactionBuilder.FEE_PER_1000B_SAT);
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
|
|
@ -271,7 +275,7 @@ angular.module('copayApp.directives')
|
||||||
|
|
||||||
client.on('datarequested', function(client) {
|
client.on('datarequested', function(client) {
|
||||||
client.setText(scope.clipCopy);
|
client.setText(scope.clipCopy);
|
||||||
} );
|
});
|
||||||
|
|
||||||
client.on('complete', function(client, args) {
|
client.on('complete', function(client, args) {
|
||||||
elm.removeClass('btn-copy').addClass('btn-copied').html('Copied!');
|
elm.removeClass('btn-copy').addClass('btn-copied').html('Copied!');
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,10 @@ if (is_browser) {
|
||||||
}
|
}
|
||||||
var Wallet = copay.Wallet;
|
var Wallet = copay.Wallet;
|
||||||
|
|
||||||
var FakePrivateKey = function () {
|
var FakePrivateKey = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
FakePrivateKey.prototype.toObj = function() {
|
FakePrivateKey.prototype.toObj = function() {
|
||||||
return extendedPublicKeyString = 'privHex';
|
return extendedPublicKeyString = 'privHex';
|
||||||
};
|
};
|
||||||
|
|
||||||
var FakeWallet = function() {
|
var FakeWallet = function() {
|
||||||
|
|
@ -37,12 +36,20 @@ var FakeWallet = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.blockchain = {
|
this.blockchain = {
|
||||||
getSubscriptions: function(){ return []; },
|
getSubscriptions: function() {
|
||||||
subscribe: function(){}
|
return [];
|
||||||
|
},
|
||||||
|
subscribe: function() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.privateKey = new FakePrivateKey();
|
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) {
|
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);
|
return cb(null, this.balance, this.balanceByAddr, this.safeBalance);
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWallet.prototype.removeTxWithSpentInputs = function (cb) {
|
FakeWallet.prototype.removeTxWithSpentInputs = function(cb) {};
|
||||||
};
|
|
||||||
|
|
||||||
FakeWallet.prototype.setEnc = function(enc) {
|
FakeWallet.prototype.setEnc = function(enc) {
|
||||||
this.enc = enc;
|
this.enc = enc;
|
||||||
|
|
@ -110,8 +116,7 @@ FakeWallet.prototype.toEncryptedObj = function() {
|
||||||
return this.enc;
|
return this.enc;
|
||||||
};
|
};
|
||||||
|
|
||||||
FakeWallet.prototype.close = function() {
|
FakeWallet.prototype.close = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
// TODO a try catch was here
|
// TODO a try catch was here
|
||||||
module.exports = FakeWallet;
|
module.exports = FakeWallet;
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,23 @@ describe("Unit: Testing Directives", function() {
|
||||||
|
|
||||||
beforeEach(module('copayApp.directives'));
|
beforeEach(module('copayApp.directives'));
|
||||||
|
|
||||||
beforeEach(function() {
|
var walletConfig = {
|
||||||
config.unitToSatoshi = 100;
|
requiredCopayers: 3,
|
||||||
config.unitName = 'bits';
|
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() {
|
beforeEach(inject(function($rootScope) {
|
||||||
expect(config.unitToSatoshi).to.equal(100);
|
$rootScope.wallet = new FakeWallet(walletConfig);
|
||||||
expect(config.unitName).to.equal('bits');
|
var w = $rootScope.wallet;
|
||||||
});
|
w.settings.unitToSatoshi = 100;
|
||||||
});
|
w.settings.unitName = 'bits';
|
||||||
|
}));
|
||||||
|
|
||||||
describe('Validate Address', function() {
|
describe('Validate Address', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
|
|
@ -94,9 +100,12 @@ describe("Unit: Testing Directives", function() {
|
||||||
|
|
||||||
describe('Unit: BTC', function() {
|
describe('Unit: BTC', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
config.unitToSatoshi = 100000000;
|
|
||||||
config.unitName = 'BTC';
|
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
|
var w = new FakeWallet(walletConfig);
|
||||||
|
w.settings.unitToSatoshi = 100000000;
|
||||||
|
w.settings.unitName = 'BTC';
|
||||||
|
$rootScope.wallet = w;
|
||||||
|
|
||||||
$rootScope.availableBalance = 0.04;
|
$rootScope.availableBalance = 0.04;
|
||||||
var element = angular.element(
|
var element = angular.element(
|
||||||
'<form name="form">' +
|
'<form name="form">' +
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,15 @@
|
||||||
describe('Unit: Testing Filters', function() {
|
describe('Unit: Testing Filters', function() {
|
||||||
|
|
||||||
beforeEach(module('copayApp.filters'));
|
beforeEach(module('copayApp.filters'));
|
||||||
|
var walletConfig = {
|
||||||
|
requiredCopayers: 3,
|
||||||
|
totalCopayers: 5,
|
||||||
|
spendUnconfirmed: 1,
|
||||||
|
reconnectDelay: 100,
|
||||||
|
networkName: 'testnet',
|
||||||
|
alternativeName: 'lol currency',
|
||||||
|
alternativeIsoCode: 'LOL'
|
||||||
|
};
|
||||||
|
|
||||||
describe('limitAddress', function() {
|
describe('limitAddress', function() {
|
||||||
|
|
||||||
|
|
@ -103,68 +112,76 @@ describe('Unit: Testing Filters', function() {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('noFractionNumber bits', function() {
|
describe('noFractionNumber', function() {
|
||||||
beforeEach(function() {
|
describe('noFractionNumber bits', function() {
|
||||||
config.unitToSatoshi = 100;
|
beforeEach(inject(function($rootScope) {
|
||||||
config.unitName = 'bits';
|
$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');
|
||||||
|
expect(noFraction(3100200)).to.equal('3,100,200');
|
||||||
|
expect(noFraction(3)).to.equal('3');
|
||||||
|
expect(noFraction(0.3)).to.equal(0.3);
|
||||||
|
expect(noFraction(0.30000000)).to.equal(0.3);
|
||||||
|
expect(noFraction(3200.01)).to.equal('3,200.01');
|
||||||
|
expect(noFraction(3200890.010000)).to.equal('3,200,890.01');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
it('should format number to display correctly', inject(function($filter) {
|
|
||||||
var noFraction = $filter('noFractionNumber');
|
|
||||||
expect(noFraction(3100)).to.equal('3,100');
|
|
||||||
expect(noFraction(3100200)).to.equal('3,100,200');
|
|
||||||
expect(noFraction(3)).to.equal('3');
|
|
||||||
expect(noFraction(0.3)).to.equal(0.3);
|
|
||||||
expect(noFraction(0.30000000)).to.equal(0.3);
|
|
||||||
expect(noFraction(3200.01)).to.equal('3,200.01');
|
|
||||||
expect(noFraction(3200890.010000)).to.equal('3,200,890.01');
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('noFractionNumber BTC', function() {
|
describe('noFractionNumber BTC', function() {
|
||||||
beforeEach(function() {
|
beforeEach(inject(function($rootScope) {
|
||||||
config.unitToSatoshi = 100000000;
|
$rootScope.wallet = new FakeWallet(walletConfig);
|
||||||
config.unitName = 'BTC';
|
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);
|
||||||
|
expect(noFraction(0.00302000)).to.equal(0.00302);
|
||||||
|
expect(noFraction(1.00000001)).to.equal(1.00000001);
|
||||||
|
expect(noFraction(3.10000012)).to.equal(3.10000012);
|
||||||
|
expect(noFraction(0.00100000)).to.equal(0.001);
|
||||||
|
expect(noFraction(0.00100009)).to.equal(0.00100009);
|
||||||
|
expect(noFraction(2000.00312011)).to.equal('2,000.00312011');
|
||||||
|
expect(noFraction(2000998.00312011)).to.equal('2,000,998.00312011');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
it('should format number to display correctly', inject(function($filter) {
|
|
||||||
var noFraction = $filter('noFractionNumber');
|
|
||||||
expect(noFraction(0.30000000)).to.equal(0.3);
|
|
||||||
expect(noFraction(0.00302000)).to.equal(0.00302);
|
|
||||||
expect(noFraction(1.00000001)).to.equal(1.00000001);
|
|
||||||
expect(noFraction(3.10000012)).to.equal(3.10000012);
|
|
||||||
expect(noFraction(0.00100000)).to.equal(0.001);
|
|
||||||
expect(noFraction(0.00100009)).to.equal(0.00100009);
|
|
||||||
expect(noFraction(2000.00312011)).to.equal('2,000.00312011');
|
|
||||||
expect(noFraction(2000998.00312011)).to.equal('2,000,998.00312011');
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('noFractionNumber mBTC', function() {
|
describe('noFractionNumber mBTC', function() {
|
||||||
beforeEach(function() {
|
beforeEach(inject(function($rootScope) {
|
||||||
config.unitToSatoshi = 100000;
|
$rootScope.wallet = new FakeWallet(walletConfig);
|
||||||
config.unitName = 'mBTC';
|
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);
|
||||||
|
expect(noFraction(0.00302)).to.equal(0.00302);
|
||||||
|
expect(noFraction(1.00001)).to.equal(1.00001);
|
||||||
|
expect(noFraction(3.10002)).to.equal(3.10002);
|
||||||
|
expect(noFraction(0.00100000)).to.equal(0.001);
|
||||||
|
expect(noFraction(0.00100009)).to.equal(0.001);
|
||||||
|
expect(noFraction(2000.00312)).to.equal('2,000.00312');
|
||||||
|
expect(noFraction(2000998.00312)).to.equal('2,000,998.00312');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
it('should format number to display correctly', inject(function($filter) {
|
|
||||||
var noFraction = $filter('noFractionNumber');
|
|
||||||
expect(noFraction(0.30000)).to.equal(0.3);
|
|
||||||
expect(noFraction(0.00302)).to.equal(0.00302);
|
|
||||||
expect(noFraction(1.00001)).to.equal(1.00001);
|
|
||||||
expect(noFraction(3.10002)).to.equal(3.10002);
|
|
||||||
expect(noFraction(0.00100000)).to.equal(0.001);
|
|
||||||
expect(noFraction(0.00100009)).to.equal(0.001);
|
|
||||||
expect(noFraction(2000.00312)).to.equal('2,000.00312');
|
|
||||||
expect(noFraction(2000998.00312)).to.equal('2,000,998.00312');
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('noFractionNumber:custom fractionSize', function() {
|
describe('noFractionNumber:custom fractionSize', function() {
|
||||||
it('should format number to display correctly', inject(function($filter) {
|
it('should format number to display correctly', inject(function($filter) {
|
||||||
var noFraction = $filter('noFractionNumber');
|
var noFraction = $filter('noFractionNumber');
|
||||||
expect(noFraction(0.30000, 0)).to.equal('0');
|
expect(noFraction(0.30000, 0)).to.equal('0');
|
||||||
expect(noFraction(1.00001, 0)).to.equal('1');
|
expect(noFraction(1.00001, 0)).to.equal('1');
|
||||||
expect(noFraction(3.10002, 0)).to.equal('3');
|
expect(noFraction(3.10002, 0)).to.equal('3');
|
||||||
expect(noFraction(2000.00312, 0)).to.equal('2,000');
|
expect(noFraction(2000.00312, 0)).to.equal('2,000');
|
||||||
expect(noFraction(2000998.00312, 0)).to.equal('2,000,998');
|
expect(noFraction(2000998.00312, 0)).to.equal('2,000,998');
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,9 @@ var getCommitHash = function() {
|
||||||
//exec git command to get the hash of the current commit
|
//exec git command to get the hash of the current commit
|
||||||
//git rev-parse HEAD
|
//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;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,7 +25,7 @@ var createVersion = function() {
|
||||||
var json = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
var json = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
|
||||||
var content = 'module.exports.version="' + json.version + '";';
|
var content = 'module.exports.version="' + json.version + '";';
|
||||||
|
|
||||||
content = content + '\nmodule.exports.commitHash="' + getCommitHash() + '";';
|
content = content + '\nmodule.exports.commitHash="' + getCommitHash() + '";';
|
||||||
fs.writeFileSync("./version.js", content);
|
fs.writeFileSync("./version.js", content);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -43,9 +45,9 @@ var createBundle = function(opts) {
|
||||||
b.require('browser-request', {
|
b.require('browser-request', {
|
||||||
expose: 'request'
|
expose: 'request'
|
||||||
});
|
});
|
||||||
b.require('underscore', {
|
b.require('underscore');
|
||||||
expose: 'underscore'
|
b.require('assert');
|
||||||
});
|
b.require('preconditions');
|
||||||
|
|
||||||
b.require('./copay', {
|
b.require('./copay', {
|
||||||
expose: 'copay'
|
expose: 'copay'
|
||||||
|
|
@ -130,10 +132,10 @@ if (require.main === module) {
|
||||||
};
|
};
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
program
|
program
|
||||||
.version('0.0.1')
|
.version('0.0.1')
|
||||||
.option('-d, --debug', 'Development. Don\'t minify the codem and include debug packages.')
|
.option('-d, --debug', 'Development. Don\'t minify the codem and include debug packages.')
|
||||||
.option('-o, --stdout', 'Specify output as stdout')
|
.option('-o, --stdout', 'Specify output as stdout')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
createVersion();
|
createVersion();
|
||||||
var copayBundle = createBundle(program);
|
var copayBundle = createBundle(program);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue