debian-mirror-gitlab/spec/frontend/ide/components/terminal/session_spec.js
2022-04-04 11:22:00 +05:30

96 lines
2.1 KiB
JavaScript

import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import Vue, { nextTick } from 'vue';
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';
Vue.use(Vuex);
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,
});
};
const findButton = () => wrapper.find(GlButton);
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();
expect(wrapper.html()).toBe('');
});
it('shows terminal', () => {
factory();
expect(wrapper.find(Terminal).props()).toEqual({
terminalPath: TEST_TERMINAL_PATH,
status: RUNNING,
});
});
[STARTING, PENDING, RUNNING].forEach((status) => {
it(`show stop button when status is ${status}`, async () => {
state.session = { status };
factory();
const button = findButton();
button.vm.$emit('click');
await nextTick();
expect(button.text()).toEqual('Stop Terminal');
expect(actions.stopSession).toHaveBeenCalled();
});
});
[STOPPING, STOPPED].forEach((status) => {
it(`show stop button when status is ${status}`, async () => {
state.session = { status };
factory();
const button = findButton();
button.vm.$emit('click');
await nextTick();
expect(button.text()).toEqual('Restart Terminal');
expect(actions.restartSession).toHaveBeenCalled();
});
});
});