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
a68907ef
Commit
a68907ef
authored
Jan 28, 2015
by
Aron Carroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial round of tests for AnnotationSync
parent
224c213f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
0 deletions
+146
-0
annotation-sync-test.coffee
tests/js/annotation-sync-test.coffee
+146
-0
No files found.
tests/js/annotation-sync-test.coffee
0 → 100644
View file @
a68907ef
assert
=
chai
.
assert
sinon
.
assert
.
expose
(
assert
,
prefix
:
''
)
describe
'AnnotationSync'
,
->
sandbox
=
sinon
.
sandbox
.
create
()
publish
=
null
fakeBridge
=
null
createAnnotationSync
=
null
createChannel
=
->
{
notify
:
sandbox
.
stub
()}
options
=
null
PARENT_WINDOW
=
'PARENT_WINDOW'
beforeEach
module
(
'h'
)
beforeEach
inject
(
AnnotationSync
)
->
listeners
=
{}
publish
=
({
method
,
params
})
->
listeners
[
method
](
'ctx'
,
params
)
fakeWindow
=
parent
:
PARENT_WINDOW
fakeBridge
=
on
:
sandbox
.
spy
((
method
,
fn
)
->
listeners
[
method
]
=
fn
)
notify
:
sandbox
.
stub
()
onConnect
:
sandbox
.
stub
()
links
:
[
{
window
:
PARENT_WINDOW
,
channel
:
createChannel
()}
{
window
:
'ANOTHER_WINDOW'
,
channel
:
createChannel
()}
{
window
:
'THIRD_WINDOW'
,
channel
:
createChannel
()}
]
options
=
on
:
sandbox
.
stub
()
emit
:
sandbox
.
stub
()
createAnnotationSync
=
->
new
AnnotationSync
(
options
,
fakeBridge
)
afterEach
:
->
sandbox
.
restore
()
describe
'on bridge connection'
,
->
it
'sends over the current annotation cache'
,
->
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
annSync
.
cache
[
'tag1'
]
=
ann
channel
=
createChannel
()
fakeBridge
.
onConnect
.
yield
(
channel
)
assert
.
called
(
channel
.
notify
)
assert
.
calledWith
(
channel
.
notify
,
{
method
:
'loadAnnotations'
params
:
[
tag
:
'tag1'
,
msg
:
ann
]
})
it
'does nothing if the cache is empty'
,
->
annSync
=
createAnnotationSync
()
channel
=
createChannel
()
fakeBridge
.
onConnect
.
yield
(
channel
)
assert
.
notCalled
(
channel
.
notify
)
describe
'.getAnnotationForTag'
,
->
it
'returns the annotation if present in the cache'
,
->
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
annSync
.
cache
[
'tag1'
]
=
ann
cached
=
annSync
.
getAnnotationForTag
(
'tag1'
)
assert
.
equal
(
cached
,
ann
)
it
'returns null if not present in the cache'
,
->
annSync
=
createAnnotationSync
()
cached
=
annSync
.
getAnnotationForTag
(
'tag1'
)
assert
.
isNull
(
cached
)
describe
'channel event handlers'
,
->
assertBroadcast
=
(
channelEvent
,
publishEvent
)
->
it
'broadcasts the "'
+
publishEvent
+
'" event over the local event bus'
,
->
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
publish
(
method
:
channelEvent
,
params
:
{
msg
:
ann
})
assert
.
called
(
options
.
emit
)
assert
.
calledWith
(
options
.
emit
,
publishEvent
,
ann
)
assertReturnValue
=
(
channelEvent
)
->
it
'returns a formatted annotation to be sent to the calling frame'
,
->
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
ret
=
publish
(
method
:
channelEvent
,
params
:
{
msg
:
ann
})
assert
.
deepEqual
(
ret
,
{
tag
:
'tag1'
,
msg
:
ann
})
assertCacheState
=
(
channelEvent
)
->
it
'removes an existing entry from the cache before the event is triggered'
,
->
options
.
emit
=
->
assert
(
!
annSync
.
cache
[
'tag1'
])
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
annSync
.
cache
[
'tag1'
]
=
ann
publish
(
method
:
channelEvent
,
params
:
{
msg
:
ann
})
it
'ensures the annotation is inserted in the cache'
,
->
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
publish
(
method
:
channelEvent
,
params
:
{
msg
:
ann
})
assert
.
equal
(
annSync
.
cache
[
'tag1'
],
ann
)
describe
'on "beforeCreateAnnotation" event'
,
->
assertBroadcast
(
'beforeCreateAnnotation'
,
'beforeAnnotationCreated'
)
assertReturnValue
(
'beforeCreateAnnotation'
)
assertCacheState
(
'beforeCreateAnnotation'
)
describe
'on "createAnnotation" event'
,
->
assertBroadcast
(
'createAnnotation'
,
'annotationCreated'
)
assertReturnValue
(
'createAnnotation'
)
assertCacheState
(
'createAnnotation'
)
describe
'on "updateAnnotation" event'
,
->
assertBroadcast
(
'updateAnnotation'
,
'annotationUpdated'
)
assertBroadcast
(
'updateAnnotation'
,
'beforeAnnotationUpdated'
)
assertReturnValue
(
'updateAnnotation'
)
assertCacheState
(
'updateAnnotation'
)
describe
'on "deleteAnnotation" event'
,
->
assertBroadcast
(
'deleteAnnotation'
,
'annotationDeleted'
)
assertReturnValue
(
'deleteAnnotation'
)
it
'removes an existing entry from the cache before the event is triggered'
,
->
options
.
emit
=
->
assert
(
!
annSync
.
cache
[
'tag1'
])
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
annSync
.
cache
[
'tag1'
]
=
ann
publish
(
method
:
'deleteAnnotation'
,
params
:
{
msg
:
ann
})
it
'removes the annotation from the cache'
,
->
ann
=
{
id
:
1
,
$
$tag
:
'tag1'
}
annSync
=
createAnnotationSync
()
publish
(
method
:
'deleteAnnotation'
,
params
:
{
msg
:
ann
})
assert
(
!
annSync
.
cache
[
'tag1'
])
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