summaryrefslogtreecommitdiff
path: root/spec/javascripts/zen_mode_spec.js
blob: a18e8aee9b1e90d357f81d5e1cb360b412ef2fd0 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint-disable space-before-function-paren, no-var, one-var, one-var-declaration-per-line, no-undef, object-shorthand, comma-dangle, no-return-assign, new-cap, padded-blocks, max-len */

/*= require zen_mode */

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

  describe('ZenMode', function() {
    fixture.preload('zen_mode.html');
    beforeEach(function() {
      fixture.load('zen_mode.html');
      spyOn(Dropzone, 'forElement').and.callFake(function() {
        return {
          enable: function() {
            return true;
          }
        };
      // Stub Dropzone.forElement(...).enable()
      });
      this.zen = new ZenMode();
      // Set this manually because we can't actually scroll the window
      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() {
        $('textarea').attr('style', 'height: 400px');
        enterZen();
        return expect('textarea').not.toHaveAttr('style');
      });
    });
    describe('in use', function() {
      beforeEach(function() {
        return enterZen();
      });
      return it('exits on Escape', function() {
        escapeKeydown();
        return expect($('.zen-backdrop')).not.toHaveClass('fullscreen');
      });
    });
    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() {
    return $('a.js-zen-enter').click();
  };

  exitZen = function() { // Ohmmmmmmm
    return $('a.js-zen-leave').click();
  };

  escapeKeydown = function() {
    return $('textarea').trigger($.Event('keydown', {
      keyCode: 27
    }));
  };

}).call(this);