debian-mirror-gitlab/spec/javascripts/zen_mode_spec.js

80 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-08-17 22:00:37 +05:30
/* 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 */
/* global Dropzone */
/* global Mousetrap */
/* global ZenMode */
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
require('~/zen_mode');
2016-09-13 17:45:13 +05:30
(function() {
var enterZen, escapeKeydown, exitZen;
describe('ZenMode', function() {
2017-08-17 22:00:37 +05:30
var fixtureName = 'issues/open-issue.html.raw';
preloadFixtures(fixtureName);
2016-09-13 17:45:13 +05:30
beforeEach(function() {
2017-08-17 22:00:37 +05:30
loadFixtures(fixtureName);
2016-09-13 17:45:13 +05:30
spyOn(Dropzone, 'forElement').and.callFake(function() {
return {
enable: function() {
return true;
}
};
2016-09-29 09:46:39 +05:30
// Stub Dropzone.forElement(...).enable()
2016-09-13 17:45:13 +05:30
});
this.zen = new ZenMode();
2016-09-29 09:46:39 +05:30
// Set this manually because we can't actually scroll the window
2016-09-13 17:45:13 +05:30
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() {
2017-08-17 22:00:37 +05:30
$('.notes-form textarea').attr('style', 'height: 400px');
2016-09-13 17:45:13 +05:30
enterZen();
2017-08-17 22:00:37 +05:30
return expect($('.notes-form textarea')).not.toHaveAttr('style');
2016-09-13 17:45:13 +05:30
});
});
describe('in use', function() {
beforeEach(function() {
return enterZen();
});
return it('exits on Escape', function() {
escapeKeydown();
2017-08-17 22:00:37 +05:30
return expect($('.notes-form .zen-backdrop')).not.toHaveClass('fullscreen');
2016-09-13 17:45:13 +05:30
});
});
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() {
2017-08-17 22:00:37 +05:30
return $('.notes-form .js-zen-enter').click();
2016-09-13 17:45:13 +05:30
};
2017-08-17 22:00:37 +05:30
exitZen = function() {
return $('.notes-form .js-zen-leave').click();
2016-09-13 17:45:13 +05:30
};
escapeKeydown = function() {
2017-08-17 22:00:37 +05:30
return $('.notes-form textarea').trigger($.Event('keydown', {
2016-09-13 17:45:13 +05:30
keyCode: 27
}));
};
2017-08-17 22:00:37 +05:30
}).call(window);