2017-01-10 18:02:20 -05:00
|
|
|
/* 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 */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Dropzone */
|
|
|
|
/* global Mousetrap */
|
|
|
|
/* global ZenMode */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
/*= require zen_mode */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var enterZen, escapeKeydown, exitZen;
|
|
|
|
|
|
|
|
describe('ZenMode', function() {
|
2016-11-22 19:25:11 -05:00
|
|
|
var fixtureName = 'issues/open-issue.html.raw';
|
2016-12-30 19:14:33 -05:00
|
|
|
preloadFixtures(fixtureName);
|
2016-07-24 16:45:11 -04:00
|
|
|
beforeEach(function() {
|
2016-12-30 19:14:33 -05:00
|
|
|
loadFixtures(fixtureName);
|
2016-07-24 16:45:11 -04:00
|
|
|
spyOn(Dropzone, 'forElement').and.callFake(function() {
|
|
|
|
return {
|
|
|
|
enable: function() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2016-07-26 23:32:10 -04:00
|
|
|
// Stub Dropzone.forElement(...).enable()
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
this.zen = new ZenMode();
|
2016-07-26 23:32:10 -04:00
|
|
|
// Set this manually because we can't actually scroll the window
|
2016-07-24 16:45:11 -04:00
|
|
|
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() {
|
2016-12-28 21:37:43 -05:00
|
|
|
$('.notes-form textarea').attr('style', 'height: 400px');
|
2016-07-24 16:45:11 -04:00
|
|
|
enterZen();
|
2016-12-28 21:37:43 -05:00
|
|
|
return expect($('.notes-form textarea')).not.toHaveAttr('style');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
describe('in use', function() {
|
|
|
|
beforeEach(function() {
|
|
|
|
return enterZen();
|
|
|
|
});
|
|
|
|
return it('exits on Escape', function() {
|
|
|
|
escapeKeydown();
|
2016-12-28 21:37:43 -05:00
|
|
|
return expect($('.notes-form .zen-backdrop')).not.toHaveClass('fullscreen');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
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() {
|
2016-12-28 21:37:43 -05:00
|
|
|
return $('.notes-form .js-zen-enter').click();
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
2016-12-29 11:19:11 -05:00
|
|
|
exitZen = function() {
|
2016-12-28 21:37:43 -05:00
|
|
|
return $('.notes-form .js-zen-leave').click();
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
escapeKeydown = function() {
|
2016-12-28 21:37:43 -05:00
|
|
|
return $('.notes-form textarea').trigger($.Event('keydown', {
|
2016-07-24 16:45:11 -04:00
|
|
|
keyCode: 27
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
}).call(this);
|