Commit 63384392 authored by Randall Leeds's avatar Randall Leeds

Fix the form validation tests

parent 63a4ab59
...@@ -131,15 +131,6 @@ describe 'h.auth', -> ...@@ -131,15 +131,6 @@ describe 'h.auth', ->
assert.isTrue $scope.login.$valid assert.isTrue $scope.login.$valid
assert.isUndefined $scope.login.responseErrorMessage assert.isUndefined $scope.login.responseErrorMessage
it 'should reset to pristine state when the model is reset', ->
$rootScope.form.$setDirty()
$rootScope.$digest()
assert.isFalse $rootScope.form.$pristine
$scope.model = null
$scope.$digest()
assert.isTrue $rootScope.form.$pristine
it 'should invoke handlers set by attributes', -> it 'should invoke handlers set by attributes', ->
$rootScope.stub = sandbox.stub() $rootScope.stub = sandbox.stub()
for event in ['error', 'success', 'timeout'] for event in ['error', 'success', 'timeout']
......
...@@ -34,34 +34,30 @@ describe 'h.directives', -> ...@@ -34,34 +34,30 @@ describe 'h.directives', ->
$element = null $element = null
beforeEach -> beforeEach ->
$scope.model = {username: ''} $scope.model = {username: undefined}
template = ''' template = '''
<form form-validate name="login" onsubmit="return false"> <form form-validate name="login" onsubmit="return false">
<div class="form-field"> <div class="form-field">
<input type="text" class="" ng-model="model.username" name="username" required ng-minlength="3" /> <input type="text" class="form-input" name="username"
ng-model="model.username" name="username"
required ng-minlength="3" />
</div> </div>
</form> </form>
''' '''
# Needs to be passed through angular.element() to work. Otherwise it
# will not link the form-validate directive.
$element = $compile(angular.element(template))($scope) $element = $compile(angular.element(template))($scope)
$scope.$digest() $scope.$digest()
it 'should apply an error class to an invalid field on change', ->
$field = $element.find('.form-field')
$input = $element.find('[name=username]')
$input.val('ab').change()
assert.include($field.prop('className'), 'form-field-error')
it 'should remove an error class to an valid field on change', -> it 'should remove an error class to an valid field on change', ->
$field = $element.find('.form-field').addClass('form-field-error') $field = $element.find('.form-field').addClass('form-field-error')
$input = $element.find('[name=username]') $input = $element.find('[name=username]').addClass('form-field-error')
$input.val('abc').trigger('input').change()
$input.controller('ngModel').$setViewValue('abc')
$scope.$digest()
assert.notInclude($field.prop('className'), 'form-field-error') assert.notInclude($field.prop('className'), 'form-field-error')
assert.notInclude($input.prop('className'), 'form-field-error')
it 'should apply an error class to an invalid field on submit', -> it 'should apply an error class to an invalid field on submit', ->
$field = $element.find('.form-field') $field = $element.find('.form-field')
...@@ -112,29 +108,28 @@ describe 'h.directives', -> ...@@ -112,29 +108,28 @@ describe 'h.directives', ->
assert.include($field.prop('className'), 'form-field-error', 'Fail fast check') assert.include($field.prop('className'), 'form-field-error', 'Fail fast check')
controller.$setViewValue('abc') controller.$setViewValue('abc')
$scope.$digest()
assert.notInclude($field.prop('className'), 'form-field-error') assert.notInclude($field.prop('className'), 'form-field-error')
# TODO: I can't get this test to pass, it should create a dirty form it 'should hide errors if the model is marked as pristine', ->
# state and then reset it. However the scope watch handler for the form $field = $element.find('.form-field').addClass('form-field-error')
# $prisine change doesn't fire when $setPrisine is called. I've tried $input = $element.find('[name=username]')
# $scope.$digest and other tricks. The form and input all have their controller = $input.controller('ngModel')
# internal $pristine values updated correctly.
it 'should hide errors if the field is pristine' # Submit Event
# it 'should hide errors if the field is pristine', -> $element.triggerHandler('submit')
# $field = $element.find('.form-field').addClass('form-field-error') controller.$setValidity('response', false)
# $input = $element.find('[name=username]') controller.responseErrorMessage = 'fail'
# $scope.$digest()
# formController = $input.controller('form')
# modelController = formController.username assert.include($field.prop('className'), 'form-field-error', 'Fail fast check')
# $input.val('a').trigger('input')
# # Then clear it out and mark it as pristine
# # Clear out the model and set to $pristine controller.$setPristine()
# $scope.model = {} $scope.$digest()
# $scope.login = formController
# formController.$setPristine() # Not triggering $pristine watch event. assert.notInclude($field.prop('className'), 'form-field-error')
#
# assert.notInclude($field.prop('className'), 'form-field-error')
describe '.username', -> describe '.username', ->
$element = null $element = null
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment