diff options
author | Felipe Artur <fcardozo@gitlab.com> | 2018-06-21 15:22:40 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-06-21 15:22:40 +0300 |
commit | 3e66795ef1ff1228906239763910b051d8afcc37 (patch) | |
tree | df6424d9ec008f5d1da455f8465681b371c4a11e /spec/javascripts/zen_mode_spec.js | |
parent | 14e35ac9b19d358d84e0cfd167f74036937285b6 (diff) |
Changes tab VUE refactoring
Diffstat (limited to 'spec/javascripts/zen_mode_spec.js')
-rw-r--r-- | spec/javascripts/zen_mode_spec.js | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/spec/javascripts/zen_mode_spec.js b/spec/javascripts/zen_mode_spec.js index 7fe3bd92049..bdeebe0de75 100644 --- a/spec/javascripts/zen_mode_spec.js +++ b/spec/javascripts/zen_mode_spec.js @@ -1,11 +1,12 @@ import $ from 'jquery'; -import Mousetrap from 'mousetrap'; import Dropzone from 'dropzone'; +import Mousetrap from 'mousetrap'; import ZenMode from '~/zen_mode'; describe('ZenMode', () => { let zen; - const fixtureName = 'merge_requests/merge_request_with_comment.html.raw'; + let dropzoneForElementSpy; + const fixtureName = 'snippets/show.html.raw'; preloadFixtures(fixtureName); @@ -18,15 +19,17 @@ describe('ZenMode', () => { } function escapeKeydown() { - $('.notes-form textarea').trigger($.Event('keydown', { - keyCode: 27, - })); + $('.notes-form textarea').trigger( + $.Event('keydown', { + keyCode: 27, + }), + ); } beforeEach(() => { loadFixtures(fixtureName); - spyOn(Dropzone, 'forElement').and.callFake(() => ({ + dropzoneForElementSpy = spyOn(Dropzone, 'forElement').and.callFake(() => ({ enable: () => true, })); zen = new ZenMode(); @@ -35,11 +38,29 @@ describe('ZenMode', () => { zen.scroll_position = 456; }); + 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); + }); + }); + describe('on enter', () => { it('pauses Mousetrap', () => { - spyOn(Mousetrap, 'pause'); + const mouseTrapPauseSpy = spyOn(Mousetrap, 'pause'); enterZen(); - expect(Mousetrap.pause).toHaveBeenCalled(); + expect(mouseTrapPauseSpy).toHaveBeenCalled(); }); it('removes textarea styling', () => { @@ -62,9 +83,9 @@ describe('ZenMode', () => { beforeEach(enterZen); it('unpauses Mousetrap', () => { - spyOn(Mousetrap, 'unpause'); + const mouseTrapUnpauseSpy = spyOn(Mousetrap, 'unpause'); exitZen(); - expect(Mousetrap.unpause).toHaveBeenCalled(); + expect(mouseTrapUnpauseSpy).toHaveBeenCalled(); }); it('restores the scroll position', () => { @@ -73,22 +94,4 @@ describe('ZenMode', () => { expect(zen.scrollTo).toHaveBeenCalled(); }); }); - - describe('enabling dropzone', () => { - beforeEach(() => { - enterZen(); - }); - - it('should not call dropzone if element is not dropzone valid', () => { - $('.div-dropzone').addClass('js-invalid-dropzone'); - exitZen(); - expect(Dropzone.forElement).not.toHaveBeenCalled(); - }); - - it('should call dropzone if element is dropzone valid', () => { - $('.div-dropzone').removeClass('js-invalid-dropzone'); - exitZen(); - expect(Dropzone.forElement).toHaveBeenCalled(); - }); - }); }); |