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
aef68c43
Commit
aef68c43
authored
Apr 03, 2015
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2127 from hypothesis/disentangle-form-helpers
Test form-input interaction with form-validate
parents
1d3904ca
eb31f2a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
14 deletions
+26
-14
form-input.coffee
h/static/scripts/directive/form-input.coffee
+6
-5
form-input-test.coffee
h/static/scripts/directive/test/form-input-test.coffee
+20
-9
No files found.
h/static/scripts/directive/form-input.coffee
View file @
aef68c43
module
.
exports
=
->
link
:
(
scope
,
elem
,
attr
,
[
form
,
model
,
validator
])
->
return
unless
form
?
.
$name
and
model
.
$name
and
validator
link
:
(
scope
,
elem
,
attr
,
[
model
,
validator
])
->
return
unless
model
fieldClassName
=
'form-field'
errorClassName
=
'form-field-error'
...
...
@@ -20,13 +20,14 @@ module.exports = ->
toggleClass
(
model
.
$invalid
and
model
.
$dirty
)
render
()
validator
.
addControl
(
model
)
scope
.
$on
'$destroy'
,
->
validator
.
removeControl
this
if
validator
?
validator
.
addControl
(
model
)
scope
.
$on
'$destroy'
,
->
validator
.
removeControl
model
scope
.
$watch
->
if
model
.
$modelValue
?
or
model
.
$pristine
toggleClass
(
model
.
$invalid
and
model
.
$dirty
)
return
require
:
[
'
^?form'
,
'
?ngModel'
,
'^?formValidate'
]
require
:
[
'?ngModel'
,
'^?formValidate'
]
restrict
:
'C'
h/static/scripts/directive/test/form-input-test.coffee
View file @
aef68c43
...
...
@@ -12,7 +12,6 @@ describe 'form-input', ->
before
->
angular
.
module
(
'h'
,
[
'ng'
])
.
directive
(
'formInput'
,
require
(
'../form-input'
))
.
directive
(
'formValidate'
,
require
(
'../form-validate'
))
beforeEach
module
(
'h'
)
beforeEach
inject
(
_$compile_
,
_$rootScope_
)
->
...
...
@@ -23,16 +22,14 @@ describe 'form-input', ->
$scope
.
model
=
{
username
:
undefined
}
template
=
'''
<form form-validate name="login" onsubmit="return false">
<div class="form-field">
<input type="text" class="form-input" name="username"
ng-model="model.username" name="username"
required ng-minlength="3" />
</div>
</form>
<div class="form-field">
<input type="text" class="form-input" name="username"
ng-model="model.username" name="username"
required ng-minlength="3" />
</div>
'''
$field
=
$compile
(
angular
.
element
(
template
))(
$scope
)
.
find
(
'div'
)
$field
=
$compile
(
angular
.
element
(
template
))(
$scope
)
$scope
.
$digest
()
it
'should remove an error class to an valid field on change'
,
->
...
...
@@ -109,3 +106,17 @@ describe 'form-input', ->
$scope
.
$digest
()
assert
.
notInclude
(
$field
.
prop
(
'className'
),
'form-field-error'
)
describe
'with form-validate'
,
->
link
=
require
(
'../form-input'
)().
link
it
'should register its model with the validator'
,
->
model
=
{
'$parsers'
:
[]}
validator
=
{
addControl
:
sinon
.
spy
(),
removeControl
:
sinon
.
spy
()}
link
(
$scope
,
$field
,
null
,
[
model
,
validator
])
assert
.
calledOnce
(
validator
.
addControl
)
assert
.
calledWith
(
validator
.
addControl
,
model
)
assert
.
notCalled
(
validator
.
removeControl
)
$scope
.
$destroy
()
assert
.
calledOnce
(
validator
.
removeControl
)
assert
.
calledWith
(
validator
.
removeControl
,
model
)
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