mirror of https://github.com/BTCPrivate/copay.git
Testing directives for AngularJS
This commit is contained in:
parent
e69032e951
commit
9b56d425aa
|
@ -13,7 +13,8 @@ var copay = window.copay = angular.module('copay',[
|
||||||
'copay.signin',
|
'copay.signin',
|
||||||
'copay.socket',
|
'copay.socket',
|
||||||
'copay.controllerUtils',
|
'copay.controllerUtils',
|
||||||
'copay.setup'
|
'copay.setup',
|
||||||
|
'copay.directives'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
angular.module('copay.header', []);
|
angular.module('copay.header', []);
|
||||||
|
@ -26,4 +27,5 @@ angular.module('copay.controllerUtils', []);
|
||||||
angular.module('copay.signin', []);
|
angular.module('copay.signin', []);
|
||||||
angular.module('copay.setup', []);
|
angular.module('copay.setup', []);
|
||||||
angular.module('copay.socket', []);
|
angular.module('copay.socket', []);
|
||||||
|
angular.module('copay.directives', []);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copay')
|
angular.module('copay.directives')
|
||||||
.directive('validAddress', [function() {
|
.directive('validAddress', [function() {
|
||||||
|
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
|
|
|
@ -1,6 +1,66 @@
|
||||||
|
'use strict';
|
||||||
//
|
//
|
||||||
// test/unit/directives/directivesSpec.js
|
// test/unit/directives/directivesSpec.js
|
||||||
//
|
//
|
||||||
describe("Unit: Testing Directives", function() {
|
describe("Unit: Testing Directives", function() {
|
||||||
|
|
||||||
|
var $scope, form;
|
||||||
|
|
||||||
|
beforeEach(module('copay.directives'));
|
||||||
|
|
||||||
|
describe('Validate Address', function() {
|
||||||
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
|
$scope = $rootScope;
|
||||||
|
var element = angular.element(
|
||||||
|
'<form name="form">' +
|
||||||
|
'<input type="text" id="address" name="address" placeholder="Send to" ng-model="address" valid-address required>' +
|
||||||
|
'</form>'
|
||||||
|
);
|
||||||
|
$scope.model = { address: null };
|
||||||
|
$compile(element)($scope);
|
||||||
|
$scope.$digest();
|
||||||
|
form = $scope.form;
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should validate', function() {
|
||||||
|
form.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
|
||||||
|
expect(form.address.$invalid).to.equal(false);
|
||||||
|
});
|
||||||
|
it('should not validate', function() {
|
||||||
|
form.address.$setViewValue('thisisaninvalidaddress');
|
||||||
|
expect(form.address.$invalid).to.equal(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Validate Amount', function() {
|
||||||
|
beforeEach(inject(function($compile, $rootScope) {
|
||||||
|
$scope = $rootScope;
|
||||||
|
$rootScope.availableBalance = 2;
|
||||||
|
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 between min and max value', function() {
|
||||||
|
form.amount.$setViewValue(1.2);
|
||||||
|
expect(form.amount.$invalid).to.equal(false);
|
||||||
|
});
|
||||||
|
it('should not validate between min and max value', function() {
|
||||||
|
form.amount.$setViewValue(0);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
form.amount.$setViewValue(9999999999999);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
});
|
||||||
|
it('should not validate because not enough amount', function() {
|
||||||
|
form.amount.$setViewValue(2.1);
|
||||||
|
expect(form.amount.$invalid).to.equal(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue