2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-10-19 03:45:52 -04:00
|
|
|
import Dropzone from 'dropzone';
|
2018-06-21 08:22:40 -04:00
|
|
|
import Mousetrap from 'mousetrap';
|
2017-06-30 17:37:31 -04:00
|
|
|
import ZenMode from '~/zen_mode';
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2017-11-22 18:20:23 -05:00
|
|
|
describe('ZenMode', () => {
|
|
|
|
let zen;
|
2018-06-21 08:22:40 -04:00
|
|
|
let dropzoneForElementSpy;
|
|
|
|
const fixtureName = 'snippets/show.html.raw';
|
2017-11-22 18:20:23 -05:00
|
|
|
|
|
|
|
preloadFixtures(fixtureName);
|
|
|
|
|
|
|
|
function enterZen() {
|
|
|
|
$('.notes-form .js-zen-enter').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
function exitZen() {
|
|
|
|
$('.notes-form .js-zen-leave').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
function escapeKeydown() {
|
2018-06-21 08:22:40 -04:00
|
|
|
$('.notes-form textarea').trigger(
|
|
|
|
$.Event('keydown', {
|
|
|
|
keyCode: 27,
|
|
|
|
}),
|
|
|
|
);
|
2017-11-22 18:20:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
loadFixtures(fixtureName);
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
dropzoneForElementSpy = spyOn(Dropzone, 'forElement').and.callFake(() => ({
|
2017-11-22 18:20:23 -05:00
|
|
|
enable: () => true,
|
|
|
|
}));
|
|
|
|
zen = new ZenMode();
|
|
|
|
|
|
|
|
// Set this manually because we can't actually scroll the window
|
|
|
|
zen.scroll_position = 456;
|
|
|
|
});
|
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
describe('enabling dropzone', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
enterZen();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not call dropzone if element is not dropzone valid', () => {
|
|
|
|
$('.div-dropzone').addClass('js-invalid-dropzone');
|
|
|
|
exitZen();
|
|
|
|
expect(dropzoneForElementSpy.calls.count()).toEqual(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should call dropzone if element is dropzone valid', () => {
|
|
|
|
$('.div-dropzone').removeClass('js-invalid-dropzone');
|
|
|
|
exitZen();
|
|
|
|
expect(dropzoneForElementSpy.calls.count()).toEqual(2);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-11-22 18:20:23 -05:00
|
|
|
describe('on enter', () => {
|
|
|
|
it('pauses Mousetrap', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
const mouseTrapPauseSpy = spyOn(Mousetrap, 'pause');
|
2017-11-22 18:20:23 -05:00
|
|
|
enterZen();
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(mouseTrapPauseSpy).toHaveBeenCalled();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-11-22 18:20:23 -05:00
|
|
|
|
|
|
|
it('removes textarea styling', () => {
|
|
|
|
$('.notes-form textarea').attr('style', 'height: 400px');
|
|
|
|
enterZen();
|
|
|
|
expect($('.notes-form textarea')).not.toHaveAttr('style');
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-11-22 18:20:23 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('in use', () => {
|
|
|
|
beforeEach(enterZen);
|
|
|
|
|
|
|
|
it('exits on Escape', () => {
|
|
|
|
escapeKeydown();
|
|
|
|
expect($('.notes-form .zen-backdrop')).not.toHaveClass('fullscreen');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('on exit', () => {
|
|
|
|
beforeEach(enterZen);
|
|
|
|
|
|
|
|
it('unpauses Mousetrap', () => {
|
2018-06-21 08:22:40 -04:00
|
|
|
const mouseTrapUnpauseSpy = spyOn(Mousetrap, 'unpause');
|
2017-11-22 18:20:23 -05:00
|
|
|
exitZen();
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(mouseTrapUnpauseSpy).toHaveBeenCalled();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-11-22 18:20:23 -05:00
|
|
|
|
|
|
|
it('restores the scroll position', () => {
|
|
|
|
spyOn(zen, 'scrollTo');
|
|
|
|
exitZen();
|
|
|
|
expect(zen.scrollTo).toHaveBeenCalled();
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
|
|
|
});
|
2017-11-22 18:20:23 -05:00
|
|
|
});
|