zen_mode_spec.js.coffee 1.28 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#= 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

  # Ohmmmmmmm
  enterZen = ->
    $('.zen-toggle-comment').prop('checked', true).trigger('change')

  # Wh- what was that?!
  exitZen = ->
    $('.zen-toggle-comment').prop('checked', false).trigger('change')

  describe 'on enter', ->
    it 'pauses Mousetrap', ->
      spyOn(Mousetrap, 'pause')
      enterZen()
      expect(Mousetrap.pause).toHaveBeenCalled()

  describe 'in use', ->
    beforeEach ->
      enterZen()

    it 'exits on Escape', ->
      $(document).trigger(jQuery.Event('keydown', {keyCode: 27}))
      expect($('.zen-toggle-comment').prop('checked')).toBe(false)

  describe 'on exit', ->
    beforeEach ->
      enterZen()

    it 'unpauses Mousetrap', ->
      spyOn(Mousetrap, 'unpause')
      exitZen()
      expect(Mousetrap.unpause).toHaveBeenCalled()

    it 'restores the scroll position', ->
      spyOn(@zen, 'restoreScroll')
      exitZen()
      expect(@zen.restoreScroll).toHaveBeenCalledWith(456)