Commit 5848dc8a authored by Chad Woolley's avatar Chad Woolley

Convert some Web IDE specs from Karma to Jest

Includes related import reordering for IDE-related
files to fix eslint warnings.

See issue https://gitlab.com/gitlab-org/gitlab/issues/29243
which tracks the overall effort for migration to Jest.
parent 181bb515
<script>
import { mapActions, mapState } from 'vuex';
import _ from 'underscore';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import Item from './item.vue';
export default {
......
<script>
import $ from 'jquery';
import { mapActions, mapState } from 'vuex';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
export default {
components: {
......
<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import Icon from '~/vue_shared/components/icon.vue';
import { GlSkeletonLoading } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import FileRow from '~/vue_shared/components/file_row.vue';
import NavDropdown from './nav_dropdown.vue';
import FileRowExtra from './file_row_extra.vue';
......
<script>
import { mapActions, mapState } from 'vuex';
import _ from 'underscore';
import { GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Item from './item.vue';
import TokenedInput from '../shared/tokened_input.vue';
......
<script>
import $ from 'jquery';
import { mapActions, mapState, mapGetters } from 'vuex';
import flash from '~/flash';
import { __, sprintf, s__ } from '~/locale';
import { mapActions, mapState, mapGetters } from 'vuex';
import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue';
import { modalTypes } from '../../constants';
......
<script>
import { listen } from 'codesandbox-api';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
export default {
components: {
......
<script>
import { __, sprintf } from '~/locale';
import { mapActions } from 'vuex';
import { __, sprintf } from '~/locale';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue';
......
import $ from 'jquery';
import Vue from 'vue';
import _ from 'underscore';
import { __, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility';
import flash from '~/flash';
import _ from 'underscore';
import * as types from './mutation_types';
import { decorateFiles } from '../lib/files';
import { stageKeys } from '../constants';
......
import Vue from 'vue';
import mountCompontent from 'spec/helpers/vue_mount_component_helper';
import mountCompontent from 'helpers/vue_mount_component_helper';
import router from '~/ide/ide_router';
import Item from '~/ide/components/branches/item.vue';
import { getTimeago } from '~/lib/utils/datetime_utility';
......@@ -30,7 +30,7 @@ describe('IDE branch item', () => {
it('renders branch name and timeago', () => {
const timeText = getTimeago().format(TEST_BRANCH.committedDate);
expect(vm.$el).toContainText(TEST_BRANCH.name);
expect(vm.$el.textContent).toContain(TEST_BRANCH.name);
expect(vm.$el.querySelector('time')).toHaveText(timeText);
expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);
});
......@@ -39,7 +39,7 @@ describe('IDE branch item', () => {
const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`)
.href;
expect(vm.$el).toMatch('a');
expect(vm.$el.textContent).toMatch('a');
expect(vm.$el).toHaveAttr('href', expectedHref);
});
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import List from '~/ide/components/branches/search_list.vue';
import Item from '~/ide/components/branches/item.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { branches } from '../../mock_data';
const localVue = createLocalVue();
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import List from '~/ide/components/merge_requests/list.vue';
import Item from '~/ide/components/merge_requests/item.vue';
import TokenedInput from '~/ide/components/shared/tokened_input.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { mergeRequests as mergeRequestsMock } from '../../mock_data';
const localVue = createLocalVue();
......
......@@ -3,7 +3,7 @@ import '~/behaviors/markdown/render_gfm';
import { createStore } from '~/ide/stores';
import RightPane from '~/ide/components/panes/right.vue';
import { rightSidebarViews } from '~/ide/constants';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
describe('IDE right pane', () => {
let Component;
......@@ -56,7 +56,7 @@ describe('IDE right pane', () => {
describe('click', () => {
beforeEach(() => {
spyOn(vm, 'open');
jest.spyOn(vm, 'open').mockReturnValue();
});
it('sets view to merge request', done => {
......@@ -74,7 +74,9 @@ describe('IDE right pane', () => {
describe('live preview', () => {
it('renders live preview button', done => {
Vue.set(vm.$store.state.entries, 'package.json', { name: 'package.json' });
Vue.set(vm.$store.state.entries, 'package.json', {
name: 'package.json',
});
vm.$store.state.clientsidePreviewEnabled = true;
vm.$nextTick(() => {
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import List from '~/ide/components/pipelines/list.vue';
import JobsList from '~/ide/components/jobs/list.vue';
import Tab from '~/vue_shared/components/tabs/tab.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import { pipelines } from '../../../../javascripts/ide/mock_data';
const localVue = createLocalVue();
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { TEST_HOST } from 'helpers/test_constants';
import ClientsideNavigator from '~/ide/components/preview/navigator.vue';
describe('IDE clientside preview navigator', () => {
......@@ -13,8 +14,10 @@ describe('IDE clientside preview navigator', () => {
beforeEach(() => {
manager = {
bundlerURL: gl.TEST_HOST,
iframe: { src: '' },
bundlerURL: TEST_HOST,
iframe: {
src: '',
},
};
vm = mountComponent(Component, {
......@@ -47,7 +50,7 @@ describe('IDE clientside preview navigator', () => {
it('calls back method when clicking back button', done => {
vm.navigationStack.push('/test');
vm.navigationStack.push('/test2');
spyOn(vm, 'back');
jest.spyOn(vm, 'back').mockReturnValue();
vm.$nextTick(() => {
vm.$el.querySelector('.ide-navigator-btn').click();
......@@ -60,7 +63,7 @@ describe('IDE clientside preview navigator', () => {
it('calls forward method when clicking forward button', done => {
vm.forwardNavigationStack.push('/test');
spyOn(vm, 'forward');
jest.spyOn(vm, 'forward').mockReturnValue();
vm.$nextTick(() => {
vm.$el.querySelectorAll('.ide-navigator-btn')[1].click();
......@@ -74,7 +77,7 @@ describe('IDE clientside preview navigator', () => {
describe('onUrlChange', () => {
it('updates the path', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
url: `${TEST_HOST}/url`,
});
expect(vm.path).toBe('/url');
......@@ -82,7 +85,7 @@ describe('IDE clientside preview navigator', () => {
it('sets currentBrowsingIndex 0 if not already set', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
url: `${TEST_HOST}/url`,
});
expect(vm.currentBrowsingIndex).toBe(0);
......@@ -90,11 +93,11 @@ describe('IDE clientside preview navigator', () => {
it('increases currentBrowsingIndex if path doesnt match', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
url: `${TEST_HOST}/url`,
});
vm.onUrlChange({
url: `${gl.TEST_HOST}/url2`,
url: `${TEST_HOST}/url2`,
});
expect(vm.currentBrowsingIndex).toBe(1);
......@@ -102,11 +105,11 @@ describe('IDE clientside preview navigator', () => {
it('does not increase currentBrowsingIndex if path matches', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
url: `${TEST_HOST}/url`,
});
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
url: `${TEST_HOST}/url`,
});
expect(vm.currentBrowsingIndex).toBe(0);
......@@ -114,7 +117,7 @@ describe('IDE clientside preview navigator', () => {
it('pushes path into navigation stack', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
url: `${TEST_HOST}/url`,
});
expect(vm.navigationStack).toEqual(['/url']);
......@@ -128,7 +131,7 @@ describe('IDE clientside preview navigator', () => {
vm.navigationStack.push('/test');
vm.navigationStack.push('/test2');
spyOn(vm, 'visitPath');
jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.back();
});
......@@ -152,7 +155,7 @@ describe('IDE clientside preview navigator', () => {
describe('forward', () => {
it('calls visitPath with first entry in forwardNavigationStack', () => {
spyOn(vm, 'visitPath');
jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.forwardNavigationStack.push('/test');
vm.forwardNavigationStack.push('/test2');
......@@ -165,7 +168,7 @@ describe('IDE clientside preview navigator', () => {
describe('refresh', () => {
it('calls refresh with current path', () => {
spyOn(vm, 'visitPath');
jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.path = '/test';
......@@ -179,7 +182,7 @@ describe('IDE clientside preview navigator', () => {
it('updates iframe src with passed in path', () => {
vm.visitPath('/testpath');
expect(manager.iframe.src).toBe(`${gl.TEST_HOST}/testpath`);
expect(manager.iframe.src).toBe(`${TEST_HOST}/testpath`);
});
});
});
import * as pathUtils from 'path';
import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
import mergeRequestsState from '~/ide/stores/modules/merge_requests/state';
import pipelinesState from '~/ide/stores/modules/pipelines/state';
import branchesState from '~/ide/stores/modules/branches/state';
import fileTemplatesState from '~/ide/stores/modules/file_templates/state';
import paneState from '~/ide/stores/modules/pane/state';
export const resetStore = store => {
const newState = {
...state(),
commit: commitState(),
mergeRequests: mergeRequestsState(),
pipelines: pipelinesState(),
branches: branchesState(),
fileTemplates: fileTemplatesState(),
rightPane: paneState(),
};
store.replaceState(newState);
};
export const file = (name = 'name', id = name, type = '', parent = null) =>
decorateData({
id,
type,
icon: 'icon',
url: 'url',
name,
path: parent ? `${parent.path}/${name}` : name,
parentPath: parent ? parent.path : '',
lastCommit: {},
});
export const createEntriesFromPaths = paths =>
paths
.map(path => ({
name: pathUtils.basename(path),
dir: pathUtils.dirname(path),
ext: pathUtils.extname(path),
}))
.reduce((entries, path, idx) => {
const { name } = path;
const parent = path.dir ? entries[path.dir] : null;
const type = path.ext ? 'blob' : 'tree';
const entry = file(name, (idx + 1).toString(), type, parent);
return {
[entry.path]: entry,
...entries,
};
}, {});
......@@ -31,7 +31,7 @@ describe('IDE router', () => {
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}`,
].forEach(route => {
it(`finds project path when route is "${route}"`, () => {
spyOn(store, 'dispatch').and.returnValue(new Promise(() => {}));
jest.spyOn(store, 'dispatch').mockReturnValue(new Promise(() => {}));
router.push(route);
......
......@@ -45,7 +45,9 @@ describe('IDE store getters', () => {
localState.currentMergeRequestId = 1;
localState.projects.abcproject = {
mergeRequests: {
1: { mergeId: 1 },
1: {
mergeId: 1,
},
},
};
......@@ -62,9 +64,21 @@ describe('IDE store getters', () => {
describe('allBlobs', () => {
beforeEach(() => {
Object.assign(localState.entries, {
index: { type: 'blob', name: 'index', lastOpenedAt: 0 },
app: { type: 'blob', name: 'blob', lastOpenedAt: 0 },
folder: { type: 'folder', name: 'folder', lastOpenedAt: 0 },
index: {
type: 'blob',
name: 'index',
lastOpenedAt: 0,
},
app: {
type: 'blob',
name: 'blob',
lastOpenedAt: 0,
},
folder: {
type: 'folder',
name: 'folder',
lastOpenedAt: 0,
},
});
});
......@@ -174,7 +188,7 @@ describe('IDE store getters', () => {
},
};
const localGetters = {
findBranch: jasmine.createSpy('findBranchSpy'),
findBranch: jest.fn(),
};
getters.currentBranch(localState, localGetters);
......@@ -251,7 +265,9 @@ describe('IDE store getters', () => {
describe('packageJson', () => {
it('returns package.json entry', () => {
localState.entries['package.json'] = { name: 'package.json' };
localState.entries['package.json'] = {
name: 'package.json',
};
expect(getters.packageJson(localState)).toEqual({
name: 'package.json',
......@@ -273,7 +289,9 @@ describe('IDE store getters', () => {
currentProject: {
default_branch: 'master',
},
currentBranch: { can_push: true },
currentBranch: {
can_push: true,
},
};
expect(getters.canPushToBranch({}, localGetters)).toBeTruthy();
......@@ -284,7 +302,9 @@ describe('IDE store getters', () => {
currentProject: {
default_branch: 'master',
},
currentBranch: { can_push: false },
currentBranch: {
can_push: false,
},
};
expect(getters.canPushToBranch({}, localGetters)).toBeFalsy();
......
import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper';
import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils';
import state from '~/ide/stores/modules/branches/state';
import * as types from '~/ide/stores/modules/branches/mutation_types';
......@@ -51,7 +51,11 @@ describe('IDE branches actions', () => {
requestBranches,
null,
mockedContext.state,
[{ type: types.REQUEST_BRANCHES }],
[
{
type: types.REQUEST_BRANCHES,
},
],
[],
done,
);
......@@ -62,17 +66,25 @@ describe('IDE branches actions', () => {
it('should commit error', done => {
testAction(
receiveBranchesError,
{ search: TEST_SEARCH },
{
search: TEST_SEARCH,
},
mockedContext.state,
[{ type: types.RECEIVE_BRANCHES_ERROR }],
[
{
type: types.RECEIVE_BRANCHES_ERROR,
},
],
[
{
type: 'setErrorMessage',
payload: {
text: 'Error loading branches.',
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: { search: TEST_SEARCH },
actionPayload: {
search: TEST_SEARCH,
},
},
},
],
......@@ -87,7 +99,12 @@ describe('IDE branches actions', () => {
receiveBranchesSuccess,
branches,
mockedContext.state,
[{ type: types.RECEIVE_BRANCHES_SUCCESS, payload: branches }],
[
{
type: types.RECEIVE_BRANCHES_SUCCESS,
payload: branches,
},
],
[],
done,
);
......@@ -105,12 +122,14 @@ describe('IDE branches actions', () => {
});
it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchBranches(mockedContext, { search: TEST_SEARCH });
fetchBranches(mockedContext, {
search: TEST_SEARCH,
});
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: jasmine.objectContaining({
expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: expect.objectContaining({
search: TEST_SEARCH,
sort: 'updated_desc',
}),
......@@ -120,12 +139,18 @@ describe('IDE branches actions', () => {
it('dispatches success with received data', done => {
testAction(
fetchBranches,
{ search: TEST_SEARCH },
{
search: TEST_SEARCH,
},
mockedState,
[],
[
{ type: 'requestBranches' },
{ type: 'resetBranches' },
{
type: 'requestBranches',
},
{
type: 'resetBranches',
},
{
type: 'receiveBranchesSuccess',
payload: branches,
......@@ -144,15 +169,23 @@ describe('IDE branches actions', () => {
it('dispatches error', done => {
testAction(
fetchBranches,
{ search: TEST_SEARCH },
{
search: TEST_SEARCH,
},
mockedState,
[],
[
{ type: 'requestBranches' },
{ type: 'resetBranches' },
{
type: 'requestBranches',
},
{
type: 'resetBranches',
},
{
type: 'receiveBranchesError',
payload: { search: TEST_SEARCH },
payload: {
search: TEST_SEARCH,
},
},
],
done,
......@@ -166,7 +199,11 @@ describe('IDE branches actions', () => {
resetBranches,
null,
mockedContext.state,
[{ type: types.RESET_BRANCHES }],
[
{
type: types.RESET_BRANCHES,
},
],
[],
done,
);
......
......@@ -10,7 +10,7 @@ describe('IDE branches mutations', () => {
mockedState = state();
});
describe(types.REQUEST_BRANCHES, () => {
describe('REQUEST_BRANCHES', () => {
it('sets loading to true', () => {
mutations[types.REQUEST_BRANCHES](mockedState);
......@@ -18,7 +18,7 @@ describe('IDE branches mutations', () => {
});
});
describe(types.RECEIVE_BRANCHES_ERROR, () => {
describe('RECEIVE_BRANCHES_ERROR', () => {
it('sets loading to false', () => {
mutations[types.RECEIVE_BRANCHES_ERROR](mockedState);
......@@ -26,7 +26,7 @@ describe('IDE branches mutations', () => {
});
});
describe(types.RECEIVE_BRANCHES_SUCCESS, () => {
describe('RECEIVE_BRANCHES_SUCCESS', () => {
it('sets branches', () => {
const expectedBranches = branches.map(branch => ({
name: branch.name,
......@@ -39,7 +39,7 @@ describe('IDE branches mutations', () => {
});
});
describe(types.RESET_BRANCHES, () => {
describe('RESET_BRANCHES', () => {
it('clears branches array', () => {
mockedState.branches = ['test'];
......
......@@ -35,7 +35,11 @@ describe('IDE merge requests actions', () => {
requestMergeRequests,
null,
mockedState,
[{ type: types.REQUEST_MERGE_REQUESTS }],
[
{
type: types.REQUEST_MERGE_REQUESTS,
},
],
[],
done,
);
......@@ -46,17 +50,27 @@ describe('IDE merge requests actions', () => {
it('should commit error', done => {
testAction(
receiveMergeRequestsError,
{ type: 'created', search: '' },
{
type: 'created',
search: '',
},
mockedState,
[{ type: types.RECEIVE_MERGE_REQUESTS_ERROR }],
[
{
type: types.RECEIVE_MERGE_REQUESTS_ERROR,
},
],
[
{
type: 'setErrorMessage',
payload: {
text: 'Error loading merge requests.',
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: { type: 'created', search: '' },
actionPayload: {
type: 'created',
search: '',
},
},
},
],
......@@ -94,14 +108,19 @@ describe('IDE merge requests actions', () => {
});
it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: 'created' },
);
{
dispatch() {},
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
state: mockedState,
rootState: mockedRootState,
},
{
type: 'created',
},
);
expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: {
scope: 'created-by-me',
state: 'opened',
......@@ -111,14 +130,20 @@ describe('IDE merge requests actions', () => {
});
it('calls API with search', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: 'created', search: 'testing search' },
);
{
dispatch() {},
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
state: mockedState,
rootState: mockedRootState,
},
{
type: 'created',
search: 'testing search',
},
);
expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: {
scope: 'created-by-me',
state: 'opened',
......@@ -130,12 +155,18 @@ describe('IDE merge requests actions', () => {
it('dispatches success with received data', done => {
testAction(
fetchMergeRequests,
{ type: 'created' },
{
type: 'created',
},
mockedState,
[],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{
type: 'requestMergeRequests',
},
{
type: 'resetMergeRequests',
},
{
type: 'receiveMergeRequestsSuccess',
payload: mergeRequests,
......@@ -152,15 +183,21 @@ describe('IDE merge requests actions', () => {
});
it('calls API with project', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: null, search: 'testing search' },
);
{
dispatch() {},
state: mockedState,
rootState: mockedRootState,
},
{
type: null,
search: 'testing search',
},
);
expect(apiSpy).toHaveBeenCalledWith(
jasmine.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`),
expect.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`),
{
params: {
state: 'opened',
......@@ -173,12 +210,18 @@ describe('IDE merge requests actions', () => {
it('dispatches success with received data', done => {
testAction(
fetchMergeRequests,
{ type: null },
{
type: null,
},
{ ...mockedState, ...mockedRootState },
[],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{
type: 'requestMergeRequests',
},
{
type: 'resetMergeRequests',
},
{
type: 'receiveMergeRequestsSuccess',
payload: mergeRequests,
......@@ -197,13 +240,26 @@ describe('IDE merge requests actions', () => {
it('dispatches error', done => {
testAction(
fetchMergeRequests,
{ type: 'created', search: '' },
{
type: 'created',
search: '',
},
mockedState,
[],
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{ type: 'receiveMergeRequestsError', payload: { type: 'created', search: '' } },
{
type: 'requestMergeRequests',
},
{
type: 'resetMergeRequests',
},
{
type: 'receiveMergeRequestsError',
payload: {
type: 'created',
search: '',
},
},
],
done,
);
......@@ -217,7 +273,11 @@ describe('IDE merge requests actions', () => {
resetMergeRequests,
null,
mockedState,
[{ type: types.RESET_MERGE_REQUESTS }],
[
{
type: types.RESET_MERGE_REQUESTS,
},
],
[],
done,
);
......
import { TEST_HOST } from 'helpers/test_constants';
import state from '~/ide/stores/modules/merge_requests/state';
import mutations from '~/ide/stores/modules/merge_requests/mutations';
import * as types from '~/ide/stores/modules/merge_requests/mutation_types';
......@@ -10,7 +11,7 @@ describe('IDE merge requests mutations', () => {
mockedState = state();
});
describe(types.REQUEST_MERGE_REQUESTS, () => {
describe('REQUEST_MERGE_REQUESTS', () => {
it('sets loading to true', () => {
mutations[types.REQUEST_MERGE_REQUESTS](mockedState);
......@@ -18,7 +19,7 @@ describe('IDE merge requests mutations', () => {
});
});
describe(types.RECEIVE_MERGE_REQUESTS_ERROR, () => {
describe('RECEIVE_MERGE_REQUESTS_ERROR', () => {
it('sets loading to false', () => {
mutations[types.RECEIVE_MERGE_REQUESTS_ERROR](mockedState);
......@@ -26,9 +27,9 @@ describe('IDE merge requests mutations', () => {
});
});
describe(types.RECEIVE_MERGE_REQUESTS_SUCCESS, () => {
describe('RECEIVE_MERGE_REQUESTS_SUCCESS', () => {
it('sets merge requests', () => {
gon.gitlab_url = gl.TEST_HOST;
gon.gitlab_url = TEST_HOST;
mutations[types.RECEIVE_MERGE_REQUESTS_SUCCESS](mockedState, mergeRequests);
expect(mockedState.mergeRequests).toEqual([
......@@ -43,7 +44,7 @@ describe('IDE merge requests mutations', () => {
});
});
describe(types.RESET_MERGE_REQUESTS, () => {
describe('RESET_MERGE_REQUESTS', () => {
it('clears merge request array', () => {
mockedState.mergeRequests = ['test'];
......
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/ide/stores/modules/pane/actions';
import * as types from '~/ide/stores/modules/pane/mutation_types';
describe('IDE pane module actions', () => {
const TEST_VIEW = {
name: 'test',
};
const TEST_VIEW_KEEP_ALIVE = {
name: 'test-keep-alive',
keepAlive: true,
};
describe('toggleOpen', () => {
it('dispatches open if closed', done => {
testAction(
actions.toggleOpen,
TEST_VIEW,
{
isOpen: false,
},
[],
[
{
type: 'open',
payload: TEST_VIEW,
},
],
done,
);
});
it('dispatches close if opened', done => {
testAction(
actions.toggleOpen,
TEST_VIEW,
{
isOpen: true,
},
[],
[
{
type: 'close',
},
],
done,
);
});
});
describe('open', () => {
it('commits SET_OPEN', done => {
testAction(
actions.open,
null,
{},
[
{
type: types.SET_OPEN,
payload: true,
},
],
[],
done,
);
});
it('commits SET_CURRENT_VIEW if view is given', done => {
testAction(
actions.open,
TEST_VIEW,
{},
[
{
type: types.SET_OPEN,
payload: true,
},
{
type: types.SET_CURRENT_VIEW,
payload: TEST_VIEW.name,
},
],
[],
done,
);
});
it('commits KEEP_ALIVE_VIEW if keepAlive is true', done => {
testAction(
actions.open,
TEST_VIEW_KEEP_ALIVE,
{},
[
{
type: types.SET_OPEN,
payload: true,
},
{
type: types.SET_CURRENT_VIEW,
payload: TEST_VIEW_KEEP_ALIVE.name,
},
{
type: types.KEEP_ALIVE_VIEW,
payload: TEST_VIEW_KEEP_ALIVE.name,
},
],
[],
done,
);
});
});
describe('close', () => {
it('commits SET_OPEN', done => {
testAction(
actions.close,
null,
{},
[
{
type: types.SET_OPEN,
payload: false,
},
],
[],
done,
);
});
});
});
......@@ -10,7 +10,7 @@ describe('IDE pipelines mutations', () => {
mockedState = state();
});
describe(types.REQUEST_LATEST_PIPELINE, () => {
describe('REQUEST_LATEST_PIPELINE', () => {
it('sets loading to true', () => {
mutations[types.REQUEST_LATEST_PIPELINE](mockedState);
......@@ -18,7 +18,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_LASTEST_PIPELINE_ERROR, () => {
describe('RECEIVE_LASTEST_PIPELINE_ERROR', () => {
it('sets loading to false', () => {
mutations[types.RECEIVE_LASTEST_PIPELINE_ERROR](mockedState);
......@@ -26,7 +26,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, () => {
describe('RECEIVE_LASTEST_PIPELINE_SUCCESS', () => {
const itSetsPipelineLoadingStates = () => {
it('sets has loaded to true', () => {
expect(mockedState.hasLoadedPipeline).toBe(true);
......@@ -51,8 +51,12 @@ describe('IDE pipelines mutations', () => {
expect(mockedState.latestPipeline).toEqual({
id: '51',
path: 'test',
commit: { id: '123' },
details: { status: jasmine.any(Object) },
commit: {
id: '123',
},
details: {
status: expect.any(Object),
},
yamlError: undefined,
});
});
......@@ -95,12 +99,9 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.REQUEST_JOBS, () => {
describe('REQUEST_JOBS', () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
});
it('sets isLoading on stage', () => {
......@@ -110,12 +111,9 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOBS_ERROR, () => {
describe('RECEIVE_JOBS_ERROR', () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
});
it('sets isLoading on stage after error', () => {
......@@ -125,14 +123,11 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOBS_SUCCESS, () => {
describe('RECEIVE_JOBS_SUCCESS', () => {
let data;
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
data = {
latest_statuses: [...jobs],
......@@ -140,14 +135,18 @@ describe('IDE pipelines mutations', () => {
});
it('updates loading', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, {
id: mockedState.stages[0].id,
data,
});
expect(mockedState.stages[0].isLoading).toBe(false);
});
it('sets jobs on stage', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, {
id: mockedState.stages[0].id,
data,
});
expect(mockedState.stages[0].jobs.length).toBe(jobs.length);
expect(mockedState.stages[0].jobs).toEqual(
jobs.map(job => ({
......@@ -164,13 +163,9 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.TOGGLE_STAGE_COLLAPSE, () => {
describe('TOGGLE_STAGE_COLLAPSE', () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
isCollapsed: false,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i, isCollapsed: false }));
});
it('toggles collapsed state', () => {
......@@ -184,7 +179,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.SET_DETAIL_JOB, () => {
describe('SET_DETAIL_JOB', () => {
it('sets detail job', () => {
mutations[types.SET_DETAIL_JOB](mockedState, jobs[0]);
......@@ -192,7 +187,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.REQUEST_JOB_TRACE, () => {
describe('REQUEST_JOB_TRACE', () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0] };
});
......@@ -204,7 +199,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOB_TRACE_ERROR, () => {
describe('RECEIVE_JOB_TRACE_ERROR', () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true };
});
......@@ -216,14 +211,15 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOB_TRACE_SUCCESS, () => {
describe('RECEIVE_JOB_TRACE_SUCCESS', () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true };
});
it('sets output on detail job', () => {
mutations[types.RECEIVE_JOB_TRACE_SUCCESS](mockedState, { html: 'html' });
mutations[types.RECEIVE_JOB_TRACE_SUCCESS](mockedState, {
html: 'html',
});
expect(mockedState.detailJob.output).toBe('html');
expect(mockedState.detailJob.isLoading).toBe(false);
});
......
......@@ -9,10 +9,7 @@ describe('IDE store file mutations', () => {
beforeEach(() => {
localState = state();
localFile = {
...file(),
type: 'blob',
};
localFile = { ...file(), type: 'blob' };
localState.entries[localFile.path] = localFile;
});
......@@ -28,11 +25,7 @@ describe('IDE store file mutations', () => {
});
it('sets pending tab as not active', () => {
localState.openFiles.push({
...localFile,
pending: true,
active: true,
});
localState.openFiles.push({ ...localFile, pending: true, active: true });
mutations.SET_FILE_ACTIVE(localState, {
path: localFile.path,
......@@ -132,7 +125,7 @@ describe('IDE store file mutations', () => {
localFile,
].forEach(f => {
expect(f).toEqual(
jasmine.objectContaining({
expect.objectContaining({
path,
name,
raw: null,
......@@ -154,10 +147,7 @@ describe('IDE store file mutations', () => {
});
it('adds raw data to open pending file', () => {
localState.openFiles.push({
...localFile,
pending: true,
});
localState.openFiles.push({ ...localFile, pending: true });
mutations.SET_FILE_RAW_DATA(localState, {
file: localFile,
......@@ -168,11 +158,7 @@ describe('IDE store file mutations', () => {
});
it('does not add raw data to open pending tempFile file', () => {
localState.openFiles.push({
...localFile,
pending: true,
tempFile: true,
});
localState.openFiles.push({ ...localFile, pending: true, tempFile: true });
mutations.SET_FILE_RAW_DATA(localState, {
file: localFile,
......@@ -234,7 +220,9 @@ describe('IDE store file mutations', () => {
it('sets file mr change', () => {
mutations.SET_FILE_MERGE_REQUEST_CHANGE(localState, {
file: localFile,
mrChange: { diff: 'ABC' },
mrChange: {
diff: 'ABC',
},
});
expect(localFile.mrChange.diff).toBe('ABC');
......@@ -311,12 +299,7 @@ describe('IDE store file mutations', () => {
mutations.DISCARD_FILE_CHANGES(localState, localFile.path);
expect(localState.trees['gitlab-ce/master'].tree).toEqual([
{
...localFile,
deleted: false,
},
]);
expect(localState.trees['gitlab-ce/master'].tree).toEqual([{ ...localFile, deleted: false }]);
});
it('adds to parent tree if deleted', () => {
......@@ -328,12 +311,7 @@ describe('IDE store file mutations', () => {
mutations.DISCARD_FILE_CHANGES(localState, localFile.path);
expect(localState.entries.parentPath.tree).toEqual([
{
...localFile,
deleted: false,
},
]);
expect(localState.entries.parentPath.tree).toEqual([{ ...localFile, deleted: false }]);
});
});
......@@ -379,11 +357,7 @@ describe('IDE store file mutations', () => {
let f;
beforeEach(() => {
f = {
...file(),
type: 'blob',
staged: true,
};
f = { ...file(), type: 'blob', staged: true };
localState.stagedFiles.push(f);
localState.changedFiles.push(f);
......@@ -422,19 +396,16 @@ describe('IDE store file mutations', () => {
describe('ADD_PENDING_TAB', () => {
beforeEach(() => {
const f = {
...file('openFile'),
path: 'openFile',
active: true,
opened: true,
};
const f = { ...file('openFile'), path: 'openFile', active: true, opened: true };
localState.entries[f.path] = f;
localState.openFiles.push(f);
});
it('adds file into openFiles as pending', () => {
mutations.ADD_PENDING_TAB(localState, { file: localFile });
mutations.ADD_PENDING_TAB(localState, {
file: localFile,
});
expect(localState.openFiles.length).toBe(1);
expect(localState.openFiles[0].pending).toBe(true);
......@@ -445,11 +416,15 @@ describe('IDE store file mutations', () => {
const newFile = file('test');
localState.entries[newFile.path] = newFile;
mutations.ADD_PENDING_TAB(localState, { file: localFile });
mutations.ADD_PENDING_TAB(localState, {
file: localFile,
});
expect(localState.openFiles.length).toBe(1);
mutations.ADD_PENDING_TAB(localState, { file: file('test') });
mutations.ADD_PENDING_TAB(localState, {
file: file('test'),
});
expect(localState.openFiles.length).toBe(1);
expect(localState.openFiles[0].name).toBe('test');
......
......@@ -51,7 +51,9 @@ describe('Multi-file store tree mutations', () => {
});
it('keeps loading state', () => {
mutations.CREATE_TREE(localState, { treePath: 'project/master' });
mutations.CREATE_TREE(localState, {
treePath: 'project/master',
});
mutations.SET_DIRECTORY_DATA(localState, {
data,
treePath: 'project/master',
......
......@@ -26,15 +26,18 @@ describe('WebIDE utils', () => {
entry.deleted = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.deleted);
});
it('renders "addition" icon for temp entries', () => {
entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.addition);
});
it('renders "modified" icon for newly-renamed entries', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = false;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
});
it('renders "modified" icon even for temp entries if they are newly-renamed', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = true;
......
import * as pathUtils from 'path';
import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
import mergeRequestsState from '~/ide/stores/modules/merge_requests/state';
import pipelinesState from '~/ide/stores/modules/pipelines/state';
import branchesState from '~/ide/stores/modules/branches/state';
import fileTemplatesState from '~/ide/stores/modules/file_templates/state';
import paneState from '~/ide/stores/modules/pane/state';
export const resetStore = store => {
const newState = {
...state(),
commit: commitState(),
mergeRequests: mergeRequestsState(),
pipelines: pipelinesState(),
branches: branchesState(),
fileTemplates: fileTemplatesState(),
rightPane: paneState(),
};
store.replaceState(newState);
};
export const file = (name = 'name', id = name, type = '', parent = null) =>
decorateData({
id,
type,
icon: 'icon',
url: 'url',
name,
path: parent ? `${parent.path}/${name}` : name,
parentPath: parent ? parent.path : '',
lastCommit: {},
});
export const createEntriesFromPaths = paths =>
paths
.map(path => ({
name: pathUtils.basename(path),
dir: pathUtils.dirname(path),
ext: pathUtils.extname(path),
}))
.reduce((entries, path, idx) => {
const { name } = path;
const parent = path.dir ? entries[path.dir] : null;
const type = path.ext ? 'blob' : 'tree';
const entry = file(name, (idx + 1).toString(), type, parent);
return {
[entry.path]: entry,
...entries,
};
}, {});
export * from '../../frontend/ide/helpers';
import testAction from 'spec/helpers/vuex_action_helper';
import * as actions from '~/ide/stores/modules/pane/actions';
import * as types from '~/ide/stores/modules/pane/mutation_types';
describe('IDE pane module actions', () => {
const TEST_VIEW = { name: 'test' };
const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true };
describe('toggleOpen', () => {
it('dispatches open if closed', done => {
testAction(
actions.toggleOpen,
TEST_VIEW,
{ isOpen: false },
[],
[{ type: 'open', payload: TEST_VIEW }],
done,
);
});
it('dispatches close if opened', done => {
testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }], done);
});
});
describe('open', () => {
it('commits SET_OPEN', done => {
testAction(actions.open, null, {}, [{ type: types.SET_OPEN, payload: true }], [], done);
});
it('commits SET_CURRENT_VIEW if view is given', done => {
testAction(
actions.open,
TEST_VIEW,
{},
[
{ type: types.SET_OPEN, payload: true },
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name },
],
[],
done,
);
});
it('commits KEEP_ALIVE_VIEW if keepAlive is true', done => {
testAction(
actions.open,
TEST_VIEW_KEEP_ALIVE,
{},
[
{ type: types.SET_OPEN, payload: true },
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
{ type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
],
[],
done,
);
});
});
describe('close', () => {
it('commits SET_OPEN', done => {
testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], [], 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