2015-05-21 01:25:18 -04:00
|
|
|
#= require zen_mode
|
|
|
|
|
|
|
|
describe 'ZenMode', ->
|
|
|
|
fixture.preload('zen_mode.html')
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
fixture.load('zen_mode.html')
|
|
|
|
|
|
|
|
# Stub Dropzone.forElement(...).enable()
|
|
|
|
spyOn(Dropzone, 'forElement').and.callFake ->
|
|
|
|
enable: -> true
|
|
|
|
|
|
|
|
@zen = new ZenMode()
|
|
|
|
|
|
|
|
# Set this manually because we can't actually scroll the window
|
|
|
|
@zen.scroll_position = 456
|
|
|
|
|
|
|
|
describe 'on enter', ->
|
|
|
|
it 'pauses Mousetrap', ->
|
|
|
|
spyOn(Mousetrap, 'pause')
|
|
|
|
enterZen()
|
|
|
|
expect(Mousetrap.pause).toHaveBeenCalled()
|
|
|
|
|
2015-09-04 16:35:01 -04:00
|
|
|
it 'removes textarea styling', ->
|
|
|
|
$('textarea').attr('style', 'height: 400px')
|
|
|
|
enterZen()
|
|
|
|
expect('textarea').not.toHaveAttr('style')
|
|
|
|
|
2015-05-21 01:25:18 -04:00
|
|
|
describe 'in use', ->
|
2016-01-08 23:33:08 -05:00
|
|
|
beforeEach -> enterZen()
|
2015-05-21 01:25:18 -04:00
|
|
|
|
|
|
|
it 'exits on Escape', ->
|
2016-01-08 23:33:08 -05:00
|
|
|
escapeKeydown()
|
|
|
|
expect($('.zen-backdrop')).not.toHaveClass('fullscreen')
|
2015-05-21 01:25:18 -04:00
|
|
|
|
|
|
|
describe 'on exit', ->
|
2016-01-08 23:33:08 -05:00
|
|
|
beforeEach -> enterZen()
|
2015-05-21 01:25:18 -04:00
|
|
|
|
|
|
|
it 'unpauses Mousetrap', ->
|
|
|
|
spyOn(Mousetrap, 'unpause')
|
|
|
|
exitZen()
|
|
|
|
expect(Mousetrap.unpause).toHaveBeenCalled()
|
|
|
|
|
|
|
|
it 'restores the scroll position', ->
|
2016-01-08 23:33:08 -05:00
|
|
|
spyOn(@zen, 'scrollTo')
|
2015-05-21 01:25:18 -04:00
|
|
|
exitZen()
|
2016-01-08 23:33:08 -05:00
|
|
|
expect(@zen.scrollTo).toHaveBeenCalled()
|
|
|
|
|
|
|
|
enterZen = -> $('a.js-zen-enter').click() # Ohmmmmmmm
|
|
|
|
exitZen = -> $('a.js-zen-leave').click()
|
|
|
|
escapeKeydown = -> $('textarea').trigger($.Event('keydown', {keyCode: 27}))
|