Commit 2a618a03 authored by Aron Carroll's avatar Aron Carroll

Add tests for remaining channel handlers

parent a68907ef
......@@ -87,10 +87,10 @@ class AnnotationSync
res
'sync': (ctx, bodies) ->
this._format(this._parse(b)) for b in bodies
(this._format(this._parse(b)) for b in bodies)
'loadAnnotations': (txn, bodies) ->
annotations = (this._parse(a) for a in annotations)
annotations = (this._parse(a) for a in bodies)
@_emit('loadAnnotations', annotations)
# Handlers for events coming from this frame, to send them across the channel
......
......@@ -144,3 +144,29 @@ describe 'AnnotationSync', ->
assert(!annSync.cache['tag1'])
describe 'on "sync" event', ->
it 'returns an array of parsed and formatted annotations', ->
options.parser = sinon.spy((x) -> x)
options.formatter = sinon.spy((x) -> x)
annSync = createAnnotationSync()
annotations = [{id: 1, $$tag: 'tag1'}, {id: 2, $$tag: 'tag2'}, {id: 3, $$tag: 'tag3'}]
bodies = ({msg: ann, tag: ann.$$tag} for ann in annotations)
ret = publish(method: 'sync', params: bodies)
assert.deepEqual(ret, ret)
assert.called(options.parser)
assert.called(options.formatter)
describe 'on "loadAnnotations" event', ->
it 'publishes the "loadAnnotations" event with parsed annotations', ->
options.parser = sinon.spy((x) -> x)
annSync = createAnnotationSync()
annotations = [{id: 1, $$tag: 'tag1'}, {id: 2, $$tag: 'tag2'}, {id: 3, $$tag: 'tag3'}]
bodies = ({msg: ann, tag: ann.$$tag} for ann in annotations)
ret = publish(method: 'loadAnnotations', params: bodies)
assert.called(options.parser)
assert.calledWith(options.emit, 'loadAnnotations', annotations)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment