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
494e58d5
Commit
494e58d5
authored
Jun 10, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update highlighter tests
parent
c65f8752
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
76 deletions
+84
-76
highlighter-test.coffee
h/static/scripts/annotator/test/highlighter-test.coffee
+84
-76
No files found.
h/static/scripts/annotator/test/highlighter-test.coffee
View file @
494e58d5
Annotator
=
require
(
'annotator'
)
$
=
Annotator
.
$
highlight
=
require
(
'../highlight
'
)
highlight
er
=
require
(
'../highlighter
'
)
assert
=
chai
.
assert
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
describe
'TextHighlight'
,
->
sandbox
=
null
scrollTarget
=
null
describe
"highlightRange"
,
->
it
'wraps a highlight span around the given range'
,
->
txt
=
document
.
createTextNode
(
'test highlight span'
)
el
=
document
.
createElement
(
'span'
)
el
.
appendChild
(
txt
)
r
=
new
Annotator
.
Range
.
NormalizedRange
({
commonAncestor
:
el
,
start
:
txt
,
end
:
txt
})
result
=
highlighter
.
highlightRange
(
r
)
assert
.
equal
(
result
.
length
,
1
)
assert
.
strictEqual
(
el
.
childNodes
[
0
],
result
[
0
])
assert
.
isTrue
(
result
[
0
].
classList
.
contains
(
'annotator-hl'
))
createTestHighlight
=
->
new
highlight
.
TextHighlight
"test range"
it
'skips text nodes that are only white space'
,
->
txt
=
document
.
createTextNode
(
'one'
)
blank
=
document
.
createTextNode
(
' '
)
txt2
=
document
.
createTextNode
(
'two'
)
el
=
document
.
createElement
(
'span'
)
el
.
appendChild
(
txt
)
el
.
appendChild
(
blank
)
el
.
appendChild
(
txt2
)
r
=
new
Annotator
.
Range
.
NormalizedRange
({
commonAncestor
:
el
,
start
:
txt
,
end
:
txt2
})
result
=
highlighter
.
highlightRange
(
r
)
assert
.
equal
(
result
.
length
,
2
)
assert
.
strictEqual
(
el
.
childNodes
[
0
],
result
[
0
])
assert
.
strictEqual
(
el
.
childNodes
[
2
],
result
[
1
])
beforeEach
->
sandbox
=
sinon
.
sandbox
.
create
()
sandbox
.
stub
highlight
.
TextHighlight
,
'highlightRange'
,
(
normedRange
,
cssClass
)
->
hl
=
document
.
createElement
"hl"
hl
.
appendChild
document
.
createTextNode
"test highlight span"
hl
Annotator
.
$
.
fn
.
scrollintoview
=
sinon
.
spy
(
options
)
->
scrollTarget
=
this
[
0
]
options
?
.
complete
?
()
describe
'removeHighlights'
,
->
it
'unwraps all the elements'
,
->
txt
=
document
.
createTextNode
(
'word'
)
el
=
document
.
createElement
(
'span'
)
hl
=
document
.
createElement
(
'span'
)
div
=
document
.
createElement
(
'div'
)
el
.
appendChild
(
txt
)
hl
.
appendChild
(
el
)
div
.
appendChild
(
hl
)
highlighter
.
removeHighlights
([
hl
])
assert
.
isNull
(
hl
.
parentNode
)
assert
.
strictEqual
(
el
.
parentNode
,
div
)
afterEach
->
sandbox
.
restore
()
scrollTarget
=
null
it
'does not fail on nodes with no parent'
,
->
txt
=
document
.
createTextNode
(
'no parent'
)
hl
=
document
.
createElement
(
'span'
)
hl
.
appendChild
(
txt
)
highlighter
.
removeHighlights
([
hl
])
describe
"constructor"
,
->
it
'wraps a highlight span around the given range'
,
->
hl
=
createTestHighlight
()
assert
.
calledWith
highlight
.
TextHighlight
.
highlightRange
,
"test range"
it
'stores the created highlight spans in _highlights'
,
->
hl
=
createTestHighlight
()
assert
.
equal
hl
.
_highlights
.
textContent
,
"test highlight span"
describe
"getBoundingClientRect"
,
->
it
'returns the bounding box of all the highlight client rectangles'
,
->
rects
=
[
{
top
:
20
left
:
15
bottom
:
30
right
:
25
}
{
top
:
10
left
:
15
bottom
:
20
right
:
25
}
{
top
:
15
left
:
20
bottom
:
25
right
:
30
}
{
top
:
15
left
:
10
bottom
:
25
right
:
20
}
]
fakeHighlights
=
rects
.
map
(
r
)
->
return
getBoundingClientRect
:
->
r
hl
=
_highlights
:
fakeHighlights
result
=
highlight
.
TextHighlight
.
prototype
.
getBoundingClientRect
.
call
(
hl
)
assert
.
equal
(
result
.
left
,
10
)
assert
.
equal
(
result
.
top
,
10
)
assert
.
equal
(
result
.
right
,
30
)
assert
.
equal
(
result
.
bottom
,
30
)
describe
"scrollToView"
,
->
it
'calls jQuery scrollintoview'
,
->
hl
=
createTestHighlight
()
hl
.
scrollToView
()
assert
.
called
Annotator
.
$
.
fn
.
scrollintoview
it
'scrolls to the created highlight span'
,
->
hl
=
createTestHighlight
()
hl
.
scrollToView
()
assert
.
equal
scrollTarget
,
hl
.
_highlights
describe
"getBoundingClientRect"
,
->
it
'returns the bounding box of all the highlight client rectangles'
,
->
rects
=
[
{
top
:
20
left
:
15
bottom
:
30
right
:
25
}
{
top
:
10
left
:
15
bottom
:
20
right
:
25
}
{
top
:
15
left
:
20
bottom
:
25
right
:
30
}
{
top
:
15
left
:
10
bottom
:
25
right
:
20
}
]
fakeHighlights
=
rects
.
map
(
r
)
->
return
getBoundingClientRect
:
->
r
result
=
highlighter
.
getBoundingClientRect
(
fakeHighlights
)
assert
.
equal
(
result
.
left
,
10
)
assert
.
equal
(
result
.
top
,
10
)
assert
.
equal
(
result
.
right
,
30
)
assert
.
equal
(
result
.
bottom
,
30
)
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