Commit e0243919 authored by Aron Carroll's avatar Aron Carroll

More CrossFrameService tests

parent 98366f3d
...@@ -3,11 +3,16 @@ sinon.assert.expose assert, prefix: null ...@@ -3,11 +3,16 @@ sinon.assert.expose assert, prefix: null
describe 'CrossFrameService', -> describe 'CrossFrameService', ->
sandbox = sinon.sandbox.create() sandbox = sinon.sandbox.create()
crossframe = null
$rootScope = null $rootScope = null
$fakeDocument = null $fakeDocument = null
$fakeWindow = null $fakeWindow = null
fakeStore = null fakeStore = null
fakeAnnotationUI = null fakeAnnotationUI = null
fakeCrossFrameDiscovery = null
fakeCrossFrameBridge = null
fakeAnnotationSync = null
fakeAnnotationUISync = null
beforeEach module('h') beforeEach module('h')
beforeEach module ($provide) -> beforeEach module ($provide) ->
...@@ -15,11 +20,28 @@ describe 'CrossFrameService', -> ...@@ -15,11 +20,28 @@ describe 'CrossFrameService', ->
$fakeWindow = {} $fakeWindow = {}
fakeStore = {} fakeStore = {}
fakeAnnotationUI = {} fakeAnnotationUI = {}
fakeCrossFrameDiscovery =
startDiscovery: sandbox.stub()
fakeCrossFrameBridge =
notify: sandbox.stub()
createChannel: sandbox.stub()
onConnect: sandbox.stub()
fakeAnnotationSync = {}
fakeAnnotationUISync = {}
$provide.value('$document', $fakeDocument) $provide.value('$document', $fakeDocument)
$provide.value('$window', $fakeWindow) $provide.value('$window', $fakeWindow)
$provide.value('store', fakeStore) $provide.value('store', fakeStore)
$provide.value('annotationUI', fakeAnnotationUI) $provide.value('annotationUI', fakeAnnotationUI)
$provide.value('CrossFrameDiscovery',
sandbox.stub().returns(fakeCrossFrameDiscovery))
$provide.value('CrossFrameBridge',
sandbox.stub().returns(fakeCrossFrameBridge))
$provide.value('AnnotationSync',
sandbox.stub().returns(fakeAnnotationSync))
$provide.value('AnnotationUISync',
sandbox.stub().returns(fakeAnnotationUISync))
return # $provide returns a promise.
beforeEach inject (_$rootScope_, _crossframe_) -> beforeEach inject (_$rootScope_, _crossframe_) ->
$rootScope = _$rootScope_ $rootScope = _$rootScope_
...@@ -29,5 +51,36 @@ describe 'CrossFrameService', -> ...@@ -29,5 +51,36 @@ describe 'CrossFrameService', ->
sandbox.restore() sandbox.restore()
describe '.connect()', -> describe '.connect()', ->
it 'creates a new channel when the discovery module finds a frame', ->
fakeCrossFrameDiscovery.startDiscovery.yields('source', 'origin', 'token')
crossframe.connect()
assert.calledWith(fakeCrossFrameBridge.createChannel,
'source', 'origin', 'token')
it 'queries discovered frames for metadata', ->
info = {metadata: link: [{href: 'http://example.com'}]}
channel = {call: sandbox.stub().yieldsTo('success', info)}
fakeCrossFrameBridge.onConnect.yields(channel)
crossframe.connect()
assert.calledWith(channel.call, {
method: 'getDocumentInfo'
success: sinon.match.func
})
it 'updates the providers array', ->
info = {metadata: link: [{href: 'http://example.com'}]}
channel = {call: sandbox.stub().yieldsTo('success', info)}
fakeCrossFrameBridge.onConnect.yields(channel)
crossframe.connect()
assert.deepEqual(crossframe.providers, [
{channel: channel, entities: ['http://example.com']}
])
describe '.notify()', -> describe '.notify()', ->
it 'proxies the call to the bridge' it 'proxies the call to the bridge', ->
message = {method: 'foo', params: 'bar'}
crossframe.connect() # create the bridge.
crossframe.notify(message)
assert.calledOn(fakeCrossFrameBridge.notify, fakeCrossFrameBridge)
assert.calledWith(fakeCrossFrameBridge.notify, message)
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