debian-mirror-gitlab/spec/frontend/ide/components/terminal/session_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

97 lines
2.1 KiB
JavaScript
Raw Normal View History

2021-02-22 17:27:13 +05:30
import { GlButton } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
2020-06-23 00:09:42 +05:30
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-04-04 11:22:00 +05:30
Vue.use(Vuex);
2020-06-23 00:09:42 +05:30
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-27 11:52:29 +05:30
const findButton = () => wrapper.findComponent(GlButton);
2021-02-22 17:27:13 +05:30
2020-06-23 00:09:42 +05:30
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-11-24 15:15:51 +05:30
expect(wrapper.html()).toBe('');
2020-06-23 00:09:42 +05:30
});
it('shows terminal', () => {
factory();
2022-08-27 11:52:29 +05:30
expect(wrapper.findComponent(Terminal).props()).toEqual({
2020-06-23 00:09:42 +05:30
terminalPath: TEST_TERMINAL_PATH,
status: RUNNING,
});
});
2021-03-08 18:12:59 +05:30
[STARTING, PENDING, RUNNING].forEach((status) => {
2022-04-04 11:22:00 +05:30
it(`show stop button when status is ${status}`, async () => {
2020-06-23 00:09:42 +05:30
state.session = { status };
factory();
2021-02-22 17:27:13 +05:30
const button = findButton();
button.vm.$emit('click');
2020-06-23 00:09:42 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(button.text()).toEqual('Stop Terminal');
expect(actions.stopSession).toHaveBeenCalled();
2020-06-23 00:09:42 +05:30
});
});
2021-03-08 18:12:59 +05:30
[STOPPING, STOPPED].forEach((status) => {
2022-04-04 11:22:00 +05:30
it(`show stop button when status is ${status}`, async () => {
2020-06-23 00:09:42 +05:30
state.session = { status };
factory();
2021-02-22 17:27:13 +05:30
const button = findButton();
button.vm.$emit('click');
2020-06-23 00:09:42 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
expect(button.text()).toEqual('Restart Terminal');
expect(actions.restartSession).toHaveBeenCalled();
2020-06-23 00:09:42 +05:30
});
});
});