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
57d5365a
Commit
57d5365a
authored
Jul 30, 2014
by
Aron Carroll
Committed by
Randall Leeds
Aug 21, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the match directive and add unit tests
parent
b67ccacb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
8 deletions
+52
-8
directives.coffee
h/static/scripts/directives.coffee
+5
-8
directives-test.coffee
tests/js/directives-test.coffee
+47
-0
No files found.
h/static/scripts/directives.coffee
View file @
57d5365a
...
...
@@ -362,15 +362,12 @@ whenscrolled = ->
scope
.
$apply
attr
.
whenscrolled
match
=
->
# Checks to see if two values match each other.
link
:
(
scope
,
elem
,
attr
,
ctrl
)
->
return
unless
ctrl
?
elem
.
on
'keyup'
,
->
currentValue
=
scope
.
match
==
ctrl
.
$modelValue
ctrl
.
$setValidity
(
'match'
,
currentValue
)
link
:
(
scope
,
elem
,
attr
,
input
)
->
validate
=
->
input
.
$setValidity
(
'match'
,
scope
.
match
==
input
.
$modelValue
)
elem
.
on
(
'keyup'
,
validate
)
scope
.
$watch
(
'match'
,
validate
)
scope
:
match
:
'='
restrict
:
'A'
...
...
tests/js/directives-test.coffee
View file @
57d5365a
...
...
@@ -156,3 +156,50 @@ describe 'h.directives', ->
it
'opens with only the username'
,
->
$element
.
find
(
'.user'
).
click
()
sinon
.
assert
.
calledWith
(
fakeWindow
.
open
,
'/u/jim'
)
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
'.showAccount'
,
->
$element
=
null
beforeEach
->
$element
=
$compile
(
'<a show-account>Account</a>'
)(
$scope
)
$scope
.
$digest
()
it
'triggers the "nav:account" event when the Account item is clicked'
,
(
done
)
->
$scope
.
$on
'nav:account'
,
->
done
()
$element
.
click
()
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