test for new angular directive: match password inputs

This commit is contained in:
Gustavo Maximiliano Cortez 2014-07-18 18:17:45 -03:00
parent b51e8b3539
commit b17bc2310d
2 changed files with 38 additions and 5 deletions

View File

@ -244,11 +244,11 @@ angular.module('copayApp.directives')
match: '='
},
link: function(scope, elem, attrs, ctrl) {
scope.$watch(function() {
return (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || scope.match === ctrl.$modelValue;
}, function(currentValue) {
ctrl.$setValidity('match', currentValue);
});
scope.$watch(function() {
return (ctrl.$pristine && angular.isUndefined(ctrl.$modelValue)) || scope.match === ctrl.$modelValue;
}, function(currentValue) {
ctrl.$setValidity('match', currentValue);
});
}
};
})

View File

@ -202,4 +202,37 @@ describe("Unit: Testing Directives", function() {
});
});
describe('Match Password Inputs', function() {
beforeEach(inject(function($compile, $rootScope) {
$scope = $rootScope;
$rootScope.availableBalance = 1000;
var element = angular.element(
'<form name="form">' +
'<input type="password" ng-model="walletPassword" name="walletPassword" required>' +
'<input type="password" ng-model="walletPasswordConfirm" name="walletPasswordConfirm" match="walletPassword" required>' +
'</form>'
);
$scope.model = {
walletPassword: null,
walletPasswordConfirm: null
};
$compile(element)($scope);
$scope.$digest();
form = $scope.form;
}));
it('should not validate', function() {
form.walletPassword.$setViewValue('mysecretpassword');
form.walletPasswordConfirm.$setViewValue('mySecretPassword');
$scope.$digest();
expect(form.walletPasswordConfirm.$invalid).to.equal(true);
});
it('should validate', function() {
form.walletPassword.$setViewValue('mysecretpassword123');
form.walletPasswordConfirm.$setViewValue('mysecretpassword123');
$scope.$digest();
expect(form.walletPasswordConfirm.$invalid).to.equal(false);
});
});
});