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/terminal/terminal_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/terminal/terminal_spec.js')
-rw-r--r-- | spec/frontend/ide/components/terminal/terminal_spec.js | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/spec/frontend/ide/components/terminal/terminal_spec.js b/spec/frontend/ide/components/terminal/terminal_spec.js index 3095288bb28..9cfe167d2f6 100644 --- a/spec/frontend/ide/components/terminal/terminal_spec.js +++ b/spec/frontend/ide/components/terminal/terminal_spec.js @@ -1,4 +1,5 @@ -import { createLocalVue, shallowMount } from '@vue/test-utils'; +import Vue, { nextTick } from 'vue'; +import { shallowMount } from '@vue/test-utils'; import Vuex from 'vuex'; import { GlLoadingIcon } from '@gitlab/ui'; import Terminal from '~/ide/components/terminal/terminal.vue'; @@ -14,24 +15,25 @@ import GLTerminal from '~/terminal/terminal'; const TEST_TERMINAL_PATH = 'terminal/path'; -const localVue = createLocalVue(); -localVue.use(Vuex); +Vue.use(Vuex); jest.mock('~/terminal/terminal', () => - jest.fn().mockImplementation(() => ({ - dispose: jest.fn(), - disable: jest.fn(), - addScrollListener: jest.fn(), - scrollToTop: jest.fn(), - scrollToBottom: jest.fn(), - })), + jest.fn().mockImplementation(function FakeTerminal() { + Object.assign(this, { + dispose: jest.fn(), + disable: jest.fn(), + addScrollListener: jest.fn(), + scrollToTop: jest.fn(), + scrollToBottom: jest.fn(), + }); + }), ); describe('IDE Terminal', () => { let wrapper; let state; - const factory = propsData => { + const factory = (propsData) => { const store = new Vuex.Store({ state, mutations: { @@ -41,13 +43,12 @@ describe('IDE Terminal', () => { }, }); - wrapper = shallowMount(localVue.extend(Terminal), { + wrapper = shallowMount(Terminal, { propsData: { status: RUNNING, terminalPath: TEST_TERMINAL_PATH, ...propsData, }, - localVue, store, }); }; @@ -63,7 +64,7 @@ describe('IDE Terminal', () => { }); describe('loading text', () => { - [STARTING, PENDING].forEach(status => { + [STARTING, PENDING].forEach((status) => { it(`shows when starting (${status})`, () => { factory({ status }); @@ -79,7 +80,7 @@ describe('IDE Terminal', () => { expect(wrapper.find('.top-bar').text()).toBe('Stopping...'); }); - [RUNNING, STOPPED].forEach(status => { + [RUNNING, STOPPED].forEach((status) => { it('hides when not loading', () => { factory({ status }); @@ -102,7 +103,7 @@ describe('IDE Terminal', () => { factory(); wrapper.vm.createTerminal(); - return localVue.nextTick(); + return nextTick(); }); it('is visible if terminal is created', () => { @@ -129,7 +130,7 @@ describe('IDE Terminal', () => { wrapper.setData({ canScrollUp: true, canScrollDown: true }); - return localVue.nextTick().then(() => { + return nextTick().then(() => { expect(wrapper.find(TerminalControls).props()).toEqual({ canScrollUp: true, canScrollDown: true, @@ -139,30 +140,24 @@ describe('IDE Terminal', () => { }); describe('refresh', () => { - let createTerminal; - let stopTerminal; - - beforeEach(() => { - createTerminal = jest.fn().mockName('createTerminal'); - stopTerminal = jest.fn().mockName('stopTerminal'); - }); - it('creates the terminal if running', () => { factory({ status: RUNNING, terminalPath: TEST_TERMINAL_PATH }); - wrapper.setMethods({ createTerminal }); wrapper.vm.refresh(); - expect(createTerminal).toHaveBeenCalled(); + expect(GLTerminal.mock.instances).toHaveLength(1); }); - it('stops the terminal if stopping', () => { - factory({ status: STOPPING }); + it('stops the terminal if stopping', async () => { + factory({ status: RUNNING, terminalPath: TEST_TERMINAL_PATH }); - wrapper.setMethods({ stopTerminal }); wrapper.vm.refresh(); - expect(stopTerminal).toHaveBeenCalled(); + const terminal = GLTerminal.mock.instances[0]; + wrapper.setProps({ status: STOPPING }); + await nextTick(); + + expect(terminal.disable).toHaveBeenCalled(); }); }); |