View
@@ -38,7 +38,7 @@ describe 'h.directives', ->
template = '''
<form form-validate data-form-validate-error-class="form-field-error" name="login" onsubmit="return false">
<div class="form-field" data-error-class="form-field-error" data-target="username">
<div class="form-field" data-error-class="form-field-error">
<input type="text" class="" ng-model="model.username" name="username" required ng-minlength="3" />
</div>
</form>
@@ -74,32 +74,27 @@ describe 'h.directives', ->
$element.trigger('submit')
assert.notInclude $field.prop('className'), 'form-field-error'
it 'should apply an error class to an invalid field on "error" event', ->
$scope.$emit('error', 'login')
it 'should apply an error class if the form recieves errors after a submit action', ->
$element.trigger('submit')
$element.controller('form').username.$setValidity('response', false)
$field = $element.find('.form-field')
assert.include $field.prop('className'), 'form-field-error'
it 'should remove an error class on valid input on keyup', ->
$scope.model.username = 'abc'
$scope.$digest()
$field = $element.find('.form-field').addClass('form-field-error')
$element.find('[name=username]').keyup()
$input = $element.find('[name=username]').val('abc').trigger('input')
$input.keyup()
assert.notInclude $field.prop('className'), 'form-field-error'
it 'should not add an error class on invalid input on keyup', ->
$scope.model.username = ''
$scope.$digest()
$field = $element.find('.form-field')
$element.find('[name=username]').keyup()
$input = $element.find('[name=username]').val('ab').trigger('input')
$input.keyup()
assert.notInclude $field.prop('className'), 'form-field-error'
describe '.username', ->
$element = null
@@ -136,6 +131,41 @@ describe 'h.directives', ->
$element.find('.user').click()
sinon.assert.calledWith(fakeWindow.open, '/u/jim@hypothesis')
describe '.match', ->
$element = null
beforeEach ->
$scope.model = {a: 1, b: 1}
$element = $compile('<input name="confirmation" ng-model="model.b" match="model.a" />')($scope)
$scope.$digest()
it 'is valid if both properties have the same value', ->
controller = $element.controller('ngModel')
assert.isFalse(controller.$error.match)
# TODO: Work out how to watch for changes to the model.
it 'is invalid if the local property differs'
# it 'is invalid if the local property differs', ->
# $scope.model.b = 2
# $scope.$digest()
# controller = $element.controller('ngModel')
# assert.isTrue(controller.$error.match)
it 'is invalid if the matched property differs', ->
$scope.model.a = 2
$scope.$digest()
controller = $element.controller('ngModel')
assert.isTrue(controller.$error.match)
it 'is invalid if the input itself is changed', ->
$element.val('2').trigger('input').keyup()
controller = $element.controller('ngModel')
assert.isTrue(controller.$error.match)
describe '.userPicker', ->
$element = null