Commit da77e47c authored by Juan Corona's avatar Juan Corona

Clean up & fix tests for cross frame hiding sidebar

`Sidebar` no longer handles the click/touchstart on the document itself, therefore the test for this was replaced with a
 test in `Guest`, a test for if it’s sending “hideSidebar” event via `CrossFrame` when the document is clicked
parent ba20e050
...@@ -425,12 +425,10 @@ module.exports = class Guest extends Delegator ...@@ -425,12 +425,10 @@ module.exports = class Guest extends Delegator
else else
this.showAnnotations annotations this.showAnnotations annotations
# Moved from Sidebar.coffee to Guest
onElementClick: (event) -> onElementClick: (event) ->
if !@selectedTargets?.length if !@selectedTargets?.length
@crossframe?.call('hideSidebar') @crossframe?.call('hideSidebar')
# Moved from Sidebar.coffee to Guest
onElementTouchStart: (event) -> onElementTouchStart: (event) ->
# Mobile browsers do not register click events on # Mobile browsers do not register click events on
# elements without cursor: pointer. So instead of # elements without cursor: pointer. So instead of
......
...@@ -50,6 +50,7 @@ module.exports = class Sidebar extends Host ...@@ -50,6 +50,7 @@ module.exports = class Sidebar extends Host
_setupSidebarEvents: -> _setupSidebarEvents: ->
annotationCounts(document.body, @crossframe) annotationCounts(document.body, @crossframe)
sidebarTrigger(document.body, => this.show())
@crossframe.on('showSidebar', => this.show()) @crossframe.on('showSidebar', => this.show())
@crossframe.on('hideSidebar', => this.hide()) @crossframe.on('hideSidebar', => this.hide())
......
...@@ -84,6 +84,7 @@ describe 'Guest', -> ...@@ -84,6 +84,7 @@ describe 'Guest', ->
fakeCrossFrame = { fakeCrossFrame = {
onConnect: sinon.stub() onConnect: sinon.stub()
on: sinon.stub() on: sinon.stub()
call: sinon.stub()
sync: sinon.stub() sync: sinon.stub()
destroy: sinon.stub() destroy: sinon.stub()
} }
...@@ -277,6 +278,24 @@ describe 'Guest', -> ...@@ -277,6 +278,24 @@ describe 'Guest', ->
emitGuestEvent('getDocumentInfo', assertComplete) emitGuestEvent('getDocumentInfo', assertComplete)
describe 'document events', ->
guest = null
beforeEach ->
guest = createGuest()
it 'emits "hideSidebar" on cross frame when the user taps or clicks in the page', ->
methods =
'click': 'onElementClick'
'touchstart': 'onElementTouchStart'
for event in ['click', 'touchstart']
sandbox.spy(guest, methods[event])
guest.element.trigger(event)
assert.called(guest[methods[event]])
assert.calledWith(guest.plugins.CrossFrame.call, 'hideSidebar')
describe 'when the selection changes', -> describe 'when the selection changes', ->
it 'shows the adder if the selection contains text', -> it 'shows the adder if the selection contains text', ->
guest = createGuest() guest = createGuest()
......
...@@ -32,6 +32,20 @@ describe 'Sidebar', -> ...@@ -32,6 +32,20 @@ describe 'Sidebar', ->
emitEvent = (event, args...) -> emitEvent = (event, args...) ->
fn(args...) for [evt, fn] in fakeCrossFrame.on.args when event == evt fn(args...) for [evt, fn] in fakeCrossFrame.on.args when event == evt
describe 'on "show" event', ->
it 'shows the frame', ->
target = sandbox.stub(Sidebar.prototype, 'show')
sidebar = createSidebar()
emitEvent('showSidebar')
assert.called(target)
describe 'on "hide" event', ->
it 'hides the frame', ->
target = sandbox.stub(Sidebar.prototype, 'hide')
sidebar = createSidebar()
emitEvent('hideSidebar')
assert.called(target)
describe 'on LOGIN_REQUESTED event', -> describe 'on LOGIN_REQUESTED event', ->
it 'calls the onLoginRequest callback function if one was provided', -> it 'calls the onLoginRequest callback function if one was provided', ->
onLoginRequest = sandbox.stub() onLoginRequest = sandbox.stub()
...@@ -195,19 +209,6 @@ describe 'Sidebar', -> ...@@ -195,19 +209,6 @@ describe 'Sidebar', ->
sidebar.onSwipe({type: 'swiperight'}) sidebar.onSwipe({type: 'swiperight'})
assert.calledOnce(hide) assert.calledOnce(hide)
describe 'document events', ->
sidebar = null
beforeEach ->
sidebar = createSidebar({})
it 'closes the sidebar when the user taps or clicks in the page', ->
for event in ['click', 'touchstart']
sidebar.show()
sidebar.element.trigger(event)
assert.isFalse(sidebar.isOpen())
describe 'destruction', -> describe 'destruction', ->
sidebar = null sidebar = null
......
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