2014-04-24 08:01:06 -07:00
|
|
|
'use strict';
|
2014-04-23 09:21:33 -07:00
|
|
|
//
|
|
|
|
// test/unit/directives/directivesSpec.js
|
|
|
|
//
|
|
|
|
describe("Unit: Testing Directives", function() {
|
|
|
|
|
2014-04-24 08:01:06 -07:00
|
|
|
var $scope, form;
|
|
|
|
|
2014-06-03 13:42:36 -07:00
|
|
|
beforeEach(module('copayApp.directives'));
|
2014-04-24 08:01:06 -07:00
|
|
|
|
|
|
|
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;
|
2014-06-12 07:12:59 -07:00
|
|
|
$rootScope.availableBalance = 0.101;
|
2014-04-24 08:01:06 -07:00
|
|
|
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;
|
|
|
|
}));
|
|
|
|
|
2014-06-12 07:12:59 -07:00
|
|
|
it('should validate', function() {
|
|
|
|
form.amount.$setViewValue(0.1);
|
|
|
|
expect(form.amount.$invalid).to.equal(false);
|
|
|
|
form.amount.$setViewValue(0.1009);
|
2014-04-24 08:01:06 -07:00
|
|
|
expect(form.amount.$invalid).to.equal(false);
|
|
|
|
});
|
2014-06-12 07:12:59 -07:00
|
|
|
it('should not validate', function() {
|
2014-04-24 08:01:06 -07:00
|
|
|
form.amount.$setViewValue(0);
|
|
|
|
expect(form.amount.$invalid).to.equal(true);
|
2014-06-12 07:12:59 -07:00
|
|
|
form.amount.$setViewValue(9999999999);
|
2014-04-24 08:01:06 -07:00
|
|
|
expect(form.amount.$invalid).to.equal(true);
|
|
|
|
form.amount.$setViewValue(2.1);
|
|
|
|
expect(form.amount.$invalid).to.equal(true);
|
2014-06-12 07:12:59 -07:00
|
|
|
form.amount.$setViewValue(0.10091);
|
|
|
|
expect(form.amount.$invalid).to.equal(true);
|
2014-04-24 08:01:06 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-11 11:39:56 -07:00
|
|
|
describe('Password strength', function() {
|
|
|
|
beforeEach(inject(function($compile, $rootScope) {
|
|
|
|
$scope = $rootScope;
|
|
|
|
var element = angular.element(
|
|
|
|
'<input type="password" name="password" ng-model="password" check-strength="passwordStrength" value="asd" required>'
|
|
|
|
);
|
|
|
|
$compile(element)($scope);
|
|
|
|
$scope.$digest();
|
|
|
|
}));
|
|
|
|
|
|
|
|
it('should check very weak password', function() {
|
|
|
|
$scope.password = 'asd';
|
|
|
|
$scope.$digest();
|
|
|
|
expect($scope.passwordStrength).to.equal('very weak');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should check weak password', function() {
|
|
|
|
$scope.password = 'asdasdASDASD';
|
|
|
|
$scope.$digest();
|
|
|
|
expect($scope.passwordStrength).to.equal('weak');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should check medium password', function() {
|
|
|
|
$scope.password = 'asdasdASDASD1';
|
|
|
|
$scope.$digest();
|
|
|
|
expect($scope.passwordStrength).to.equal('medium');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should check strong password', function() {
|
|
|
|
$scope.password = 'asdasdASDASD1{';
|
|
|
|
$scope.$digest();
|
|
|
|
expect($scope.passwordStrength).to.equal('strong');
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
2014-04-23 09:21:33 -07:00
|
|
|
});
|