BigW Consortium Gitlab

zen_mode_spec.js.coffee 1.33 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
#= 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()

24 25 26 27 28
    it 'removes textarea styling', ->
      $('textarea').attr('style', 'height: 400px')
      enterZen()
      expect('textarea').not.toHaveAttr('style')

29
  describe 'in use', ->
Robert Speicher committed
30
    beforeEach -> enterZen()
31 32

    it 'exits on Escape', ->
Robert Speicher committed
33 34
      escapeKeydown()
      expect($('.zen-backdrop')).not.toHaveClass('fullscreen')
35 36

  describe 'on exit', ->
Robert Speicher committed
37
    beforeEach -> enterZen()
38 39 40 41 42 43 44

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

    it 'restores the scroll position', ->
Robert Speicher committed
45
      spyOn(@zen, 'scrollTo')
46
      exitZen()
Robert Speicher committed
47 48 49 50 51
      expect(@zen.scrollTo).toHaveBeenCalled()

enterZen      = -> $('a.js-zen-enter').click() # Ohmmmmmmm
exitZen       = -> $('a.js-zen-leave').click()
escapeKeydown = -> $('textarea').trigger($.Event('keydown', {keyCode: 27}))