BigW Consortium Gitlab

zen_mode_spec.js 2.31 KB
Newer Older
1
/* eslint-disable space-before-function-paren, no-var, one-var, one-var-declaration-per-line, object-shorthand, comma-dangle, no-return-assign, new-cap, max-len */
2 3
/* global Dropzone */
/* global Mousetrap */
Fatih Acet committed
4

5
import ZenMode from '~/zen_mode';
Fatih Acet committed
6 7 8 9 10

(function() {
  var enterZen, escapeKeydown, exitZen;

  describe('ZenMode', function() {
11
    var fixtureName = 'issues/open-issue.html.raw';
12
    preloadFixtures(fixtureName);
Fatih Acet committed
13
    beforeEach(function() {
14
      loadFixtures(fixtureName);
Fatih Acet committed
15 16 17 18 19 20
      spyOn(Dropzone, 'forElement').and.callFake(function() {
        return {
          enable: function() {
            return true;
          }
        };
21
      // Stub Dropzone.forElement(...).enable()
Fatih Acet committed
22 23
      });
      this.zen = new ZenMode();
24
      // Set this manually because we can't actually scroll the window
Fatih Acet committed
25 26 27 28 29 30 31 32 33
      return this.zen.scroll_position = 456;
    });
    describe('on enter', function() {
      it('pauses Mousetrap', function() {
        spyOn(Mousetrap, 'pause');
        enterZen();
        return expect(Mousetrap.pause).toHaveBeenCalled();
      });
      return it('removes textarea styling', function() {
34
        $('.notes-form textarea').attr('style', 'height: 400px');
Fatih Acet committed
35
        enterZen();
36
        return expect($('.notes-form textarea')).not.toHaveAttr('style');
Fatih Acet committed
37 38 39 40 41 42 43 44
      });
    });
    describe('in use', function() {
      beforeEach(function() {
        return enterZen();
      });
      return it('exits on Escape', function() {
        escapeKeydown();
45
        return expect($('.notes-form .zen-backdrop')).not.toHaveClass('fullscreen');
Fatih Acet committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
      });
    });
    return describe('on exit', function() {
      beforeEach(function() {
        return enterZen();
      });
      it('unpauses Mousetrap', function() {
        spyOn(Mousetrap, 'unpause');
        exitZen();
        return expect(Mousetrap.unpause).toHaveBeenCalled();
      });
      return it('restores the scroll position', function() {
        spyOn(this.zen, 'scrollTo');
        exitZen();
        return expect(this.zen.scrollTo).toHaveBeenCalled();
      });
    });
  });

  enterZen = function() {
66
    return $('.notes-form .js-zen-enter').click();
Fatih Acet committed
67 68
  };

69
  exitZen = function() {
70
    return $('.notes-form .js-zen-leave').click();
Fatih Acet committed
71 72 73
  };

  escapeKeydown = function() {
74
    return $('.notes-form textarea').trigger($.Event('keydown', {
Fatih Acet committed
75 76 77
      keyCode: 27
    }));
  };
78
}).call(window);