Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
63384392
Commit
63384392
authored
Aug 15, 2014
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the form validation tests
parent
63a4ab59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
42 deletions
+28
-42
auth-test.coffee
tests/js/auth-test.coffee
+0
-9
directives-test.coffee
tests/js/directives-test.coffee
+28
-33
No files found.
tests/js/auth-test.coffee
View file @
63384392
...
...
@@ -131,15 +131,6 @@ describe 'h.auth', ->
assert
.
isTrue
$scope
.
login
.
$valid
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'
,
->
$rootScope
.
stub
=
sandbox
.
stub
()
for
event
in
[
'error'
,
'success'
,
'timeout'
]
...
...
tests/js/directives-test.coffee
View file @
63384392
...
...
@@ -34,34 +34,30 @@ describe 'h.directives', ->
$element
=
null
beforeEach
->
$scope
.
model
=
{
username
:
''
}
$scope
.
model
=
{
username
:
undefined
}
template
=
'''
<form form-validate name="login" onsubmit="return false">
<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>
</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
)
$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'
,
->
$field
=
$element
.
find
(
'.form-field'
).
addClass
(
'form-field-error'
)
$input
=
$element
.
find
(
'[name=username]'
)
$input
.
val
(
'abc'
).
trigger
(
'input'
).
change
()
$input
=
$element
.
find
(
'[name=username]'
).
addClass
(
'form-field-error'
)
$input
.
controller
(
'ngModel'
).
$setViewValue
(
'abc'
)
$scope
.
$digest
()
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'
,
->
$field
=
$element
.
find
(
'.form-field'
)
...
...
@@ -112,29 +108,28 @@ describe 'h.directives', ->
assert
.
include
(
$field
.
prop
(
'className'
),
'form-field-error'
,
'Fail fast check'
)
controller
.
$setViewValue
(
'abc'
)
$scope
.
$digest
()
assert
.
notInclude
(
$field
.
prop
(
'className'
),
'form-field-error'
)
# TODO: I can't get this test to pass, it should create a dirty form
# state and then reset it. However the scope watch handler for the form
# $prisine change doesn't fire when $setPrisine is called. I've tried
# $scope.$digest and other tricks. The form and input all have their
# internal $pristine values updated correctly.
it
'should hide errors if the field is pristine'
# it 'should hide errors if the field is pristine', ->
# $field = $element.find('.form-field').addClass('form-field-error')
# $input = $element.find('[name=username]')
#
# formController = $input.controller('form')
# modelController = formController.username
# $input.val('a').trigger('input')
#
# # Clear out the model and set to $pristine
# $scope.model = {}
# $scope.login = formController
# formController.$setPristine() # Not triggering $pristine watch event.
#
# assert.notInclude($field.prop('className'), 'form-field-error')
it
'should hide errors if the model is marked as pristine'
,
->
$field
=
$element
.
find
(
'.form-field'
).
addClass
(
'form-field-error'
)
$input
=
$element
.
find
(
'[name=username]'
)
controller
=
$input
.
controller
(
'ngModel'
)
# Submit Event
$element
.
triggerHandler
(
'submit'
)
controller
.
$setValidity
(
'response'
,
false
)
controller
.
responseErrorMessage
=
'fail'
$scope
.
$digest
()
assert
.
include
(
$field
.
prop
(
'className'
),
'form-field-error'
,
'Fail fast check'
)
# Then clear it out and mark it as pristine
controller
.
$setPristine
()
$scope
.
$digest
()
assert
.
notInclude
(
$field
.
prop
(
'className'
),
'form-field-error'
)
describe
'.username'
,
->
$element
=
null
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment