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
4db68d8a
Commit
4db68d8a
authored
Feb 10, 2015
by
gergely-ujvari
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1931 from hypothesis/anchoring-testing
Switch two-phase anchoring tests to async
parents
be94ba8c
799850cb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
189 additions
and
177 deletions
+189
-177
enhancedanchoring-test.coffee
tests/js/plugin/enhancedanchoring-test.coffee
+189
-177
No files found.
tests/js/plugin/enhancedanchoring-test.coffee
View file @
4db68d8a
...
...
@@ -231,10 +231,13 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
@
_rendered
=
[]
# Helper function to trigger a page rendering
# This is an asynchronous method; returns a promise.
renderPage
=
(
doc
,
index
)
->
if
doc
.
isPageMapped
(
index
)
throw
new
Error
"Cannot call renderPage with an already mapped index:
#{
index
}
, ensure the document is setup correctly"
new
Promise
(
resolve
,
reject
)
->
setTimeout
->
doc
.
_rendered
.
push
index
# Publish an event
...
...
@@ -243,11 +246,22 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
event
.
pageIndex
=
index
window
.
dispatchEvent
event
# Resolve the promise
resolve
()
# Helper function to trigger the rendering of several pages.
# This is an asynchronous method; returns a promise.
renderPages
=
(
doc
,
indexes
)
->
Promise
.
all
(
renderPage
(
doc
,
index
)
for
index
in
indexes
)
# Helper function to trigger a page unrendering
# This is an asynchronous method; returns a promise.
unrenderPage
=
(
doc
,
index
)
->
unless
doc
.
isPageMapped
index
throw
new
Error
"Cannot call unrenderPage with an unmapped index:
#{
index
}
, ensure the document is setup correctly"
new
Promise
(
resolve
,
reject
)
->
setTimeout
->
i
=
doc
.
_rendered
.
indexOf
index
doc
.
_rendered
.
splice
(
i
,
1
)
...
...
@@ -258,6 +272,9 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
event
.
pageIndex
=
index
window
.
dispatchEvent
event
# Resolve the promise
resolve
()
# Helper function to set up an anchoring manager
# with a document access policy that mimics
# a platform with lazy rendering
...
...
@@ -309,14 +326,14 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'creates real anchors'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
assert
anchor
.
fullyRealized
it
'creates highlights'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
1
]
...
...
@@ -325,50 +342,49 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'announces the highlights with the appropriate event'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
1
]
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightsCreated'
,
[
hl
]
describe
'when a page is unrendered'
,
->
it
'calls removeFromDocument an the correct highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
1
]
unrenderPage
am
.
document
,
1
unrenderPage
(
am
.
document
,
1
).
then
->
assert
.
called
hl
.
removeFromDocument
it
'removes highlights from the relevant page'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
unrenderPage
am
.
document
,
1
unrenderPage
(
am
.
document
,
1
).
then
->
assert
!
anchor
.
fullyRealized
it
'announces the removal of the highlights from the relevant page'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
1
]
unrenderPage
am
.
document
,
1
unrenderPage
(
am
.
document
,
1
).
then
->
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightRemoved'
,
hl
it
'switches the anchor to virtual'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
unrenderPage
am
.
document
,
1
unrenderPage
(
am
.
document
,
1
).
then
->
assert
!
anchor
.
fullyRealized
describe
'when the wanted page is not rendered'
,
->
...
...
@@ -400,15 +416,14 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
am
=
createAnchoringManagerAndLazyDocument
()
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
assert
anchor
.
fullyRealized
it
'creates the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
hl
=
anchor
.
highlight
[
1
]
assert
.
ok
hl
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightsCreated'
,
[
hl
]
...
...
@@ -417,8 +432,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
am
=
createAnchoringManagerAndLazyDocument
()
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
hl
=
anchor
.
highlight
[
1
]
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightsCreated'
,
[
hl
]
...
...
@@ -426,7 +440,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'creates partially realized anchors'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
...
...
@@ -434,7 +448,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'creates the highlights for the rendered pages'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
...
...
@@ -442,7 +456,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'creates no highlights for the missing pages'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
...
...
@@ -450,7 +464,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'announces the creation of highlights for the rendered pages'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
...
...
@@ -461,29 +475,29 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'the anchor is fully realized'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
renderPage
am
.
document
,
3
renderPage
(
am
.
document
,
3
).
then
->
assert
anchor
.
fullyRealized
it
'creates the missing highlights'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
renderPage
am
.
document
,
3
renderPage
(
am
.
document
,
3
).
then
->
assert
.
ok
anchor
.
highlight
[
3
]
it
'announces the creation of the missing highlights'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
(
am
.
document
,
2
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
renderPage
am
.
document
,
3
renderPage
(
am
.
document
,
3
).
then
->
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightsCreated'
,
[
anchor
.
highlight
[
3
]]
...
...
@@ -492,64 +506,59 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'calls removeFromDocument() on the involved highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
am
.
document
,
3
renderPages
(
am
.
document
,
[
2
,
3
]).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
2
]
unrenderPage
am
.
document
,
2
unrenderPage
(
am
.
document
,
2
).
then
->
assert
.
called
hl
.
removeFromDocument
it
'does not call removeFromDocument() on the other highlights'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
am
.
document
,
3
renderPages
(
am
.
document
,
[
2
,
3
]).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
3
]
unrenderPage
am
.
document
,
2
unrenderPage
(
am
.
document
,
2
).
then
->
assert
.
notCalled
hl
.
removeFromDocument
it
'removes the involved highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
am
.
document
,
3
renderPages
(
am
.
document
,
[
2
,
3
]).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
unrenderPage
am
.
document
,
2
unrenderPage
(
am
.
document
,
2
).
then
->
assert
.
notOk
anchor
.
highlight
[
2
]
it
'retains the other highlights'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
am
.
document
,
3
renderPages
(
am
.
document
,
[
2
,
3
]).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
unrenderPage
am
.
document
,
2
unrenderPage
(
am
.
document
,
2
).
then
->
assert
.
ok
anchor
.
highlight
[
3
]
it
'announces the removal of the involved highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
am
.
document
,
3
renderPages
(
am
.
document
,
[
2
,
3
]).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
2
]
unrenderPage
am
.
document
,
2
unrenderPage
(
am
.
document
,
2
).
then
->
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightRemoved'
,
hl
it
'switched the anchor to virtual'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
2
renderPage
am
.
document
,
3
renderPages
(
am
.
document
,
[
2
,
3
]).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[[
2
,
3
]]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
2
]
unrenderPage
am
.
document
,
2
unrenderPage
(
am
.
document
,
2
).
then
->
assert
!
anchor
.
fullyRealized
...
...
@@ -557,7 +566,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'calls removeFromDocument() on the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
1
]
...
...
@@ -567,34 +576,37 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'removes the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
virtualize
1
assert
.
notOk
anchor
.
highlight
[
1
],
"the highlight should be no more"
it
'announces the removal of the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
hl
=
anchor
.
highlight
[
1
]
anchor
.
virtualize
1
assert
.
calledWith
am
.
annotator
.
publish
,
'highlightRemoved'
,
hl
it
'switches the anchor to virtual'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
virtualize
1
assert
!
anchor
.
fullyRealized
describe
'when re-realizing a manually virtualized anchor'
,
->
it
're-creates the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
virtualize
1
...
...
@@ -604,7 +616,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'announces the creation of the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
virtualize
1
...
...
@@ -615,7 +627,7 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
it
'realizes the anchor'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
renderPage
am
.
document
,
1
renderPage
(
am
.
document
,
1
).
then
->
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
virtualize
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