2020-06-23 00:09:42 +05:30
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
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';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.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, {
|
|
|
|
localVue,
|
|
|
|
store,
|
|
|
|
...options,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
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}`, () => {
|
|
|
|
state.session = { status };
|
|
|
|
factory();
|
|
|
|
|
|
|
|
const button = wrapper.find('button');
|
|
|
|
button.trigger('click');
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(button.text()).toEqual('Stop Terminal');
|
|
|
|
expect(actions.stopSession).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
[STOPPING, STOPPED].forEach(status => {
|
|
|
|
it(`show stop button when status is ${status}`, () => {
|
|
|
|
state.session = { status };
|
|
|
|
factory();
|
|
|
|
|
|
|
|
const button = wrapper.find('button');
|
|
|
|
button.trigger('click');
|
|
|
|
|
|
|
|
return wrapper.vm.$nextTick().then(() => {
|
|
|
|
expect(button.text()).toEqual('Restart Terminal');
|
|
|
|
expect(actions.restartSession).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|