2020-11-23 01:09:38 -05:00
|
|
|
import { GlButton } from '@gitlab/ui';
|
2022-01-21 10:13:54 -05:00
|
|
|
import { shallowMount } from '@vue/test-utils';
|
2022-01-25 07:14:14 -05:00
|
|
|
import Vue, { nextTick } from 'vue';
|
2020-05-29 14:08:26 -04:00
|
|
|
import Vuex from 'vuex';
|
|
|
|
import TerminalSession from '~/ide/components/terminal/session.vue';
|
|
|
|
import Terminal from '~/ide/components/terminal/terminal.vue';
|
|
|
|
import {
|
|
|
|
STARTING,
|
|
|
|
PENDING,
|
|
|
|
RUNNING,
|
|
|
|
STOPPING,
|
|
|
|
STOPPED,
|
|
|
|
} from '~/ide/stores/modules/terminal/constants';
|
|
|
|
|
|
|
|
const TEST_TERMINAL_PATH = 'terminal/path';
|
|
|
|
|
2022-01-21 10:13:54 -05:00
|
|
|
Vue.use(Vuex);
|
2020-05-29 14:08:26 -04:00
|
|
|
|
|
|
|
describe('IDE TerminalSession', () => {
|
|
|
|
let wrapper;
|
|
|
|
let actions;
|
|
|
|
let state;
|
|
|
|
|
|
|
|
const factory = (options = {}) => {
|
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
terminal: {
|
|
|
|
namespaced: true,
|
|
|
|
actions,
|
|
|
|
state,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
wrapper = shallowMount(TerminalSession, {
|
|
|
|
store,
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-08-15 05:11:06 -04:00
|
|
|
const findButton = () => wrapper.findComponent(GlButton);
|
2020-11-23 01:09:38 -05:00
|
|
|
|
2020-05-29 14:08:26 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
state = {
|
|
|
|
session: { status: RUNNING, terminalPath: TEST_TERMINAL_PATH },
|
|
|
|
};
|
|
|
|
actions = {
|
|
|
|
restartSession: jest.fn(),
|
|
|
|
stopSession: jest.fn(),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
it('is empty if session is falsey', () => {
|
|
|
|
state.session = null;
|
|
|
|
factory();
|
|
|
|
|
2020-08-25 02:10:18 -04:00
|
|
|
expect(wrapper.html()).toBe('');
|
2020-05-29 14:08:26 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows terminal', () => {
|
|
|
|
factory();
|
|
|
|
|
2022-08-15 05:11:06 -04:00
|
|
|
expect(wrapper.findComponent(Terminal).props()).toEqual({
|
2020-05-29 14:08:26 -04:00
|
|
|
terminalPath: TEST_TERMINAL_PATH,
|
|
|
|
status: RUNNING,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
[STARTING, PENDING, RUNNING].forEach((status) => {
|
2022-01-25 07:14:14 -05:00
|
|
|
it(`show stop button when status is ${status}`, async () => {
|
2020-05-29 14:08:26 -04:00
|
|
|
state.session = { status };
|
|
|
|
factory();
|
|
|
|
|
2020-11-23 01:09:38 -05:00
|
|
|
const button = findButton();
|
|
|
|
button.vm.$emit('click');
|
2020-05-29 14:08:26 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(button.text()).toEqual('Stop Terminal');
|
|
|
|
expect(actions.stopSession).toHaveBeenCalled();
|
2020-05-29 14:08:26 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
[STOPPING, STOPPED].forEach((status) => {
|
2022-01-25 07:14:14 -05:00
|
|
|
it(`show stop button when status is ${status}`, async () => {
|
2020-05-29 14:08:26 -04:00
|
|
|
state.session = { status };
|
|
|
|
factory();
|
|
|
|
|
2020-11-23 01:09:38 -05:00
|
|
|
const button = findButton();
|
|
|
|
button.vm.$emit('click');
|
2020-05-29 14:08:26 -04:00
|
|
|
|
2022-01-25 07:14:14 -05:00
|
|
|
await nextTick();
|
|
|
|
expect(button.text()).toEqual('Restart Terminal');
|
|
|
|
expect(actions.restartSession).toHaveBeenCalled();
|
2020-05-29 14:08:26 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|