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
else
this.showAnnotations annotations
# Moved from Sidebar.coffee to Guest
onElementClick: (event) ->
if !@selectedTargets?.length
@crossframe?.call('hideSidebar')
# Moved from Sidebar.coffee to Guest
onElementTouchStart: (event) ->
# Mobile browsers do not register click events on
# elements without cursor: pointer. So instead of
......
......@@ -50,6 +50,7 @@ module.exports = class Sidebar extends Host
_setupSidebarEvents: ->
annotationCounts(document.body, @crossframe)
sidebarTrigger(document.body, => this.show())
@crossframe.on('showSidebar', => this.show())
@crossframe.on('hideSidebar', => this.hide())
......
......@@ -84,6 +84,7 @@ describe 'Guest', ->
fakeCrossFrame = {
onConnect: sinon.stub()
on: sinon.stub()
call: sinon.stub()
sync: sinon.stub()
destroy: sinon.stub()
}
......@@ -277,6 +278,24 @@ describe 'Guest', ->
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', ->
it 'shows the adder if the selection contains text', ->
guest = createGuest()
......
......@@ -32,6 +32,20 @@ describe 'Sidebar', ->
emitEvent = (event, args...) ->
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', ->
it 'calls the onLoginRequest callback function if one was provided', ->
onLoginRequest = sandbox.stub()
......@@ -195,19 +209,6 @@ describe 'Sidebar', ->
sidebar.onSwipe({type: 'swiperight'})
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', ->
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