Add more tests to controller
This commit is contained in:
parent
cf143898f9
commit
ac6dfc8035
3 changed files with 49 additions and 10 deletions
|
|
@ -29,7 +29,7 @@ var RateService = function(request) {
|
||||||
that.isAvailable = true;
|
that.isAvailable = true;
|
||||||
that.rates = rates;
|
that.rates = rates;
|
||||||
that.queued.forEach(function(callback) {
|
that.queued.forEach(function(callback) {
|
||||||
setTimeout(callback, 0);
|
setTimeout(callback, 1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
@ -38,7 +38,7 @@ var RateService = function(request) {
|
||||||
|
|
||||||
RateService.prototype.whenAvailable = function(callback) {
|
RateService.prototype.whenAvailable = function(callback) {
|
||||||
if (this.isAvailable) {
|
if (this.isAvailable) {
|
||||||
setTimeout(callback, 0);
|
setTimeout(callback, 1);
|
||||||
} else {
|
} else {
|
||||||
this.queued.push(callback);
|
this.queued.push(callback);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,9 @@ describe("Unit: Controllers", function() {
|
||||||
totalCopayers: 5,
|
totalCopayers: 5,
|
||||||
spendUnconfirmed: 1,
|
spendUnconfirmed: 1,
|
||||||
reconnectDelay: 100,
|
reconnectDelay: 100,
|
||||||
networkName: 'testnet'
|
networkName: 'testnet',
|
||||||
|
alternativeName: 'lol currency',
|
||||||
|
alternativeIsoCode: 'LOL'
|
||||||
};
|
};
|
||||||
|
|
||||||
it('Copay config should be binded', function() {
|
it('Copay config should be binded', function() {
|
||||||
|
|
@ -124,11 +126,20 @@ describe("Unit: Controllers", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Send Controller', function() {
|
describe('Send Controller', function() {
|
||||||
var scope, form, sendForm;
|
var scope, form, sendForm, sendCtrl;
|
||||||
beforeEach(angular.mock.module('copayApp'));
|
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) {
|
beforeEach(angular.mock.inject(function($compile, $rootScope, $controller) {
|
||||||
scope = $rootScope.$new();
|
scope = $rootScope.$new();
|
||||||
$rootScope.wallet = new FakeWallet(walletConfig);
|
$rootScope.wallet = new FakeWallet(walletConfig);
|
||||||
|
config.alternativeName = 'lol currency';
|
||||||
|
config.alternativeIsoCode = 'LOL';
|
||||||
var element = angular.element(
|
var element = angular.element(
|
||||||
'<form name="form">' +
|
'<form name="form">' +
|
||||||
'<input type="text" id="newaddress" name="newaddress" ng-disabled="loading" placeholder="Address" ng-model="newaddress" valid-address required>' +
|
'<input type="text" id="newaddress" name="newaddress" ng-disabled="loading" placeholder="Address" ng-model="newaddress" valid-address required>' +
|
||||||
|
|
@ -147,11 +158,12 @@ describe("Unit: Controllers", function() {
|
||||||
'<form name="form2">' +
|
'<form name="form2">' +
|
||||||
'<input type="text" id="address" name="address" ng-model="address" valid-address required>' +
|
'<input type="text" id="address" name="address" ng-model="address" valid-address required>' +
|
||||||
'<input type="number" id="amount" name="amount" ng-model="amount" min="1" max="10000000000" required>' +
|
'<input type="number" id="amount" name="amount" ng-model="amount" min="1" max="10000000000" required>' +
|
||||||
|
'<input type="number" id="alternative" name="alternative" ng-model="alternative">' +
|
||||||
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
'<textarea id="comment" name="comment" ng-model="commentText" ng-maxlength="100"></textarea>' +
|
||||||
'</form>'
|
'</form>'
|
||||||
);
|
);
|
||||||
$compile(element2)(scope);
|
$compile(element2)(scope);
|
||||||
$controller('SendController', {
|
sendCtrl = $controller('SendController', {
|
||||||
$scope: scope,
|
$scope: scope,
|
||||||
$modal: {},
|
$modal: {},
|
||||||
});
|
});
|
||||||
|
|
@ -241,8 +253,22 @@ describe("Unit: Controllers", function() {
|
||||||
config.unitToSatoshi = old;
|
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() {
|
it('should create and send a transaction proposal', function() {
|
||||||
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||||
|
|
|
||||||
|
|
@ -144,11 +144,24 @@ describe('Unit: Rate Service', function() {
|
||||||
should.exist(rateService.isAvailable);
|
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) {
|
inject(function(rateService) {
|
||||||
rateService.whenAvailable(function() {
|
rateService.whenAvailable(function() {
|
||||||
rateService.rates['LOL'] = 2;
|
(1).should.equal(rateService.fromFiat(2, 'LOL'));
|
||||||
(1 * 1e8).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'));
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue