diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 13:34:23 -0600 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /spec/frontend/ide/components/repo_editor_spec.js | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) | |
download | gitlab-ce-6438df3a1e0fb944485cebf07976160184697d72.tar.gz |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'spec/frontend/ide/components/repo_editor_spec.js')
-rw-r--r-- | spec/frontend/ide/components/repo_editor_spec.js | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/spec/frontend/ide/components/repo_editor_spec.js b/spec/frontend/ide/components/repo_editor_spec.js index 71a4f08cfb4..89a7f423e34 100644 --- a/spec/frontend/ide/components/repo_editor_spec.js +++ b/spec/frontend/ide/components/repo_editor_spec.js @@ -5,6 +5,7 @@ import '~/behaviors/markdown/render_gfm'; import { Range } from 'monaco-editor'; import waitForPromises from 'helpers/wait_for_promises'; import waitUsingRealTimer from 'helpers/wait_using_real_timer'; +import { createComponentWithStore } from 'helpers/vue_mount_component_helper'; import axios from '~/lib/utils/axios_utils'; import service from '~/ide/services'; import { createStoreOptions } from '~/ide/stores'; @@ -16,7 +17,6 @@ import { FILE_VIEW_MODE_PREVIEW, viewerTypes, } from '~/ide/constants'; -import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; import { file } from '../helpers'; import { exampleConfigs, exampleFiles } from '../lib/editorconfig/mock_data'; @@ -25,7 +25,7 @@ describe('RepoEditor', () => { let store; const waitForEditorSetup = () => - new Promise(resolve => { + new Promise((resolve) => { vm.$once('editorSetup', resolve); }); @@ -43,7 +43,7 @@ describe('RepoEditor', () => { vm.$mount(); }; - const createOpenFile = path => { + const createOpenFile = (path) => { const origFile = store.state.openFiles[0]; const newFile = { ...origFile, path, key: path, name: 'myfile.txt', content: 'hello world' }; @@ -91,7 +91,7 @@ describe('RepoEditor', () => { }); const findEditor = () => vm.$el.querySelector('.multi-file-editor-holder'); - const changeViewMode = viewMode => + const changeViewMode = (viewMode) => store.dispatch('editor/updateFileEditor', { path: vm.file.path, data: { viewMode } }); describe('default', () => { @@ -119,7 +119,7 @@ describe('RepoEditor', () => { expect(findEditor()).not.toHaveCss({ display: 'none' }); }); - it('renders only an edit tab', done => { + it('renders only an edit tab', (done) => { Vue.nextTick(() => { const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li'); @@ -157,7 +157,7 @@ describe('RepoEditor', () => { mock.restore(); }); - it('renders an Edit and a Preview Tab', done => { + it('renders an Edit and a Preview Tab', (done) => { Vue.nextTick(() => { const tabs = vm.$el.querySelectorAll('.ide-mode-tabs .nav-links li'); @@ -169,7 +169,7 @@ describe('RepoEditor', () => { }); }); - it('renders markdown for tempFile', done => { + it('renders markdown for tempFile', (done) => { vm.file.tempFile = true; vm.$nextTick() @@ -202,9 +202,11 @@ describe('RepoEditor', () => { }); describe('when open file is binary and not raw', () => { - beforeEach(done => { + beforeEach((done) => { vm.file.name = 'file.dat'; vm.file.content = '🐱'; // non-ascii binary content + jest.spyOn(vm.editor, 'createInstance').mockImplementation(); + jest.spyOn(vm.editor, 'createDiffInstance').mockImplementation(); vm.$nextTick(done); }); @@ -212,10 +214,20 @@ describe('RepoEditor', () => { it('does not render the IDE', () => { expect(vm.shouldHideEditor).toBeTruthy(); }); + + it('does not call createInstance', async () => { + // Mirror the act's in the `createEditorInstance` + vm.createEditorInstance(); + + await vm.$nextTick(); + + expect(vm.editor.createInstance).not.toHaveBeenCalled(); + expect(vm.editor.createDiffInstance).not.toHaveBeenCalled(); + }); }); describe('createEditorInstance', () => { - it('calls createInstance when viewer is editor', done => { + it('calls createInstance when viewer is editor', (done) => { jest.spyOn(vm.editor, 'createInstance').mockImplementation(); vm.createEditorInstance(); @@ -227,7 +239,7 @@ describe('RepoEditor', () => { }); }); - it('calls createDiffInstance when viewer is diff', done => { + it('calls createDiffInstance when viewer is diff', (done) => { vm.$store.state.viewer = 'diff'; jest.spyOn(vm.editor, 'createDiffInstance').mockImplementation(); @@ -241,7 +253,7 @@ describe('RepoEditor', () => { }); }); - it('calls createDiffInstance when viewer is a merge request diff', done => { + it('calls createDiffInstance when viewer is a merge request diff', (done) => { vm.$store.state.viewer = 'mrdiff'; jest.spyOn(vm.editor, 'createDiffInstance').mockImplementation(); @@ -342,7 +354,7 @@ describe('RepoEditor', () => { jest.spyOn(vm.editor, 'updateDiffView').mockImplementation(); }); - it('calls updateDimensions when panelResizing is false', done => { + it('calls updateDimensions when panelResizing is false', (done) => { vm.$store.state.panelResizing = true; vm.$nextTick() @@ -358,7 +370,7 @@ describe('RepoEditor', () => { .catch(done.fail); }); - it('does not call updateDimensions when panelResizing is true', done => { + it('does not call updateDimensions when panelResizing is true', (done) => { vm.$store.state.panelResizing = true; vm.$nextTick(() => { @@ -369,7 +381,7 @@ describe('RepoEditor', () => { }); }); - it('calls updateDimensions when rightPane is opened', done => { + it('calls updateDimensions when rightPane is opened', (done) => { vm.$store.state.rightPane.isOpen = true; vm.$nextTick(() => { @@ -386,7 +398,7 @@ describe('RepoEditor', () => { expect(vm.$el.querySelector('.nav-links')).not.toBe(null); }); - it('hides tabs in review mode', done => { + it('hides tabs in review mode', (done) => { vm.$store.state.currentActivityView = leftSidebarViews.review.name; vm.$nextTick(() => { @@ -396,7 +408,7 @@ describe('RepoEditor', () => { }); }); - it('hides tabs in commit mode', done => { + it('hides tabs in commit mode', (done) => { vm.$store.state.currentActivityView = leftSidebarViews.commit.name; vm.$nextTick(() => { @@ -408,7 +420,7 @@ describe('RepoEditor', () => { }); describe('when files view mode is preview', () => { - beforeEach(done => { + beforeEach((done) => { jest.spyOn(vm.editor, 'updateDimensions').mockImplementation(); changeViewMode(FILE_VIEW_MODE_PREVIEW); vm.file.name = 'myfile.md'; @@ -440,7 +452,7 @@ describe('RepoEditor', () => { jest.spyOn(vm, 'shouldHideEditor', 'get').mockReturnValue(true); }); - it('does not fetch file information for temp entries', done => { + it('does not fetch file information for temp entries', (done) => { vm.file.tempFile = true; vm.initEditor(); @@ -452,7 +464,7 @@ describe('RepoEditor', () => { .catch(done.fail); }); - it('is being initialised for files without content even if shouldHideEditor is `true`', done => { + it('is being initialised for files without content even if shouldHideEditor is `true`', (done) => { vm.file.content = ''; vm.file.raw = ''; @@ -467,7 +479,7 @@ describe('RepoEditor', () => { .catch(done.fail); }); - it('does not initialize editor for files already with content', done => { + it('does not initialize editor for files already with content', (done) => { vm.file.content = 'foo'; vm.initEditor(); @@ -487,7 +499,7 @@ describe('RepoEditor', () => { jest.spyOn(vm, 'initEditor').mockImplementation(); }); - it('calls removePendingTab when old file is pending', done => { + it('calls removePendingTab when old file is pending', (done) => { jest.spyOn(vm, 'shouldHideEditor', 'get').mockReturnValue(true); jest.spyOn(vm, 'removePendingTab').mockImplementation(); @@ -507,7 +519,7 @@ describe('RepoEditor', () => { .catch(done.fail); }); - it('does not call initEditor if the file did not change', done => { + it('does not call initEditor if the file did not change', (done) => { Vue.set(vm, 'file', vm.file); vm.$nextTick() @@ -518,7 +530,7 @@ describe('RepoEditor', () => { .catch(done.fail); }); - it('calls initEditor when file key is changed', done => { + it('calls initEditor when file key is changed', (done) => { expect(vm.initEditor).not.toHaveBeenCalled(); Vue.set(vm, 'file', { @@ -540,7 +552,7 @@ describe('RepoEditor', () => { vm.getRawFileData.mockRestore(); }); - const createRemoteFile = name => ({ + const createRemoteFile = (name) => ({ ...file(name), tmpFile: false, }); @@ -593,7 +605,7 @@ describe('RepoEditor', () => { }); describe('onPaste', () => { - const setFileName = name => { + const setFileName = (name) => { Vue.set(vm, 'file', { ...vm.file, content: 'hello world\n', @@ -615,8 +627,8 @@ describe('RepoEditor', () => { ); }; - const watchState = watched => - new Promise(resolve => { + const watchState = (watched) => + new Promise((resolve) => { const unwatch = vm.$store.watch(watched, () => { unwatch(); resolve(); @@ -626,7 +638,7 @@ describe('RepoEditor', () => { // Pasting an image does a lot of things like using the FileReader API, // so, waitForPromises isn't very reliable (and causes a flaky spec) // Read more about state.watch: https://vuex.vuejs.org/api/#watch - const waitForFileContentChange = () => watchState(s => s.entries['foo/bar.md'].content); + const waitForFileContentChange = () => watchState((s) => s.entries['foo/bar.md'].content); beforeEach(() => { setFileName('bar.md'); |