mirror of https://github.com/BTCPrivate/copay.git
More tests for amounts validation
This commit is contained in:
parent
f379ee95c0
commit
c669fc2d17
|
@ -8,6 +8,10 @@ describe("Unit: Testing Directives", function() {
|
||||||
|
|
||||||
beforeEach(module('copayApp.directives'));
|
beforeEach(module('copayApp.directives'));
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
config.unitToSatoshi = 100;
|
||||||
|
config.unitName = 'bits';
|
||||||
|
});
|
||||||
|
|
||||||
describe('Check config', function() {
|
describe('Check config', function() {
|
||||||
it('unit should be set to BITS in config.js', function() {
|
it('unit should be set to BITS in config.js', function() {
|
||||||
|
@ -43,6 +47,7 @@ describe("Unit: Testing Directives", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Validate Amount', function() {
|
describe('Validate Amount', function() {
|
||||||
|
describe('Unit: bits', function() {
|
||||||
beforeEach(inject(function($compile, $rootScope) {
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
$scope = $rootScope;
|
$scope = $rootScope;
|
||||||
$rootScope.availableBalance = 1000;
|
$rootScope.availableBalance = 1000;
|
||||||
|
@ -58,14 +63,13 @@ describe("Unit: Testing Directives", function() {
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
form = $scope.form;
|
form = $scope.form;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('should validate', function() {
|
it('should validate', function() {
|
||||||
form.amount.$setViewValue(100);
|
form.amount.$setViewValue(100);
|
||||||
expect(form.amount.$invalid).to.equal(false);
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
form.amount.$setViewValue(900);
|
form.amount.$setViewValue(800);
|
||||||
expect(form.amount.$invalid).to.equal(false);
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
|
form.amount.$setViewValue(900);
|
||||||
|
expect($scope.notEnoughAmount).to.equal(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not validate', function() {
|
it('should not validate', function() {
|
||||||
|
@ -77,9 +81,57 @@ describe("Unit: Testing Directives", function() {
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
form.amount.$setViewValue(1000);
|
form.amount.$setViewValue(1000);
|
||||||
expect(form.amount.$invalid).to.equal(true);
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
form.amount.$setViewValue(901);
|
||||||
|
expect($scope.notEnoughAmount).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Unit: BTC', function() {
|
||||||
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
|
config.unitToSatoshi = 100000000;
|
||||||
|
config.unitName = 'BTC';
|
||||||
|
$scope = $rootScope;
|
||||||
|
$rootScope.availableBalance = 0.04;
|
||||||
|
var element = angular.element(
|
||||||
|
'<form name="form">' +
|
||||||
|
'<input type="number" id="amount" name="amount" placeholder="Amount" ng-model="amount" min="0.0001" max="10000000" enough-amount required>' +
|
||||||
|
'</form>'
|
||||||
|
);
|
||||||
|
$scope.model = {
|
||||||
|
amount: null
|
||||||
|
};
|
||||||
|
$compile(element)($scope);
|
||||||
|
$scope.$digest();
|
||||||
|
form = $scope.form;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should validate', function() {
|
||||||
|
form.amount.$setViewValue(0.01);
|
||||||
|
expect($scope.notEnoughAmount).to.equal(null);
|
||||||
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
|
form.amount.$setViewValue(0.039);
|
||||||
|
expect($scope.notEnoughAmount).to.equal(null);
|
||||||
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not validate', function() {
|
||||||
|
form.amount.$setViewValue(0.03999);
|
||||||
|
expect($scope.notEnoughAmount).to.equal(true);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
form.amount.$setViewValue(0);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
form.amount.$setViewValue(0.0);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
form.amount.$setViewValue(0.05);
|
||||||
|
expect($scope.notEnoughAmount).to.equal(true);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('Contact directive', function() {
|
describe('Contact directive', function() {
|
||||||
var element1, element2;
|
var element1, element2;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,13 @@
|
||||||
//
|
//
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
config.unitToSatoshi = 100;
|
||||||
|
config.unitName = 'bits';
|
||||||
|
});
|
||||||
|
|
||||||
describe('Check config', function() {
|
describe('Check config', function() {
|
||||||
|
|
||||||
it('unit should be set to BITS in config.js', function() {
|
it('unit should be set to BITS in config.js', function() {
|
||||||
expect(config.unitToSatoshi).to.equal(100);
|
expect(config.unitToSatoshi).to.equal(100);
|
||||||
expect(config.unitName).to.equal('bits');
|
expect(config.unitName).to.equal('bits');
|
||||||
|
|
Loading…
Reference in New Issue