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
b4b68c69
Commit
b4b68c69
authored
Jan 27, 2015
by
ujvari
Committed by
Gergely Ujvari
Jan 29, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for viewFilter
parent
5f06db6a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
171 additions
and
0 deletions
+171
-0
services-test.coffee
tests/js/services-test.coffee
+171
-0
No files found.
tests/js/services-test.coffee
0 → 100644
View file @
b4b68c69
assert
=
chai
.
assert
sinon
.
assert
.
expose
assert
,
prefix
:
null
poem
=
tiger
:
'Tiger! Tiger! burning bright
In the forest of the night
What immortal hand or eye
Could frame thy fearful symmetry?'
raven
:
'Once upon a midnight dreary, while I pondered, weak and weary,
Over many a quaint and curious volume of forgotten lore—
While I nodded, nearly napping, suddenly there came a tapping,
As of some one gently rapping, rapping at my chamber door.
“’Tis some visitor,” I muttered, “tapping at my chamber door—
Only this and nothing more.”'
describe
'h'
,
->
sandbox
=
null
beforeEach
module
(
'h'
)
beforeEach
module
(
$provide
)
->
sandbox
=
sinon
.
sandbox
.
create
()
return
afterEach
->
sandbox
.
restore
()
describe
'viewFilter service'
,
->
viewFilter
=
null
stringHelpers
=
null
beforeEach
inject
(
_stringHelpers_
,
_viewFilter_
)
->
stringHelpers
=
_stringHelpers_
viewFilter
=
_viewFilter_
describe
'filter'
,
->
it
'normalizes the filter terms'
,
->
stringHelpers
.
uniFold
=
sandbox
.
spy
()
filters
=
text
:
terms
:
[
'Tiger'
]
operator
:
'and'
viewFilter
.
filter
[],
filters
assert
.
calledWith
stringHelpers
.
uniFold
,
'tiger'
describe
'filter operators'
,
->
annotations
=
null
beforeEach
->
annotations
=
[
{
id
:
1
,
text
:
poem
.
tiger
},
{
id
:
2
,
text
:
poem
.
raven
}
]
it
'all terms must match for "and" operator'
,
->
filters
=
text
:
terms
:
[
'Tiger'
,
'burning'
,
'bright'
]
operator
:
'and'
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
equal
result
.
length
,
1
assert
.
equal
result
[
0
],
1
it
'only one term must match for "or" operator'
,
->
filters
=
text
:
terms
:
[
'Tiger'
,
'quaint'
]
operator
:
'or'
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
equal
result
.
length
,
2
describe
'checkers'
,
->
describe
'autofalse'
,
->
it
'consider auto false function'
,
->
viewFilter
.
checkers
=
test
:
autofalse
:
sandbox
.
stub
().
returns
(
true
)
value
:
(
annotation
)
->
return
annotation
.
test
match
:
(
term
,
value
)
->
return
value
.
indexOf
(
term
)
>
-
1
filters
=
test
:
terms
:
[
'Tiger'
]
operator
:
'and'
annotations
=
[{
id
:
1
,
test
:
poem
.
tiger
}]
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
autofalse
assert
.
equal
result
.
length
,
0
it
'uses the value function to extract data from the annotation'
,
->
viewFilter
.
checkers
=
test
:
autofalse
:
(
annotation
)
->
return
false
value
:
sandbox
.
stub
().
returns
(
'test'
)
match
:
(
term
,
value
)
->
return
value
.
indexOf
(
term
)
>
-
1
filters
=
test
:
terms
:
[
'test'
]
operator
:
'and'
annotations
=
[{
id
:
1
,
test
:
poem
.
tiger
}]
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
value
assert
.
equal
result
.
length
,
1
it
'the match function determines the matching'
,
->
viewFilter
.
checkers
=
test
:
autofalse
:
(
annotation
)
->
return
false
value
:
(
annotation
)
->
return
annotation
.
test
match
:
sandbox
.
stub
().
returns
(
false
)
filters
=
test
:
terms
:
[
'Tiger'
]
operator
:
'and'
annotations
=
[{
id
:
1
,
test
:
poem
.
tiger
}]
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
match
assert
.
equal
result
.
length
,
0
viewFilter
.
checkers
.
test
.
match
.
returns
(
true
)
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
called
viewFilter
.
checkers
.
test
.
match
assert
.
equal
result
.
length
,
1
describe
'any field'
,
->
it
'finds matches across many fields'
,
->
annotation1
=
{
id
:
1
,
text
:
poem
.
tiger
}
annotation2
=
{
id
:
2
,
user
:
poem
.
tiger
}
annotation3
=
{
id
:
3
,
tags
:
[
'Tiger'
]}
annotations
=
[
annotation1
,
annotation2
,
annotation3
]
filters
=
any
:
terms
:
[
'Tiger'
]
operator
:
'and'
result
=
viewFilter
.
filter
annotations
,
filters
assert
.
equal
result
.
length
,
3
it
'can find terms across different fields'
,
->
annotation
=
id
:
1
text
:
poem
.
tiger
target
:
[
selector
:
[{
"type"
:
"TextQuoteSelector"
,
"exact"
:
"The Tiger by William Blake"
,
}]
user
:
"acct:poe@edgar.com"
tags
:
[
"poem"
,
"Blake"
,
"Tiger"
]
]
filters
=
any
:
terms
:
[
'burning'
,
'William'
,
'poem'
,
'bright'
]
operator
:
'and'
result
=
viewFilter
.
filter
[
annotation
],
filters
assert
.
equal
result
.
length
,
1
assert
.
equal
result
[
0
],
1
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