2016-11-15 14:08:06 +00:00
|
|
|
/* 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 */
|
2016-07-24 20:45:11 +00:00
|
|
|
|
|
|
|
/*= 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;
|
|
|
|
}
|
|
|
|
};
|
2016-07-27 03:32:10 +00:00
|
|
|
// Stub Dropzone.forElement(...).enable()
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
|
|
|
this.zen = new ZenMode();
|
2016-07-27 03:32:10 +00:00
|
|
|
// Set this manually because we can't actually scroll the window
|
2016-07-24 20:45:11 +00: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() {
|
|
|
|
$('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();
|
|
|
|
};
|
|
|
|
|
2016-07-27 03:32:10 +00:00
|
|
|
exitZen = function() { // Ohmmmmmmm
|
2016-07-24 20:45:11 +00:00
|
|
|
return $('a.js-zen-leave').click();
|
|
|
|
};
|
|
|
|
|
|
|
|
escapeKeydown = function() {
|
|
|
|
return $('textarea').trigger($.Event('keydown', {
|
|
|
|
keyCode: 27
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|