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
745be4ef
Commit
745be4ef
authored
Feb 09, 2015
by
csillag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add/update test suite for scrolling
parent
025cc7ea
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
5 deletions
+74
-5
guest-test.coffee
tests/js/guest-test.coffee
+5
-5
enhancedanchoring-test.coffee
tests/js/plugin/enhancedanchoring-test.coffee
+69
-0
No files found.
tests/js/guest-test.coffee
View file @
745be4ef
...
...
@@ -194,14 +194,14 @@ describe 'Annotator.Guest', ->
assert
.
calledWith
(
highlights
[
1
].
setFocused
,
false
)
describe
'on "scrollToAnnotation" event'
,
->
it
'scrolls to the
highLight
with the matching tag'
,
->
it
'scrolls to the
anchor
with the matching tag'
,
->
guest
=
createGuest
()
highlight
s
=
[
{
annotation
:
{
$
$tag
:
'tag1'
},
scroll
To
:
sandbox
.
stub
()}
anchor
s
=
[
{
annotation
:
{
$
$tag
:
'tag1'
},
scroll
IntoView
:
sandbox
.
stub
()}
]
sandbox
.
stub
(
guest
.
anchoring
,
'get
Highlights'
).
returns
(
highlight
s
)
sandbox
.
stub
(
guest
.
anchoring
,
'get
Anchors'
).
returns
(
anchor
s
)
emitGuestEvent
(
'scrollToAnnotation'
,
'ctx'
,
'tag1'
)
assert
.
called
(
highlights
[
0
].
scrollTo
)
assert
.
called
(
anchors
[
0
].
scrollIntoView
)
describe
'on "getDocumentInfo" event'
,
->
guest
=
null
...
...
tests/js/plugin/enhancedanchoring-test.coffee
View file @
745be4ef
...
...
@@ -37,6 +37,8 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
am
.
chooseAccessPolicy
()
am
.
document
.
setPageIndex
=
sinon
.
spy
()
am
.
strategies
.
push
name
:
"dummy anchoring strategy"
code
:
(
annotation
,
target
)
->
...
...
@@ -57,6 +59,11 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
anchor
:
anchor
page
:
page
removeFromDocument
:
sinon
.
spy
()
scrollIntoView
:
sinon
.
spy
->
new
Promise
(
resolve
,
reject
)
=>
setTimeout
=>
@
anchor
.
anchoring
.
document
.
setPageIndex
@
page
resolve
()
afterEach
->
sandbox
.
restore
()
...
...
@@ -219,16 +226,52 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
assert
.
include
hls
,
anchor2
.
highlight
[
anchor2
.
startPage
]
assert
.
notInclude
hls
,
anchor3
.
highlight
[
anchor3
.
startPage
]
describe
'Anchor.scrollIntoView()'
,
->
it
'calls scrollIntoView() on the highlight'
,
->
am
=
createAnchoringManager
()
ann
=
createTestAnnotation
"a1"
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
scrollIntoView
().
then
->
assert
.
called
anchor
.
highlight
[
anchor
.
startPage
].
scrollIntoView
describe
'two-phased anchoring'
,
->
# Simple lazy rendering document simulation for testing,
# which emulates the user movement prediction (and page rendering)
# behavior of PDF.js
class
DummyDocumentAccess
@
applicable
:
->
true
isPageMapped
:
(
index
)
->
index
in
@
_rendered
getPageIndex
:
->
@
currentIndex
setPageIndex
:
(
index
)
->
# Do this when the wanted page is ready
onPageReady
=
=>
# Try to find out where will the reader proceed
prediction
=
if
@
currentIndex
<
index
index
+
1
# If we went forward, we'll want the next page, too
else
index
-
1
# if we want backward, we'll want the prev. page, too
# Set the page index where we want to be
@
currentIndex
=
index
# Render the predicted next page
renderPage
(
this
,
prediction
)
unless
@
isPageMapped
prediction
# Try to move where we need to be
if
@
isPageMapped
index
onPageReady
()
else
renderPage
(
this
,
index
).
then
onPageReady
constructor
:
->
@
_rendered
=
[]
@
currentIndex
=
-
10
# Helper function to trigger a page rendering
# This is an asynchronous method; returns a promise.
...
...
@@ -634,3 +677,29 @@ describe 'Annotator.Plugin.EnhancedAnchoring', ->
anchor
.
realize
()
assert
anchor
.
fullyRealized
describe
'when scrolling to a virtual anchor'
,
->
it
'gets the right page rendered'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
scrollIntoView
().
then
->
assert
am
.
document
.
isPageMapped
1
it
'scrolls to the right page'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
scrollIntoView
().
then
->
assert
.
equal
am
.
document
.
getPageIndex
(),
1
it
'calls scrollIntoView() on the highlight'
,
->
am
=
createAnchoringManagerAndLazyDocument
()
ann
=
createTestAnnotationForPages
"a1"
,
[
1
]
anchor
=
am
.
createAnchor
(
ann
,
ann
.
target
[
0
]).
result
anchor
.
scrollIntoView
().
then
->
assert
.
called
anchor
.
highlight
[
1
].
scrollIntoView
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