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
17545f5e
Commit
17545f5e
authored
Aug 05, 2014
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update formValidate to use $setViewValue
This seems to be the correct way to interact with Angular views.
parent
3f8d0c87
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
25 deletions
+29
-25
directives-test.coffee
tests/js/directives-test.coffee
+29
-25
No files found.
tests/js/directives-test.coffee
View file @
17545f5e
...
...
@@ -48,28 +48,36 @@ describe 'h.directives', ->
it
'should apply an error class to an invalid field on change'
,
->
$field
=
$element
.
find
(
'.form-field'
)
$element
.
find
(
'[name=username]'
).
val
(
'ab'
).
change
()
assert
.
include
$field
.
prop
(
'className'
),
'form-field-error'
$input
=
$element
.
find
(
'[name=username]'
)
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'
,
->
$field
=
$element
.
find
(
'.form-field'
).
addClass
(
'form-field-error'
)
$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'
,
->
$field
=
$element
.
find
(
'.form-field'
)
$element
.
trigger
(
'submit'
)
assert
.
include
$field
.
prop
(
'className'
),
'form-field-error'
$element
.
trigger
Handler
(
'submit'
)
assert
.
include
(
$field
.
prop
(
'className'
),
'form-field-error'
)
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'
)
controller
=
$element
.
find
(
'[name=username]'
).
controller
(
'ngModel'
)
controller
.
$setViewValue
(
'abc'
)
$element
.
trigger
(
'submit'
)
assert
.
notInclude
$field
.
prop
(
'className'
),
'form-field-error'
$element
.
trigger
Handler
(
'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'
)
...
...
@@ -78,23 +86,19 @@ describe 'h.directives', ->
$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
()
it
'should remove an error class on valid input when the view changes'
,
->
$field
=
$element
.
find
(
'.form-field'
).
addClass
(
'form-field-error'
)
$element
.
find
(
'[name=username]'
).
keyup
()
assert
.
notInclude
$field
.
prop
(
'className'
),
'form-field-error'
controller
=
$element
.
find
(
'[name=username]'
).
controller
(
'ngModel'
)
controller
.
$setViewValue
(
'abc'
)
it
'should not add an error class on invalid input on keyup'
,
->
$scope
.
model
.
username
=
''
$scope
.
$digest
()
assert
.
notInclude
(
$field
.
prop
(
'className'
),
'form-field-error'
)
it
'should not add an error class on invalid input on when the view changes'
,
->
$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'
,
->
...
...
@@ -116,7 +120,7 @@ describe 'h.directives', ->
it
'prevents the default browser action on click'
,
->
event
=
jQuery
.
Event
(
'click'
)
$element
.
find
(
'.user'
).
trigger
(
event
)
$element
.
find
(
'.user'
).
trigger
Handler
(
event
)
assert
(
event
.
isDefaultPrevented
())
...
...
@@ -158,7 +162,7 @@ describe 'h.directives', ->
it
'calls the given search function'
,
->
$scope
.
query
=
"Test query"
$scope
.
$digest
()
$element
.
trigger
(
'submit'
)
$element
.
trigger
Handler
(
'submit'
)
sinon
.
assert
.
calledWith
(
$scope
.
update
,
"Test query"
)
it
'calls the given clear function'
,
->
...
...
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