BigW Consortium Gitlab

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

6 7
require('./spec_helper');
require('zen_mode');
Fatih Acet committed
8 9 10 11 12

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

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

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

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

}).call(this);