Fixed amount values: decimal is variable, depending of unit in config. Also custom values are allowed

This commit is contained in:
Gustavo Cortez 2014-06-27 02:46:28 -03:00
commit 75b45d2f17
4 changed files with 97 additions and 28 deletions

View file

@ -69,14 +69,67 @@ describe('Unit: Testing Filters', function() {
}));
});
describe('noFractionNumber', function() {
describe('noFractionNumber bits', function() {
beforeEach(function() {
config.unitToSatoshi = 100;
config.unitName = 'bits';
});
it('should format number to display correctly', inject(function($filter) {
var noFraction = $filter('noFractionNumber');
var fraction = 4;
expect(noFraction(3100, fraction)).to.equal('3,100');
expect(noFraction(3100200, fraction)).to.equal('3,100,200');
expect(noFraction(3, fraction)).to.equal('3');
expect(noFraction(0.3, fraction)).to.equal(0.3);
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() {
beforeEach(function() {
config.unitToSatoshi = 100000000;
config.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');
}));
});
describe('noFractionNumber mBTC', function() {
beforeEach(function() {
config.unitToSatoshi = 100000;
config.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');
}));
});
describe('noFractionNumber:custom fractionSize', function() {
it('should format number to display correctly', inject(function($filter) {
var noFraction = $filter('noFractionNumber');
expect(noFraction(0.30000, 0)).to.equal('0');
expect(noFraction(1.00001, 0)).to.equal('1');
expect(noFraction(3.10002, 0)).to.equal('3');
expect(noFraction(2000.00312, 0)).to.equal('2,000');
expect(noFraction(2000998.00312, 0)).to.equal('2,000,998');
}));
});