Commit cf597f08 authored by Mark Florian's avatar Mark Florian

Merge branch 'vs-migrate-ide-to-jest' into 'master'

Migrate ee/ide to Jest

Closes #194288

See merge request gitlab-org/gitlab!28437
parents 89003fb3 90b68e62
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { shallowMount } from '@vue/test-utils';
import { GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'spec/test_constants';
import TerminalEmptyState from 'ee/ide/components/terminal/empty_state.vue';
......@@ -11,10 +11,7 @@ describe('EE IDE TerminalEmptyState', () => {
let wrapper;
const factory = (options = {}) => {
const localVue = createLocalVue();
wrapper = shallowMount(localVue.extend(TerminalEmptyState), {
localVue,
wrapper = shallowMount(TerminalEmptyState, {
...options,
});
};
......
......@@ -4,16 +4,26 @@ import { GlLoadingIcon } from '@gitlab/ui';
import Terminal from 'ee/ide/components/terminal/terminal.vue';
import TerminalControls from 'ee/ide/components/terminal/terminal_controls.vue';
import { STARTING, PENDING, RUNNING, STOPPING, STOPPED } from 'ee/ide/constants';
import GLTerminal from '~/terminal/terminal';
const TEST_TERMINAL_PATH = 'terminal/path';
const localVue = createLocalVue();
localVue.use(Vuex);
jest.mock('~/terminal/terminal', () =>
jest.fn().mockImplementation(() => ({
dispose: jest.fn(),
disable: jest.fn(),
addScrollListener: jest.fn(),
scrollToTop: jest.fn(),
scrollToBottom: jest.fn(),
})),
);
describe('EE IDE Terminal', () => {
let wrapper;
let state;
let GLTerminalSpy;
const factory = propsData => {
const store = new Vuex.Store({
......@@ -37,15 +47,6 @@ describe('EE IDE Terminal', () => {
};
beforeEach(() => {
GLTerminalSpy = spyOnDependency(Terminal, 'GLTerminal').and.returnValue(
jasmine.createSpyObj('GLTerminal', [
'dispose',
'disable',
'addScrollListener',
'scrollToTop',
'scrollToBottom',
]),
);
state = {
panelResizing: false,
};
......@@ -91,10 +92,11 @@ describe('EE IDE Terminal', () => {
});
describe('terminal controls', () => {
beforeEach(done => {
beforeEach(() => {
factory();
wrapper.vm.createTerminal();
localVue.nextTick(done);
return localVue.nextTick();
});
it('is visible if terminal is created', () => {
......@@ -113,7 +115,7 @@ describe('EE IDE Terminal', () => {
expect(wrapper.vm.glterminal.scrollToBottom).toHaveBeenCalled();
});
it('has props set', done => {
it('has props set', () => {
expect(wrapper.find(TerminalControls).props()).toEqual({
canScrollUp: false,
canScrollDown: false,
......@@ -121,16 +123,12 @@ describe('EE IDE Terminal', () => {
wrapper.setData({ canScrollUp: true, canScrollDown: true });
localVue
.nextTick()
.then(() => {
expect(wrapper.find(TerminalControls).props()).toEqual({
canScrollUp: true,
canScrollDown: true,
});
})
.then(done)
.catch(done.fail);
return localVue.nextTick().then(() => {
expect(wrapper.find(TerminalControls).props()).toEqual({
canScrollUp: true,
canScrollDown: true,
});
});
});
});
......@@ -139,8 +137,8 @@ describe('EE IDE Terminal', () => {
let stopTerminal;
beforeEach(() => {
createTerminal = jasmine.createSpy('createTerminal');
stopTerminal = jasmine.createSpy('stopTerminal');
createTerminal = jest.fn().mockName('createTerminal');
stopTerminal = jest.fn().mockName('stopTerminal');
});
it('creates the terminal if running', () => {
......@@ -169,7 +167,7 @@ describe('EE IDE Terminal', () => {
});
it('creates the terminal', () => {
expect(GLTerminalSpy).toHaveBeenCalledWith(wrapper.vm.$refs.terminal);
expect(GLTerminal).toHaveBeenCalledWith(wrapper.vm.$refs.terminal);
expect(wrapper.vm.glterminal).toBeTruthy();
});
......@@ -182,7 +180,7 @@ describe('EE IDE Terminal', () => {
expect(wrapper.vm.canScrollUp).toBe(false);
expect(wrapper.vm.canScrollDown).toBe(false);
const listener = wrapper.vm.glterminal.addScrollListener.calls.argsFor(0)[0];
const listener = wrapper.vm.glterminal.addScrollListener.mock.calls[0][0];
listener({ canScrollUp: true, canScrollDown: true });
expect(wrapper.vm.canScrollUp).toBe(true);
......
......@@ -29,7 +29,7 @@ describe('EE IDE TerminalView', () => {
},
});
wrapper = shallowMount(localVue.extend(TerminalView), { localVue, store });
wrapper = shallowMount(TerminalView, { localVue, store });
};
beforeEach(() => {
......@@ -42,8 +42,8 @@ describe('EE IDE TerminalView', () => {
};
actions = {
hideSplash: jasmine.createSpy('hideSplash'),
startSession: jasmine.createSpy('startSession'),
hideSplash: jest.fn().mockName('hideSplash'),
startSession: jest.fn().mockName('startSession'),
};
getters = {
......
import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper';
import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'spec/test_constants';
import { CHECK_CONFIG, CHECK_RUNNERS, RETRY_RUNNERS_INTERVAL } from 'ee/ide/constants';
import * as mutationTypes from 'ee/ide/stores/modules/terminal/mutation_types';
......@@ -39,30 +39,27 @@ describe('EE IDE store terminal check actions', () => {
path_with_namespace: TEST_PROJECT_PATH,
},
};
jasmine.clock().install();
});
afterEach(() => {
mock.restore();
jasmine.clock().uninstall();
});
describe('requestConfigCheck', () => {
it('handles request loading', done => {
testAction(
it('handles request loading', () => {
return testAction(
actions.requestConfigCheck,
null,
{},
[{ type: mutationTypes.REQUEST_CHECK, payload: CHECK_CONFIG }],
[],
done,
);
});
});
describe('receiveConfigCheckSuccess', () => {
it('handles successful response', done => {
testAction(
it('handles successful response', () => {
return testAction(
actions.receiveConfigCheckSuccess,
null,
{},
......@@ -71,17 +68,16 @@ describe('EE IDE store terminal check actions', () => {
{ type: mutationTypes.RECEIVE_CHECK_SUCCESS, payload: CHECK_CONFIG },
],
[],
done,
);
});
});
describe('receiveConfigCheckError', () => {
it('handles error response', done => {
it('handles error response', () => {
const status = httpStatus.UNPROCESSABLE_ENTITY;
const payload = { response: { status } };
testAction(
return testAction(
actions.receiveConfigCheckError,
payload,
state,
......@@ -99,15 +95,14 @@ describe('EE IDE store terminal check actions', () => {
},
],
[],
done,
);
});
[httpStatus.FORBIDDEN, httpStatus.NOT_FOUND].forEach(status => {
it(`hides tab, when status is ${status}`, done => {
it(`hides tab, when status is ${status}`, () => {
const payload = { response: { status } };
testAction(
return testAction(
actions.receiveConfigCheckError,
payload,
state,
......@@ -116,20 +111,19 @@ describe('EE IDE store terminal check actions', () => {
type: mutationTypes.SET_VISIBLE,
payload: false,
},
jasmine.objectContaining({ type: mutationTypes.RECEIVE_CHECK_ERROR }),
expect.objectContaining({ type: mutationTypes.RECEIVE_CHECK_ERROR }),
],
[],
done,
);
});
});
});
describe('fetchConfigCheck', () => {
it('dispatches request and receive', done => {
it('dispatches request and receive', () => {
mock.onPost(/.*\/ide_terminals\/check_config/).reply(200, {});
testAction(
return testAction(
actions.fetchConfigCheck,
null,
{
......@@ -138,14 +132,13 @@ describe('EE IDE store terminal check actions', () => {
},
[],
[{ type: 'requestConfigCheck' }, { type: 'receiveConfigCheckSuccess' }],
done,
);
});
it('when error, dispatches request and receive', done => {
it('when error, dispatches request and receive', () => {
mock.onPost(/.*\/ide_terminals\/check_config/).reply(400, {});
testAction(
return testAction(
actions.fetchConfigCheck,
null,
{
......@@ -155,90 +148,85 @@ describe('EE IDE store terminal check actions', () => {
[],
[
{ type: 'requestConfigCheck' },
{ type: 'receiveConfigCheckError', payload: jasmine.any(Error) },
{ type: 'receiveConfigCheckError', payload: expect.any(Error) },
],
done,
);
});
});
describe('requestRunnersCheck', () => {
it('handles request loading', done => {
testAction(
it('handles request loading', () => {
return testAction(
actions.requestRunnersCheck,
null,
{},
[{ type: mutationTypes.REQUEST_CHECK, payload: CHECK_RUNNERS }],
[],
done,
);
});
});
describe('receiveRunnersCheckSuccess', () => {
it('handles successful response, with data', done => {
it('handles successful response, with data', () => {
const payload = [{}];
testAction(
return testAction(
actions.receiveRunnersCheckSuccess,
payload,
state,
[{ type: mutationTypes.RECEIVE_CHECK_SUCCESS, payload: CHECK_RUNNERS }],
[],
done,
);
});
it('handles successful response, with empty data', done => {
it('handles successful response, with empty data', () => {
const commitPayload = {
type: CHECK_RUNNERS,
message: messages.runnersCheckEmpty(TEST_RUNNERS_HELP_PATH),
};
testAction(
return testAction(
actions.receiveRunnersCheckSuccess,
[],
state,
[{ type: mutationTypes.RECEIVE_CHECK_ERROR, payload: commitPayload }],
[{ type: 'retryRunnersCheck' }],
done,
);
});
});
describe('receiveRunnersCheckError', () => {
it('dispatches handle with message', done => {
it('dispatches handle with message', () => {
const commitPayload = {
type: CHECK_RUNNERS,
message: messages.UNEXPECTED_ERROR_RUNNERS,
};
testAction(
return testAction(
actions.receiveRunnersCheckError,
null,
{},
[{ type: mutationTypes.RECEIVE_CHECK_ERROR, payload: commitPayload }],
[],
done,
);
});
});
describe('retryRunnersCheck', () => {
it('dispatches fetch again after timeout', () => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
actions.retryRunnersCheck({ dispatch, state });
expect(dispatch).not.toHaveBeenCalled();
jasmine.clock().tick(RETRY_RUNNERS_INTERVAL + 1);
jest.advanceTimersByTime(RETRY_RUNNERS_INTERVAL + 1);
expect(dispatch).toHaveBeenCalledWith('fetchRunnersCheck', { background: true });
});
it('does not dispatch fetch if config check is error', () => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
state.checks.config = {
isLoading: false,
isValid: false,
......@@ -248,52 +236,49 @@ describe('EE IDE store terminal check actions', () => {
expect(dispatch).not.toHaveBeenCalled();
jasmine.clock().tick(RETRY_RUNNERS_INTERVAL + 1);
jest.advanceTimersByTime(RETRY_RUNNERS_INTERVAL + 1);
expect(dispatch).not.toHaveBeenCalled();
});
});
describe('fetchRunnersCheck', () => {
it('dispatches request and receive', done => {
it('dispatches request and receive', () => {
mock.onGet(/api\/.*\/projects\/.*\/runners/, { params: { scope: 'active' } }).reply(200, []);
testAction(
return testAction(
actions.fetchRunnersCheck,
{},
rootGetters,
[],
[{ type: 'requestRunnersCheck' }, { type: 'receiveRunnersCheckSuccess', payload: [] }],
done,
);
});
it('does not dispatch request when background is true', done => {
it('does not dispatch request when background is true', () => {
mock.onGet(/api\/.*\/projects\/.*\/runners/, { params: { scope: 'active' } }).reply(200, []);
testAction(
return testAction(
actions.fetchRunnersCheck,
{ background: true },
rootGetters,
[],
[{ type: 'receiveRunnersCheckSuccess', payload: [] }],
done,
);
});
it('dispatches request and receive, when error', done => {
it('dispatches request and receive, when error', () => {
mock.onGet(/api\/.*\/projects\/.*\/runners/, { params: { scope: 'active' } }).reply(500, []);
testAction(
return testAction(
actions.fetchRunnersCheck,
{},
rootGetters,
[],
[
{ type: 'requestRunnersCheck' },
{ type: 'receiveRunnersCheckError', payload: jasmine.any(Error) },
{ type: 'receiveRunnersCheckError', payload: expect.any(Error) },
],
done,
);
});
});
......
import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper';
import testAction from 'helpers/vuex_action_helper';
import { STARTING, PENDING, STOPPING, STOPPED } from 'ee/ide/constants';
import * as messages from 'ee/ide/stores/modules/terminal/messages';
import * as mutationTypes from 'ee/ide/stores/modules/terminal/mutation_types';
import actionsModule, * as actions from 'ee/ide/stores/modules/terminal/actions/session_controls';
import * as actions from 'ee/ide/stores/modules/terminal/actions/session_controls';
import httpStatus from '~/lib/utils/http_status';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
jest.mock('~/flash');
const TEST_PROJECT_PATH = 'lorem/root';
const TEST_BRANCH_ID = 'master';
......@@ -25,11 +28,10 @@ describe('EE IDE store terminal session controls actions', () => {
let dispatch;
let rootState;
let rootGetters;
let flashSpy;
beforeEach(() => {
mock = new MockAdapter(axios);
dispatch = jasmine.createSpy('dispatch');
dispatch = jest.fn().mockName('dispatch');
rootState = {
currentBranchId: TEST_BRANCH_ID,
};
......@@ -39,7 +41,6 @@ describe('EE IDE store terminal session controls actions', () => {
path_with_namespace: TEST_PROJECT_PATH,
},
};
flashSpy = spyOnDependency(actionsModule, 'flash');
});
afterEach(() => {
......@@ -47,21 +48,20 @@ describe('EE IDE store terminal session controls actions', () => {
});
describe('requestStartSession', () => {
it('sets session status', done => {
testAction(
it('sets session status', () => {
return testAction(
actions.requestStartSession,
null,
{},
[{ type: mutationTypes.SET_SESSION_STATUS, payload: STARTING }],
[],
done,
);
});
});
describe('receiveStartSessionSuccess', () => {
it('sets session and starts polling status', done => {
testAction(
it('sets session and starts polling status', () => {
return testAction(
actions.receiveStartSessionSuccess,
TEST_SESSION,
{},
......@@ -81,7 +81,6 @@ describe('EE IDE store terminal session controls actions', () => {
},
],
[{ type: 'pollSessionStatus' }],
done,
);
});
});
......@@ -90,11 +89,11 @@ describe('EE IDE store terminal session controls actions', () => {
it('flashes message', () => {
actions.receiveStartSessionError({ dispatch });
expect(flashSpy).toHaveBeenCalledWith(messages.UNEXPECTED_ERROR_STARTING);
expect(createFlash).toHaveBeenCalledWith(messages.UNEXPECTED_ERROR_STARTING);
});
it('sets session status', done => {
testAction(actions.receiveStartSessionError, null, {}, [], [{ type: 'killSession' }], done);
it('sets session status', () => {
return testAction(actions.receiveStartSessionError, null, {}, [], [{ type: 'killSession' }]);
});
});
......@@ -109,10 +108,10 @@ describe('EE IDE store terminal session controls actions', () => {
expect(dispatch).not.toHaveBeenCalled();
});
it('dispatches request and receive on success', done => {
it('dispatches request and receive on success', () => {
mock.onPost(/.*\/ide_terminals/).reply(200, TEST_SESSION);
testAction(
return testAction(
actions.startSession,
null,
{ ...rootGetters, ...rootState },
......@@ -121,14 +120,13 @@ describe('EE IDE store terminal session controls actions', () => {
{ type: 'requestStartSession' },
{ type: 'receiveStartSessionSuccess', payload: TEST_SESSION },
],
done,
);
});
it('dispatches request and receive on error', done => {
it('dispatches request and receive on error', () => {
mock.onPost(/.*\/ide_terminals/).reply(400);
testAction(
return testAction(
actions.startSession,
null,
{ ...rootGetters, ...rootState },
......@@ -137,27 +135,25 @@ describe('EE IDE store terminal session controls actions', () => {
{ type: 'requestStartSession' },
{ type: 'receiveStartSessionError', payload: jasmine.any(Error) },
],
done,
);
});
});
describe('requestStopSession', () => {
it('sets session status', done => {
testAction(
it('sets session status', () => {
return testAction(
actions.requestStopSession,
null,
{},
[{ type: mutationTypes.SET_SESSION_STATUS, payload: STOPPING }],
[],
done,
);
});
});
describe('receiveStopSessionSuccess', () => {
it('kills the session', done => {
testAction(actions.receiveStopSessionSuccess, null, {}, [], [{ type: 'killSession' }], done);
it('kills the session', () => {
return testAction(actions.receiveStopSessionSuccess, null, {}, [], [{ type: 'killSession' }]);
});
});
......@@ -165,40 +161,39 @@ describe('EE IDE store terminal session controls actions', () => {
it('flashes message', () => {
actions.receiveStopSessionError({ dispatch });
expect(flashSpy).toHaveBeenCalledWith(messages.UNEXPECTED_ERROR_STOPPING);
expect(createFlash).toHaveBeenCalledWith(messages.UNEXPECTED_ERROR_STOPPING);
});
it('kills the session', done => {
testAction(actions.receiveStopSessionError, null, {}, [], [{ type: 'killSession' }], done);
it('kills the session', () => {
return testAction(actions.receiveStopSessionError, null, {}, [], [{ type: 'killSession' }]);
});
});
describe('stopSession', () => {
it('dispatches request and receive on success', done => {
it('dispatches request and receive on success', () => {
mock.onPost(TEST_SESSION.cancel_path).reply(200, {});
const state = {
session: { cancelPath: TEST_SESSION.cancel_path },
};
testAction(
return testAction(
actions.stopSession,
null,
state,
[],
[{ type: 'requestStopSession' }, { type: 'receiveStopSessionSuccess' }],
done,
);
});
it('dispatches request and receive on error', done => {
it('dispatches request and receive on error', () => {
mock.onPost(TEST_SESSION.cancel_path).reply(400);
const state = {
session: { cancelPath: TEST_SESSION.cancel_path },
};
testAction(
return testAction(
actions.stopSession,
null,
state,
......@@ -207,20 +202,18 @@ describe('EE IDE store terminal session controls actions', () => {
{ type: 'requestStopSession' },
{ type: 'receiveStopSessionError', payload: jasmine.any(Error) },
],
done,
);
});
});
describe('killSession', () => {
it('stops polling and sets status', done => {
testAction(
it('stops polling and sets status', () => {
return testAction(
actions.killSession,
null,
{},
[{ type: mutationTypes.SET_SESSION_STATUS, payload: STOPPED }],
[{ type: 'stopPollingSessionStatus' }],
done,
);
});
});
......@@ -242,25 +235,24 @@ describe('EE IDE store terminal session controls actions', () => {
expect(dispatch).not.toHaveBeenCalled();
});
it('dispatches startSession if retryPath is empty', done => {
it('dispatches startSession if retryPath is empty', () => {
state.session.retryPath = '';
testAction(
return testAction(
actions.restartSession,
null,
{ ...state, ...rootState },
[],
[{ type: 'startSession' }],
done,
);
});
it('dispatches request and receive on success', done => {
it('dispatches request and receive on success', () => {
mock
.onPost(state.session.retryPath, { branch: rootState.currentBranchId, format: 'json' })
.reply(200, TEST_SESSION);
testAction(
return testAction(
actions.restartSession,
null,
{ ...state, ...rootState },
......@@ -269,16 +261,15 @@ describe('EE IDE store terminal session controls actions', () => {
{ type: 'requestStartSession' },
{ type: 'receiveStartSessionSuccess', payload: TEST_SESSION },
],
done,
);
});
it('dispatches request and receive on error', done => {
it('dispatches request and receive on error', () => {
mock
.onPost(state.session.retryPath, { branch: rootState.currentBranchId, format: 'json' })
.reply(400);
testAction(
return testAction(
actions.restartSession,
null,
{ ...state, ...rootState },
......@@ -287,23 +278,21 @@ describe('EE IDE store terminal session controls actions', () => {
{ type: 'requestStartSession' },
{ type: 'receiveStartSessionError', payload: jasmine.any(Error) },
],
done,
);
});
[httpStatus.NOT_FOUND, httpStatus.UNPROCESSABLE_ENTITY].forEach(status => {
it(`dispatches request and startSession on ${status}`, done => {
it(`dispatches request and startSession on ${status}`, () => {
mock
.onPost(state.session.retryPath, { branch: rootState.currentBranchId, format: 'json' })
.reply(status);
testAction(
return testAction(
actions.restartSession,
null,
{ ...state, ...rootState },
[],
[{ type: 'requestStartSession' }, { type: 'startSession' }],
done,
);
});
});
......
import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper';
import testAction from 'helpers/vuex_action_helper';
import { PENDING, RUNNING, STOPPING, STOPPED } from 'ee/ide/constants';
import * as messages from 'ee/ide/stores/modules/terminal/messages';
import * as mutationTypes from 'ee/ide/stores/modules/terminal/mutation_types';
import actionsModule, * as actions from 'ee/ide/stores/modules/terminal/actions/session_status';
import * as actions from 'ee/ide/stores/modules/terminal/actions/session_status';
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
jest.mock('~/flash');
const TEST_SESSION = {
id: 7,
......@@ -19,30 +22,25 @@ describe('EE IDE store terminal session controls actions', () => {
let mock;
let dispatch;
let commit;
let flashSpy;
beforeEach(() => {
jasmine.clock().install();
mock = new MockAdapter(axios);
dispatch = jasmine.createSpy('dispatch');
commit = jasmine.createSpy('commit');
flashSpy = spyOnDependency(actionsModule, 'flash');
dispatch = jest.fn().mockName('dispatch');
commit = jest.fn().mockName('commit');
});
afterEach(() => {
jasmine.clock().uninstall();
mock.restore();
});
describe('pollSessionStatus', () => {
it('starts interval to poll status', done => {
testAction(
it('starts interval to poll status', () => {
return testAction(
actions.pollSessionStatus,
null,
{},
[{ type: mutationTypes.SET_SESSION_STATUS_INTERVAL, payload: jasmine.any(Number) }],
[{ type: mutationTypes.SET_SESSION_STATUS_INTERVAL, payload: expect.any(Number) }],
[{ type: 'stopPollingSessionStatus' }, { type: 'fetchSessionStatus' }],
done,
);
});
......@@ -52,9 +50,9 @@ describe('EE IDE store terminal session controls actions', () => {
};
actions.pollSessionStatus({ state, dispatch, commit });
dispatch.calls.reset();
dispatch.mockClear();
jasmine.clock().tick(5001);
jest.advanceTimersByTime(5001);
expect(dispatch).toHaveBeenCalledWith('stopPollingSessionStatus');
});
......@@ -65,52 +63,49 @@ describe('EE IDE store terminal session controls actions', () => {
};
actions.pollSessionStatus({ state, dispatch, commit });
dispatch.calls.reset();
dispatch.mockClear();
jasmine.clock().tick(5001);
jest.advanceTimersByTime(5001);
expect(dispatch).toHaveBeenCalledWith('fetchSessionStatus');
});
});
describe('stopPollingSessionStatus', () => {
it('does nothing if sessionStatusInterval is empty', done => {
testAction(actions.stopPollingSessionStatus, null, {}, [], [], done);
it('does nothing if sessionStatusInterval is empty', () => {
return testAction(actions.stopPollingSessionStatus, null, {}, [], []);
});
it('clears interval', done => {
testAction(
it('clears interval', () => {
return testAction(
actions.stopPollingSessionStatus,
null,
{ sessionStatusInterval: 7 },
[{ type: mutationTypes.SET_SESSION_STATUS_INTERVAL, payload: 0 }],
[],
done,
);
});
});
describe('receiveSessionStatusSuccess', () => {
it('sets session status', done => {
testAction(
it('sets session status', () => {
return testAction(
actions.receiveSessionStatusSuccess,
{ status: RUNNING },
{},
[{ type: mutationTypes.SET_SESSION_STATUS, payload: RUNNING }],
[],
done,
);
});
[STOPPING, STOPPED, 'unexpected'].forEach(status => {
it(`kills session if status is ${status}`, done => {
testAction(
it(`kills session if status is ${status}`, () => {
return testAction(
actions.receiveSessionStatusSuccess,
{ status },
{},
[{ type: mutationTypes.SET_SESSION_STATUS, payload: status }],
[{ type: 'killSession' }],
done,
);
});
});
......@@ -120,11 +115,11 @@ describe('EE IDE store terminal session controls actions', () => {
it('flashes message', () => {
actions.receiveSessionStatusError({ dispatch });
expect(flashSpy).toHaveBeenCalledWith(messages.UNEXPECTED_ERROR_STATUS);
expect(createFlash).toHaveBeenCalledWith(messages.UNEXPECTED_ERROR_STATUS);
});
it('kills the session', done => {
testAction(actions.receiveSessionStatusError, null, {}, [], [{ type: 'killSession' }], done);
it('kills the session', () => {
return testAction(actions.receiveSessionStatusError, null, {}, [], [{ type: 'killSession' }]);
});
});
......@@ -147,29 +142,27 @@ describe('EE IDE store terminal session controls actions', () => {
expect(dispatch).not.toHaveBeenCalled();
});
it('dispatches success on success', done => {
it('dispatches success on success', () => {
mock.onGet(state.session.showPath).reply(200, TEST_SESSION);
testAction(
return testAction(
actions.fetchSessionStatus,
null,
state,
[],
[{ type: 'receiveSessionStatusSuccess', payload: TEST_SESSION }],
done,
);
});
it('dispatches error on error', done => {
it('dispatches error on error', () => {
mock.onGet(state.session.showPath).reply(400);
testAction(
return testAction(
actions.fetchSessionStatus,
null,
state,
[],
[{ type: 'receiveSessionStatusError', payload: jasmine.any(Error) }],
done,
[{ type: 'receiveSessionStatusError', payload: expect.any(Error) }],
);
});
});
......
import testAction from 'spec/helpers/vuex_action_helper';
import testAction from 'helpers/vuex_action_helper';
import * as mutationTypes from 'ee/ide/stores/modules/terminal/mutation_types';
import * as actions from 'ee/ide/stores/modules/terminal/actions/setup';
describe('EE IDE store terminal setup actions', () => {
describe('init', () => {
it('dispatches checks', done => {
testAction(
it('dispatches checks', () => {
return testAction(
actions.init,
null,
{},
[],
[{ type: 'fetchConfigCheck' }, { type: 'fetchRunnersCheck' }],
done,
);
});
});
describe('hideSplash', () => {
it('commits HIDE_SPLASH', done => {
testAction(actions.hideSplash, null, {}, [{ type: mutationTypes.HIDE_SPLASH }], [], done);
it('commits HIDE_SPLASH', () => {
return testAction(actions.hideSplash, null, {}, [{ type: mutationTypes.HIDE_SPLASH }], []);
});
});
describe('setPaths', () => {
it('commits SET_PATHS', done => {
it('commits SET_PATHS', () => {
const paths = {
foo: 'bar',
lorem: 'ipsum',
};
testAction(
return testAction(
actions.setPaths,
paths,
{},
[{ type: mutationTypes.SET_PATHS, payload: paths }],
[],
done,
);
});
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment