From b17bc2310d8ff95af4fd6b7ad0ccfb37a2a4f829 Mon Sep 17 00:00:00 2001 From: Gustavo Maximiliano Cortez Date: Fri, 18 Jul 2014 18:17:45 -0300 Subject: [PATCH] test for new angular directive: match password inputs --- js/directives.js | 10 ++++---- test/unit/directives/directivesSpec.js | 33 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/js/directives.js b/js/directives.js index 72cd843ce..48457bf2f 100644 --- a/js/directives.js +++ b/js/directives.js @@ -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); + }); } }; }) diff --git a/test/unit/directives/directivesSpec.js b/test/unit/directives/directivesSpec.js index dbca2ce8e..a3fd59a24 100644 --- a/test/unit/directives/directivesSpec.js +++ b/test/unit/directives/directivesSpec.js @@ -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( + '
' + + '' + + '' + + '
' + ); + $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); + }); + }); + });