diff --git a/js/services/rate.js b/js/services/rate.js index 9b7e1980e..764e5c914 100644 --- a/js/services/rate.js +++ b/js/services/rate.js @@ -29,7 +29,7 @@ var RateService = function(request) { that.isAvailable = true; that.rates = rates; that.queued.forEach(function(callback) { - setTimeout(callback, 0); + setTimeout(callback, 1); }); }); }; @@ -38,7 +38,7 @@ var RateService = function(request) { RateService.prototype.whenAvailable = function(callback) { if (this.isAvailable) { - setTimeout(callback, 0); + setTimeout(callback, 1); } else { this.queued.push(callback); } diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index c056246c8..aeb7a5006 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -29,7 +29,9 @@ describe("Unit: Controllers", function() { totalCopayers: 5, spendUnconfirmed: 1, reconnectDelay: 100, - networkName: 'testnet' + networkName: 'testnet', + alternativeName: 'lol currency', + alternativeIsoCode: 'LOL' }; it('Copay config should be binded', function() { @@ -124,11 +126,20 @@ describe("Unit: Controllers", function() { }); describe('Send Controller', function() { - var scope, form, sendForm; + var scope, form, sendForm, sendCtrl; beforeEach(angular.mock.module('copayApp')); + beforeEach(module(function($provide) { + $provide.value('request', { + 'get': function(_, cb) { + cb(null, null, [{name: 'lol currency', code: 'LOL', rate: 2}]); + } + }); + })); beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) { scope = $rootScope.$new(); $rootScope.wallet = new FakeWallet(walletConfig); + config.alternativeName = 'lol currency'; + config.alternativeIsoCode = 'LOL'; var element = angular.element( '
' ); $compile(element2)(scope); - $controller('SendController', { + sendCtrl = $controller('SendController', { $scope: scope, $modal: {}, }); @@ -241,8 +253,22 @@ describe("Unit: Controllers", function() { config.unitToSatoshi = old; }); - - + it('should convert bits amount to fiat', function(done) { + sendCtrl.rateService.whenAvailable(function() { + sendForm.amount.$setViewValue(1e6); + scope.$digest(); + expect(scope.alternative).to.equal(2); + done(); + }); + }); + it('should convert fiat to bits amount', function(done) { + sendCtrl.rateService.whenAvailable(function() { + sendForm.alternative.$setViewValue(2); + scope.$digest(); + expect(scope.amount).to.equal(1e6); + done(); + }); + }); it('should create and send a transaction proposal', function() { sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); diff --git a/test/unit/services/servicesSpec.js b/test/unit/services/servicesSpec.js index 3552f725d..144e9488b 100644 --- a/test/unit/services/servicesSpec.js +++ b/test/unit/services/servicesSpec.js @@ -144,11 +144,24 @@ describe('Unit: Rate Service', function() { should.exist(rateService.isAvailable); }) ); - it('should be possible to ask for conversion', + beforeEach(module(function($provide) { + $provide.value('request', { + 'get': function(_, cb) { + cb(null, null, [{name: 'lol currency', code: 'LOL', rate: 2}]); + } + }); + })); + it('should be possible to ask for conversion from fiat', inject(function(rateService) { rateService.whenAvailable(function() { - rateService.rates['LOL'] = 2; - (1 * 1e8).should.equal(rateService.fromFiat(2, 'LOL')); + (1).should.equal(rateService.fromFiat(2, 'LOL')); + }); + }) + ); + it('should be possible to ask for conversion to fiat', + inject(function(rateService) { + rateService.whenAvailable(function() { + (2).should.equal(rateService.toFiat(1e8, 'LOL')); }); }) );