diff options
author | Phil Hughes <me@iamphill.com> | 2018-03-28 15:30:58 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-04-05 10:19:15 +0100 |
commit | f1ddfac4b0062996b9a040c9e4ab1f23e87c345a (patch) | |
tree | d8e622e43767f4f72755ce387e5c1bf9e290f985 /spec/javascripts | |
parent | 9cd0bb74aaa45cb475e48f58b155438ba7c81506 (diff) | |
download | gitlab-ce-f1ddfac4b0062996b9a040c9e4ab1f23e87c345a.tar.gz |
added specs
Diffstat (limited to 'spec/javascripts')
-rw-r--r-- | spec/javascripts/ide/components/repo_editor_spec.js | 68 | ||||
-rw-r--r-- | spec/javascripts/ide/lib/editor_spec.js | 52 |
2 files changed, 87 insertions, 33 deletions
diff --git a/spec/javascripts/ide/components/repo_editor_spec.js b/spec/javascripts/ide/components/repo_editor_spec.js index 9d3fa1280f4..de31894c185 100644 --- a/spec/javascripts/ide/components/repo_editor_spec.js +++ b/spec/javascripts/ide/components/repo_editor_spec.js @@ -149,47 +149,49 @@ describe('RepoEditor', () => { }); }); - describe('setup editor for merge request viewing', () => { - beforeEach(done => { - // Resetting as the main test setup has already done it - vm.$destroy(); - resetStore(vm.$store); - Editor.editorInstance.modelManager.dispose(); - - const f = { - ...file(), - active: true, - tempFile: true, - html: 'testing', - mrChange: { diff: 'ABC' }, - baseRaw: 'testing', - content: 'test', - }; - const RepoEditor = Vue.extend(repoEditor); - vm = createComponentWithStore(RepoEditor, store, { - file: f, - }); - - vm.$store.state.openFiles.push(f); - vm.$store.state.entries[f.path] = f; - - vm.$store.state.viewer = 'mrdiff'; + describe('editor updateDimensions', () => { + beforeEach(() => { + spyOn(vm.editor, 'updateDimensions').and.callThrough(); + spyOn(vm.editor, 'updateDiffView'); + }); - vm.monaco = true; + it('calls updateDimensions when rightPanelCollapsed is changed', done => { + vm.$store.state.rightPanelCollapsed = true; - vm.$mount(); + vm.$nextTick(() => { + expect(vm.editor.updateDimensions).toHaveBeenCalled(); + expect(vm.editor.updateDiffView).toHaveBeenCalled(); - monacoLoader(['vs/editor/editor.main'], () => { - setTimeout(done, 0); + done(); }); }); - it('attaches merge request model to editor when merge request diff', () => { - spyOn(vm.editor, 'attachMergeRequestModel').and.callThrough(); + it('calls updateDimensions when panelResizing is false', done => { + vm.$store.state.panelResizing = true; + + vm + .$nextTick() + .then(() => { + vm.$store.state.panelResizing = false; + }) + .then(vm.$nextTick) + .then(() => { + expect(vm.editor.updateDimensions).toHaveBeenCalled(); + expect(vm.editor.updateDiffView).toHaveBeenCalled(); + }) + .then(done) + .catch(done.fail); + }); - vm.setupEditor(); + it('does not call updateDimensions when panelResizing is true', done => { + vm.$store.state.panelResizing = true; - expect(vm.editor.attachMergeRequestModel).toHaveBeenCalledWith(vm.model); + vm.$nextTick(() => { + expect(vm.editor.updateDimensions).not.toHaveBeenCalled(); + expect(vm.editor.updateDiffView).not.toHaveBeenCalled(); + + done(); + }); }); }); }); diff --git a/spec/javascripts/ide/lib/editor_spec.js b/spec/javascripts/ide/lib/editor_spec.js index ec56ebc0341..5aec4b5108c 100644 --- a/spec/javascripts/ide/lib/editor_spec.js +++ b/spec/javascripts/ide/lib/editor_spec.js @@ -215,4 +215,56 @@ describe('Multi-file editor library', () => { expect(instance.decorationsController.dispose).not.toHaveBeenCalled(); }); }); + + describe('updateDiffView', () => { + describe('edit mode', () => { + it('does not update options', () => { + instance.createInstance(holder); + + spyOn(instance.instance, 'updateOptions'); + + instance.updateDiffView(); + + expect(instance.instance.updateOptions).not.toHaveBeenCalled(); + }); + }); + + describe('diff mode', () => { + beforeEach(() => { + instance.createDiffInstance(holder); + + spyOn(instance.instance, 'updateOptions').and.callThrough(); + }); + + it('sets renderSideBySide to false if el is less than 700 pixels', () => { + spyOnProperty(instance.instance.getDomNode(), 'offsetWidth').and.returnValue(600); + + expect(instance.instance.updateOptions).not.toHaveBeenCalledWith({ + renderSideBySide: false, + }); + }); + + it('sets renderSideBySide to false if el is more than 700 pixels', () => { + spyOnProperty(instance.instance.getDomNode(), 'offsetWidth').and.returnValue(800); + + expect(instance.instance.updateOptions).not.toHaveBeenCalledWith({ + renderSideBySide: true, + }); + }); + }); + }); + + describe('isDiffEditorType', () => { + it('returns true when diff editor', () => { + instance.createDiffInstance(holder); + + expect(instance.isDiffEditorType).toBe(true); + }); + + it('returns false when not diff editor', () => { + instance.createInstance(holder); + + expect(instance.isDiffEditorType).toBe(false); + }); + }); }); |