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
abf19b65
Commit
abf19b65
authored
Feb 03, 2015
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit tests for the Bridge plugin
parent
329ef769
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
14 deletions
+85
-14
bridge.coffee
h/static/scripts/annotator/plugin/bridge.coffee
+3
-4
bridge-test.coffee
tests/js/annotator/plugins/bridge-test.coffee
+82
-10
No files found.
h/static/scripts/annotator/plugin/bridge.coffee
View file @
abf19b65
$
=
Annotator
.
$
$
=
Annotator
.
$
class
Annotator
.
Plugin
.
Bridge
extends
Annotator
.
Plugin
class
Annotator
.
Plugin
.
Bridge
extends
Annotator
.
Plugin
constructor
:
(
elem
,
options
)
->
constructor
:
(
elem
,
options
)
->
super
super
@
discovery
=
new
CrossFrameDiscovery
(
window
,
options
.
discoveryOptions
)
@
discovery
=
new
window
.
CrossFrameDiscovery
(
window
,
options
.
discoveryOptions
)
@
bridge
=
new
CrossFrameBridge
(
options
.
bridgeOptions
)
@
bridge
=
new
window
.
CrossFrameBridge
(
options
.
bridgeOptions
)
@
annotationSync
=
new
AnnotationSync
(
options
.
annotationSyncOptions
,
@
bridge
)
@
annotationSync
=
new
window
.
AnnotationSync
(
options
.
annotationSyncOptions
,
@
bridge
)
pluginInit
:
->
pluginInit
:
->
onDiscoveryCallback
=
(
source
,
origin
,
token
)
=>
onDiscoveryCallback
=
(
source
,
origin
,
token
)
=>
...
...
tests/js/annotator/plugins/bridge-test.coffee
View file @
abf19b65
...
@@ -2,24 +2,96 @@ assert = chai.assert
...
@@ -2,24 +2,96 @@ assert = chai.assert
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
describe
'Annotator.Plugin.Bridge'
,
->
describe
'Annotator.Plugin.Bridge'
,
->
fakeCFDiscovery
=
null
fakeCFBridge
=
null
fakeAnnotationSync
=
null
sandbox
=
sinon
.
sandbox
.
create
()
sandbox
=
sinon
.
sandbox
.
create
()
createGuest
=
(
options
)
->
createBridge
=
(
options
)
->
defaults
=
annotationSyncOptions
:
on
:
sandbox
.
stub
()
emit
:
sandbox
.
stub
()
element
=
document
.
createElement
(
'div'
)
element
=
document
.
createElement
(
'div'
)
return
new
Annotator
.
Plugin
.
Bridge
(
element
,
options
||
{})
return
new
Annotator
.
Plugin
.
Bridge
(
element
,
$
.
extend
(
true
,
{},
defaults
,
options
))
beforeEach
->
fakeCFDiscovery
=
startDiscovery
:
sandbox
.
stub
()
stopDiscovery
:
sandbox
.
stub
()
fakeCFBridge
=
createChannel
:
sandbox
.
stub
()
afterEach
->
sandbox
.
restore
()
fakeAnnotationSync
=
sync
:
sandbox
.
stub
()
window
.
AnnotationSync
=
sandbox
.
stub
().
returns
(
fakeAnnotationSync
)
window
.
CrossFrameDiscovery
=
sandbox
.
stub
().
returns
(
fakeCFDiscovery
)
window
.
CrossFrameBridge
=
sandbox
.
stub
().
returns
(
fakeCFBridge
)
afterEach
->
delete
window
.
AnnotationSync
delete
window
.
CrossFrameBridge
delete
window
.
CrossFrameDiscovery
sandbox
.
restore
()
describe
'constructor'
,
->
describe
'constructor'
,
->
it
'instantiates the CrossFrameDiscovery component'
it
'instantiates the CrossFrameDiscovery component'
,
->
it
'instantiates the CrossFrameBridge component'
createBridge
()
it
'instantiates the AnnotationSync component'
assert
.
called
(
CrossFrameDiscovery
)
assert
.
calledWith
(
CrossFrameDiscovery
,
window
)
it
'passes the options along to the bridge'
,
->
createBridge
(
discoveryOptions
:
{
server
:
true
})
assert
.
called
(
CrossFrameDiscovery
)
assert
.
calledWith
(
CrossFrameDiscovery
,
window
,
server
:
true
)
it
'instantiates the CrossFrameBridge component'
,
->
createBridge
()
assert
.
called
(
CrossFrameBridge
)
assert
.
calledWith
(
CrossFrameDiscovery
)
it
'passes the options along to the bridge'
,
->
createBridge
(
bridgeOptions
:
{
scope
:
'myscope'
})
assert
.
called
(
CrossFrameBridge
)
assert
.
calledWith
(
CrossFrameBridge
,
scope
:
'myscope'
)
it
'instantiates the AnnotationSync component'
,
->
createBridge
()
assert
.
called
(
AnnotationSync
)
it
'passes along options to AnnotationSync'
,
->
formatter
=
(
x
)
->
x
createBridge
(
annotationSyncOptions
:
{
formatter
:
formatter
})
assert
.
called
(
AnnotationSync
)
assert
.
calledWith
(
AnnotationSync
,
{
on
:
sinon
.
match
.
func
emit
:
sinon
.
match
.
func
formatter
:
formatter
})
describe
'.pluginInit'
,
->
describe
'.pluginInit'
,
->
it
'starts the discovery of new channels'
it
'starts the discovery of new channels'
,
->
it
'creates a channel when a new frame is discovered'
bridge
=
createBridge
()
bridge
.
pluginInit
()
assert
.
called
(
fakeCFDiscovery
.
startDiscovery
)
it
'creates a channel when a new frame is discovered'
,
->
bridge
=
createBridge
()
bridge
.
pluginInit
()
fakeCFDiscovery
.
startDiscovery
.
yield
(
'SOURCE'
,
'ORIGIN'
,
'TOKEN'
)
assert
.
called
(
fakeCFBridge
.
createChannel
)
assert
.
calledWith
(
fakeCFBridge
.
createChannel
,
'SOURCE'
,
'ORIGIN'
,
'TOKEN'
)
describe
'.destroy'
,
->
describe
'.destroy'
,
->
it
'stops the discovery of new frames'
it
'stops the discovery of new frames'
,
->
bridge
=
createBridge
()
bridge
.
destroy
()
assert
.
called
(
fakeCFDiscovery
.
stopDiscovery
)
describe
'.sync'
,
->
describe
'.sync'
,
->
it
'syncs the annotations with the other frame'
it
'syncs the annotations with the other frame'
,
->
bridge
=
createBridge
()
bridge
.
sync
()
assert
.
called
(
fakeAnnotationSync
.
sync
)
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