diff options
Diffstat (limited to 'spec/frontend/ide')
-rw-r--r-- | spec/frontend/ide/components/ide_spec.js | 55 | ||||
-rw-r--r-- | spec/frontend/ide/components/terminal/session_spec.js | 11 | ||||
-rw-r--r-- | spec/frontend/ide/components/terminal/view_spec.js | 18 | ||||
-rw-r--r-- | spec/frontend/ide/stores/actions/file_spec.js | 16 | ||||
-rw-r--r-- | spec/frontend/ide/utils_spec.js | 24 |
5 files changed, 48 insertions, 76 deletions
diff --git a/spec/frontend/ide/components/ide_spec.js b/spec/frontend/ide/components/ide_spec.js index ff3852b6775..315298eaf26 100644 --- a/spec/frontend/ide/components/ide_spec.js +++ b/spec/frontend/ide/components/ide_spec.js @@ -1,15 +1,8 @@ import Vuex from 'vuex'; import { createLocalVue, shallowMount } from '@vue/test-utils'; -import { GlButton, GlLoadingIcon } from '@gitlab/ui'; +import waitForPromises from 'helpers/wait_for_promises'; import { createStore } from '~/ide/stores'; import ErrorMessage from '~/ide/components/error_message.vue'; -import FindFile from '~/vue_shared/components/file_finder/index.vue'; -import CommitEditorHeader from '~/ide/components/commit_sidebar/editor_header.vue'; -import RepoTabs from '~/ide/components/repo_tabs.vue'; -import IdeStatusBar from '~/ide/components/ide_status_bar.vue'; -import RightPane from '~/ide/components/panes/right.vue'; -import NewModal from '~/ide/components/new_dropdown/modal.vue'; - import ide from '~/ide/components/ide.vue'; import { file } from '../helpers'; import { projectData } from '../mock_data'; @@ -39,17 +32,6 @@ describe('WebIDE', () => { return shallowMount(ide, { store, localVue, - stubs: { - ErrorMessage, - GlButton, - GlLoadingIcon, - CommitEditorHeader, - RepoTabs, - IdeStatusBar, - FindFile, - RightPane, - NewModal, - }, }); } @@ -74,27 +56,24 @@ describe('WebIDE', () => { describe('ide component, non-empty repo', () => { describe('error message', () => { - it('does not show error message when it is not set', () => { - wrapper = createComponent({ - state: { - errorMessage: null, - }, - }); - - expect(wrapper.find(ErrorMessage).exists()).toBe(false); - }); - - it('shows error message when set', () => { - wrapper = createComponent({ - state: { - errorMessage: { - text: 'error', + it.each` + errorMessage | exists + ${null} | ${false} + ${{ text: 'error' }} | ${true} + `( + 'should error message exists=$exists when errorMessage=$errorMessage', + async ({ errorMessage, exists }) => { + wrapper = createComponent({ + state: { + errorMessage, }, - }, - }); + }); - expect(wrapper.find(ErrorMessage).exists()).toBe(true); - }); + await waitForPromises(); + + expect(wrapper.find(ErrorMessage).exists()).toBe(exists); + }, + ); }); describe('onBeforeUnload', () => { diff --git a/spec/frontend/ide/components/terminal/session_spec.js b/spec/frontend/ide/components/terminal/session_spec.js index ce61a31691a..3ca37166ac4 100644 --- a/spec/frontend/ide/components/terminal/session_spec.js +++ b/spec/frontend/ide/components/terminal/session_spec.js @@ -1,4 +1,5 @@ import { createLocalVue, shallowMount } from '@vue/test-utils'; +import { GlButton } from '@gitlab/ui'; import Vuex from 'vuex'; import TerminalSession from '~/ide/components/terminal/session.vue'; import Terminal from '~/ide/components/terminal/terminal.vue'; @@ -38,6 +39,8 @@ describe('IDE TerminalSession', () => { }); }; + const findButton = () => wrapper.find(GlButton); + beforeEach(() => { state = { session: { status: RUNNING, terminalPath: TEST_TERMINAL_PATH }, @@ -69,8 +72,8 @@ describe('IDE TerminalSession', () => { state.session = { status }; factory(); - const button = wrapper.find('button'); - button.trigger('click'); + const button = findButton(); + button.vm.$emit('click'); return wrapper.vm.$nextTick().then(() => { expect(button.text()).toEqual('Stop Terminal'); @@ -84,8 +87,8 @@ describe('IDE TerminalSession', () => { state.session = { status }; factory(); - const button = wrapper.find('button'); - button.trigger('click'); + const button = findButton(); + button.vm.$emit('click'); return wrapper.vm.$nextTick().then(() => { expect(button.text()).toEqual('Restart Terminal'); diff --git a/spec/frontend/ide/components/terminal/view_spec.js b/spec/frontend/ide/components/terminal/view_spec.js index eff200550da..37f7957c526 100644 --- a/spec/frontend/ide/components/terminal/view_spec.js +++ b/spec/frontend/ide/components/terminal/view_spec.js @@ -1,6 +1,7 @@ import { shallowMount, createLocalVue } from '@vue/test-utils'; import Vuex from 'vuex'; import { TEST_HOST } from 'spec/test_constants'; +import waitForPromises from 'helpers/wait_for_promises'; import TerminalEmptyState from '~/ide/components/terminal/empty_state.vue'; import TerminalView from '~/ide/components/terminal/view.vue'; import TerminalSession from '~/ide/components/terminal/session.vue'; @@ -17,7 +18,7 @@ describe('IDE TerminalView', () => { let getters; let wrapper; - const factory = () => { + const factory = async () => { const store = new Vuex.Store({ modules: { terminal: { @@ -30,6 +31,9 @@ describe('IDE TerminalView', () => { }); wrapper = shallowMount(TerminalView, { localVue, store }); + + // Uses deferred components, so wait for those to load... + await waitForPromises(); }; beforeEach(() => { @@ -59,8 +63,8 @@ describe('IDE TerminalView', () => { wrapper.destroy(); }); - it('renders empty state', () => { - factory(); + it('renders empty state', async () => { + await factory(); expect(wrapper.find(TerminalEmptyState).props()).toEqual({ helpPath: TEST_HELP_PATH, @@ -69,8 +73,8 @@ describe('IDE TerminalView', () => { }); }); - it('hides splash and starts, when started', () => { - factory(); + it('hides splash and starts, when started', async () => { + await factory(); expect(actions.startSession).not.toHaveBeenCalled(); expect(actions.hideSplash).not.toHaveBeenCalled(); @@ -81,9 +85,9 @@ describe('IDE TerminalView', () => { expect(actions.hideSplash).toHaveBeenCalled(); }); - it('shows Web Terminal when started', () => { + it('shows Web Terminal when started', async () => { state.isShowSplash = false; - factory(); + await factory(); expect(wrapper.find(TerminalEmptyState).exists()).toBe(false); expect(wrapper.find(TerminalSession).exists()).toBe(true); diff --git a/spec/frontend/ide/stores/actions/file_spec.js b/spec/frontend/ide/stores/actions/file_spec.js index cc290fc526e..744ac086b5f 100644 --- a/spec/frontend/ide/stores/actions/file_spec.js +++ b/spec/frontend/ide/stores/actions/file_spec.js @@ -510,8 +510,6 @@ describe('IDE store file actions', () => { describe('changeFileContent', () => { let tmpFile; - const callAction = (content = 'content\n') => - store.dispatch('changeFileContent', { path: tmpFile.path, content }); beforeEach(() => { tmpFile = file('tmpFile'); @@ -521,11 +519,23 @@ describe('IDE store file actions', () => { }); it('updates file content', () => { - return callAction().then(() => { + const content = 'content\n'; + + return store.dispatch('changeFileContent', { path: tmpFile.path, content }).then(() => { expect(tmpFile.content).toBe('content\n'); }); }); + it('does nothing if path does not exist', () => { + const content = 'content\n'; + + return store + .dispatch('changeFileContent', { path: 'not/a/real_file.txt', content }) + .then(() => { + expect(tmpFile.content).toBe('\n'); + }); + }); + it('adds file into stagedFiles array', () => { return store .dispatch('changeFileContent', { diff --git a/spec/frontend/ide/utils_spec.js b/spec/frontend/ide/utils_spec.js index 6cd2128d356..3b772c0b259 100644 --- a/spec/frontend/ide/utils_spec.js +++ b/spec/frontend/ide/utils_spec.js @@ -4,7 +4,6 @@ import { registerLanguages, registerSchema, trimPathComponents, - insertFinalNewline, trimTrailingWhitespace, getPathParents, getPathParent, @@ -225,29 +224,6 @@ describe('WebIDE utils', () => { }); }); - describe('addFinalNewline', () => { - it.each` - input | output - ${'some text'} | ${'some text\n'} - ${'some text\n'} | ${'some text\n'} - ${'some text\n\n'} | ${'some text\n\n'} - ${'some\n text'} | ${'some\n text\n'} - `('adds a newline if it doesnt already exist for input: $input', ({ input, output }) => { - expect(insertFinalNewline(input)).toBe(output); - }); - - it.each` - input | output - ${'some text'} | ${'some text\r\n'} - ${'some text\r\n'} | ${'some text\r\n'} - ${'some text\n'} | ${'some text\n\r\n'} - ${'some text\r\n\r\n'} | ${'some text\r\n\r\n'} - ${'some\r\n text'} | ${'some\r\n text\r\n'} - `('works with CRLF newline style; input: $input', ({ input, output }) => { - expect(insertFinalNewline(input, '\r\n')).toBe(output); - }); - }); - describe('getPathParents', () => { it.each` path | parents |