Commit 17545f5e authored by Aron Carroll's avatar Aron Carroll

Update formValidate to use $setViewValue

This seems to be the correct way to interact with Angular views.
parent 3f8d0c87
...@@ -48,28 +48,36 @@ describe 'h.directives', -> ...@@ -48,28 +48,36 @@ describe 'h.directives', ->
it 'should apply an error class to an invalid field on change', -> it 'should apply an error class to an invalid field on change', ->
$field = $element.find('.form-field') $field = $element.find('.form-field')
$element.find('[name=username]').val('ab').change() $input = $element.find('[name=username]')
assert.include $field.prop('className'), 'form-field-error'
controller = $input.controller('ngModel')
controller.$setViewValue('ab')
$input.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]')
$input.val('abc').change()
assert.notInclude $field.prop('className'), 'form-field-error' controller = $input.controller('ngModel')
controller.$setViewValue('abc')
$input.triggerHandler('change')
assert.notInclude($field.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')
$element.trigger('submit') $element.triggerHandler('submit')
assert.include $field.prop('className'), 'form-field-error' assert.include($field.prop('className'), 'form-field-error')
it 'should remove an error class from a valid field on submit', -> it 'should remove an error class from a valid field on submit', ->
$scope.model.username = 'abc'
$scope.$digest()
$field = $element.find('.form-field').addClass('form-field-error') $field = $element.find('.form-field').addClass('form-field-error')
controller = $element.find('[name=username]').controller('ngModel')
controller.$setViewValue('abc')
$element.trigger('submit') $element.triggerHandler('submit')
assert.notInclude $field.prop('className'), 'form-field-error' assert.notInclude($field.prop('className'), 'form-field-error')
it 'should apply an error class to an invalid field on "error" event', -> it 'should apply an error class to an invalid field on "error" event', ->
$scope.$emit('error', 'login') $scope.$emit('error', 'login')
...@@ -78,23 +86,19 @@ describe 'h.directives', -> ...@@ -78,23 +86,19 @@ describe 'h.directives', ->
$field = $element.find('.form-field') $field = $element.find('.form-field')
assert.include $field.prop('className'), 'form-field-error' assert.include $field.prop('className'), 'form-field-error'
it 'should remove an error class on valid input on keyup', -> it 'should remove an error class on valid input when the view changes', ->
$scope.model.username = 'abc'
$scope.$digest()
$field = $element.find('.form-field').addClass('form-field-error') $field = $element.find('.form-field').addClass('form-field-error')
$element.find('[name=username]').keyup() controller = $element.find('[name=username]').controller('ngModel')
controller.$setViewValue('abc')
assert.notInclude $field.prop('className'), 'form-field-error'
it 'should not add an error class on invalid input on keyup', -> assert.notInclude($field.prop('className'), 'form-field-error')
$scope.model.username = ''
$scope.$digest()
it 'should not add an error class on invalid input on when the view changes', ->
$field = $element.find('.form-field') $field = $element.find('.form-field')
$element.find('[name=username]').keyup() controller = $element.find('[name=username]').controller('ngModel')
controller.$setViewValue('ab')
assert.notInclude $field.prop('className'), 'form-field-error' assert.notInclude($field.prop('className'), 'form-field-error')
describe '.username', -> describe '.username', ->
...@@ -116,7 +120,7 @@ describe 'h.directives', -> ...@@ -116,7 +120,7 @@ describe 'h.directives', ->
it 'prevents the default browser action on click', -> it 'prevents the default browser action on click', ->
event = jQuery.Event('click') event = jQuery.Event('click')
$element.find('.user').trigger(event) $element.find('.user').triggerHandler(event)
assert(event.isDefaultPrevented()) assert(event.isDefaultPrevented())
...@@ -158,7 +162,7 @@ describe 'h.directives', -> ...@@ -158,7 +162,7 @@ describe 'h.directives', ->
it 'calls the given search function', -> it 'calls the given search function', ->
$scope.query = "Test query" $scope.query = "Test query"
$scope.$digest() $scope.$digest()
$element.trigger('submit') $element.triggerHandler('submit')
sinon.assert.calledWith($scope.update, "Test query") sinon.assert.calledWith($scope.update, "Test query")
it 'calls the given clear function', -> it 'calls the given clear function', ->
......
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