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
daa64411
Commit
daa64411
authored
Jan 26, 2015
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start writing tests for the AnnotationUISync module
parent
6fb310f9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
10 deletions
+98
-10
annotation-sync.coffee
h/static/scripts/annotation-sync.coffee
+2
-0
annotation-ui-sync.coffee
h/static/scripts/annotation-ui-sync.coffee
+9
-7
cross-frame-service.coffee
h/static/scripts/cross-frame-service.coffee
+3
-3
annotation-ui-sync-test.coffee
tests/js/annotation-ui-sync-test.coffee
+84
-0
No files found.
h/static/scripts/annotation-sync.coffee
View file @
daa64411
...
...
@@ -49,6 +49,8 @@ class AnnotationSync
this
.
_syncCache
(
channel
)
@
bridge
.
onConnect
(
onConnect
)
# Provide a public interface to the annotation cache so that other
# sync services can lookup annotations by tag.
getAnnotationForTag
:
(
tag
)
->
@
cache
[
tag
]
or
null
...
...
h/static/scripts/annotation-ui-sync.coffee
View file @
daa64411
# Uses a channel between the sidebar and the attached providers to ensure
# the interface remains in sync.
class
AnnotationUISync
constructor
:
(
$
rootScope
,
$window
,
bridge
,
annotationUI
)
->
constructor
:
(
$
window
,
bridge
,
annotationSync
,
annotationUI
)
->
getAnnotationsByTags
=
(
tags
)
->
tags
.
map
(
bridge
.
getAnnotationForTag
,
bridge
)
tags
.
map
(
annotationSync
.
getAnnotationForTag
,
bridge
)
notifyHost
=
(
message
)
->
for
{
channel
,
window
}
in
bridge
.
links
where
window
is
$window
.
parent
...
...
@@ -17,20 +17,20 @@ class AnnotationUISync
back
:
hide
open
:
show
showEditor
:
show
showAnnotations
:
(
ctx
,
tags
=
[])
=
>
showAnnotations
:
(
ctx
,
tags
=
[])
-
>
show
()
annotations
=
getAnnotationsByTags
(
tags
)
annotationUI
.
xorSelectedAnnotations
(
annotations
)
focusAnnotations
:
(
ctx
,
tags
=
[])
=
>
focusAnnotations
:
(
ctx
,
tags
=
[])
-
>
annotations
=
getAnnotationsByTags
(
tags
)
annotationUI
.
focusAnnotations
(
annotations
)
toggleAnnotationSelection
:
(
ctx
,
tags
=
[])
=
>
toggleAnnotationSelection
:
(
ctx
,
tags
=
[])
-
>
annotations
=
getAnnotationsByTags
(
tags
)
annotationUI
.
selectAnnotations
(
annotations
)
setTool
:
(
ctx
,
name
)
=
>
setTool
:
(
ctx
,
name
)
-
>
annotationUI
.
tool
=
name
bridge
.
notify
(
method
:
'setTool'
,
params
:
name
)
setVisibleHighlights
:
(
ctx
,
state
)
=
>
setVisibleHighlights
:
(
ctx
,
state
)
-
>
annotationUI
.
visibleHighlights
=
Boolean
(
state
)
bridge
.
notify
(
method
:
'setVisibleHighlights'
,
params
:
state
)
...
...
@@ -49,3 +49,5 @@ class AnnotationUISync
params
:
annotationUI
.
visibleHighlights
bridge
.
onConnect
(
onConnect
)
angular
.
module
(
'h'
).
value
(
'AnnotationUISync'
,
AnnotationUISync
)
h/static/scripts/cross-frame-service.coffee
View file @
daa64411
...
...
@@ -38,8 +38,8 @@ class CrossFrameService
new
AnnotationSync
(
options
,
bridge
)
createAnnotationUISync
=
(
bridge
)
->
new
AnnotationUISync
(
$
rootScope
,
$window
,
bridge
,
annotationUI
)
createAnnotationUISync
=
(
bridge
,
annotationSync
)
->
new
AnnotationUISync
(
$
window
,
bridge
,
annotationSync
,
annotationUI
)
addProvider
=
(
channel
)
=>
provider
=
{
channel
:
channel
,
entities
:
[]}
...
...
@@ -57,7 +57,7 @@ class CrossFrameService
bridge
.
onConnect
(
addProvider
)
annotationSync
=
createAnnotationSync
(
bridge
)
annotationUISync
=
createAnnotationUISync
(
bridge
)
annotationUISync
=
createAnnotationUISync
(
bridge
,
annotationSync
)
onDiscoveryCallback
=
(
source
,
origin
,
token
)
->
bridge
.
createChannel
(
source
,
origin
,
token
)
...
...
tests/js/annotation-ui-sync-test.coffee
0 → 100644
View file @
daa64411
assert
=
chai
.
assert
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
describe
'AnnotationUISync'
,
->
sandbox
=
sinon
.
sandbox
.
create
()
uiSync
=
null
fakeBridge
=
null
createAnnotationUISync
=
null
PARENT_WINDOW
=
{}
beforeEach
module
(
'h'
)
beforeEach
inject
(
AnnotationUISync
)
->
fakeWindow
=
parent
:
PARENT_WINDOW
fakeBridge
=
on
:
sandbox
.
stub
()
notify
:
sandbox
.
stub
()
onConnect
:
sandbox
.
stub
()
fakeAnnotationSync
=
getAnnotationForTag
:
(
x
)
->
x
fakeAnnotationUI
=
focusAnnotations
:
sandbox
.
stub
()
selectAnnotations
:
sandbox
.
stub
()
xorSelectedAnnotations
:
sandbox
.
stub
()
tool
:
'comment'
visibleHighlights
:
false
createAnnotationUISync
=
->
new
AnnotationUISync
(
fakeWindow
,
fakeBridge
,
fakeAnnotationSync
,
fakeAnnotationUI
)
afterEach
:
->
sandbox
.
restore
()
describe
'on bridge connection'
,
->
describe
'when the source is not the parent window'
,
->
it
'broadcasts the tool/visibility settings to the channel'
,
->
channel
=
notify
:
sandbox
.
stub
()
fakeBridge
.
onConnect
.
callsArgWith
(
0
,
channel
,
{})
createAnnotationUISync
()
assert
.
calledWith
(
channel
.
notify
,
{
method
:
'setTool'
params
:
'comment'
})
assert
.
calledWith
(
channel
.
notify
,
{
method
:
'setVisibleHighlights'
params
:
false
})
describe
'when the source is the parent window'
,
->
it
'does nothing'
,
->
channel
=
notify
:
sandbox
.
stub
()
fakeBridge
.
onConnect
.
callsArgWith
(
0
,
channel
,
PARENT_WINDOW
)
createAnnotationUISync
()
assert
.
notCalled
(
channel
.
notify
)
describe
'on "back" event'
,
->
it
'sends the "hideFrame" message to the host only'
describe
'on "open" event'
,
->
it
'sends the "showFrame" message to the host only'
describe
'on "showEditor" event'
,
->
it
'sends the "showFrame" message to the host only'
describe
'on "showAnnotations" event'
,
->
it
'sends the "showFrame" message to the host only'
it
'updates the annotationUI to include the shown annotations'
describe
'on "focusAnnotations" event'
,
->
it
'updates the annotationUI to show the provided annotations'
describe
'on "toggleAnnotationSelection" event'
,
->
it
'updates the annotationUI to show the provided annotations'
describe
'on "setTool" event'
,
->
it
'updates the annotationUI with the new tool'
it
'notifies the other frames of the change'
describe
'on "setVisibleHighlights" event'
,
->
it
'updates the annotationUI with the new value'
it
'notifies the other frames of the change'
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