BigW Consortium Gitlab

zen_mode_spec.js 2.32 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 4
/* global Dropzone */
/* global Mousetrap */
/* global ZenMode */
Fatih Acet committed
5

6
import '~/zen_mode';
Fatih Acet committed
7 8 9 10 11

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

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

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

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