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> <script>
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import _ from 'underscore'; import _ from 'underscore';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import Item from './item.vue'; import Item from './item.vue';
export default { export default {
......
<script> <script>
import $ from 'jquery'; import $ from 'jquery';
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
export default { export default {
components: { components: {
......
<script> <script>
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import Icon from '~/vue_shared/components/icon.vue';
import { GlSkeletonLoading } from '@gitlab/ui'; import { GlSkeletonLoading } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import FileRow from '~/vue_shared/components/file_row.vue'; import FileRow from '~/vue_shared/components/file_row.vue';
import NavDropdown from './nav_dropdown.vue'; import NavDropdown from './nav_dropdown.vue';
import FileRowExtra from './file_row_extra.vue'; import FileRowExtra from './file_row_extra.vue';
......
<script> <script>
import { mapActions, mapState } from 'vuex'; import { mapActions, mapState } from 'vuex';
import _ from 'underscore'; import _ from 'underscore';
import { GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Item from './item.vue'; import Item from './item.vue';
import TokenedInput from '../shared/tokened_input.vue'; import TokenedInput from '../shared/tokened_input.vue';
......
<script> <script>
import $ from 'jquery'; import $ from 'jquery';
import { mapActions, mapState, mapGetters } from 'vuex';
import flash from '~/flash'; import flash from '~/flash';
import { __, sprintf, s__ } from '~/locale'; import { __, sprintf, s__ } from '~/locale';
import { mapActions, mapState, mapGetters } from 'vuex';
import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue'; import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue';
import { modalTypes } from '../../constants'; import { modalTypes } from '../../constants';
......
<script> <script>
import { listen } from 'codesandbox-api'; import { listen } from 'codesandbox-api';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
export default { export default {
components: { components: {
......
<script> <script>
import { __, sprintf } from '~/locale';
import { mapActions } from 'vuex'; import { mapActions } from 'vuex';
import { __, sprintf } from '~/locale';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
......
import $ from 'jquery'; import $ from 'jquery';
import Vue from 'vue'; import Vue from 'vue';
import _ from 'underscore';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import flash from '~/flash'; import flash from '~/flash';
import _ from 'underscore';
import * as types from './mutation_types'; import * as types from './mutation_types';
import { decorateFiles } from '../lib/files'; import { decorateFiles } from '../lib/files';
import { stageKeys } from '../constants'; import { stageKeys } from '../constants';
......
import Vue from 'vue'; 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 router from '~/ide/ide_router';
import Item from '~/ide/components/branches/item.vue'; import Item from '~/ide/components/branches/item.vue';
import { getTimeago } from '~/lib/utils/datetime_utility'; import { getTimeago } from '~/lib/utils/datetime_utility';
...@@ -30,7 +30,7 @@ describe('IDE branch item', () => { ...@@ -30,7 +30,7 @@ describe('IDE branch item', () => {
it('renders branch name and timeago', () => { it('renders branch name and timeago', () => {
const timeText = getTimeago().format(TEST_BRANCH.committedDate); 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('time')).toHaveText(timeText);
expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null); expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);
}); });
...@@ -39,7 +39,7 @@ describe('IDE branch item', () => { ...@@ -39,7 +39,7 @@ describe('IDE branch item', () => {
const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`) const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`)
.href; .href;
expect(vm.$el).toMatch('a'); expect(vm.$el.textContent).toMatch('a');
expect(vm.$el).toHaveAttr('href', expectedHref); expect(vm.$el).toHaveAttr('href', expectedHref);
}); });
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale'; import { __ } from '~/locale';
import List from '~/ide/components/branches/search_list.vue'; import List from '~/ide/components/branches/search_list.vue';
import Item from '~/ide/components/branches/item.vue'; import Item from '~/ide/components/branches/item.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { branches } from '../../mock_data'; import { branches } from '../../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import List from '~/ide/components/merge_requests/list.vue'; import List from '~/ide/components/merge_requests/list.vue';
import Item from '~/ide/components/merge_requests/item.vue'; import Item from '~/ide/components/merge_requests/item.vue';
import TokenedInput from '~/ide/components/shared/tokened_input.vue'; import TokenedInput from '~/ide/components/shared/tokened_input.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { mergeRequests as mergeRequestsMock } from '../../mock_data'; import { mergeRequests as mergeRequestsMock } from '../../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
......
...@@ -3,7 +3,7 @@ import '~/behaviors/markdown/render_gfm'; ...@@ -3,7 +3,7 @@ import '~/behaviors/markdown/render_gfm';
import { createStore } from '~/ide/stores'; import { createStore } from '~/ide/stores';
import RightPane from '~/ide/components/panes/right.vue'; import RightPane from '~/ide/components/panes/right.vue';
import { rightSidebarViews } from '~/ide/constants'; 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', () => { describe('IDE right pane', () => {
let Component; let Component;
...@@ -56,7 +56,7 @@ describe('IDE right pane', () => { ...@@ -56,7 +56,7 @@ describe('IDE right pane', () => {
describe('click', () => { describe('click', () => {
beforeEach(() => { beforeEach(() => {
spyOn(vm, 'open'); jest.spyOn(vm, 'open').mockReturnValue();
}); });
it('sets view to merge request', done => { it('sets view to merge request', done => {
...@@ -74,7 +74,9 @@ describe('IDE right pane', () => { ...@@ -74,7 +74,9 @@ describe('IDE right pane', () => {
describe('live preview', () => { describe('live preview', () => {
it('renders live preview button', done => { 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.$store.state.clientsidePreviewEnabled = true;
vm.$nextTick(() => { vm.$nextTick(() => {
......
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex'; 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 List from '~/ide/components/pipelines/list.vue';
import JobsList from '~/ide/components/jobs/list.vue'; import JobsList from '~/ide/components/jobs/list.vue';
import Tab from '~/vue_shared/components/tabs/tab.vue'; import Tab from '~/vue_shared/components/tabs/tab.vue';
import CiIcon from '~/vue_shared/components/ci_icon.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'; import { pipelines } from '../../../../javascripts/ide/mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
......
import Vue from 'vue'; 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'; import ClientsideNavigator from '~/ide/components/preview/navigator.vue';
describe('IDE clientside preview navigator', () => { describe('IDE clientside preview navigator', () => {
...@@ -13,8 +14,10 @@ describe('IDE clientside preview navigator', () => { ...@@ -13,8 +14,10 @@ describe('IDE clientside preview navigator', () => {
beforeEach(() => { beforeEach(() => {
manager = { manager = {
bundlerURL: gl.TEST_HOST, bundlerURL: TEST_HOST,
iframe: { src: '' }, iframe: {
src: '',
},
}; };
vm = mountComponent(Component, { vm = mountComponent(Component, {
...@@ -47,7 +50,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -47,7 +50,7 @@ describe('IDE clientside preview navigator', () => {
it('calls back method when clicking back button', done => { it('calls back method when clicking back button', done => {
vm.navigationStack.push('/test'); vm.navigationStack.push('/test');
vm.navigationStack.push('/test2'); vm.navigationStack.push('/test2');
spyOn(vm, 'back'); jest.spyOn(vm, 'back').mockReturnValue();
vm.$nextTick(() => { vm.$nextTick(() => {
vm.$el.querySelector('.ide-navigator-btn').click(); vm.$el.querySelector('.ide-navigator-btn').click();
...@@ -60,7 +63,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -60,7 +63,7 @@ describe('IDE clientside preview navigator', () => {
it('calls forward method when clicking forward button', done => { it('calls forward method when clicking forward button', done => {
vm.forwardNavigationStack.push('/test'); vm.forwardNavigationStack.push('/test');
spyOn(vm, 'forward'); jest.spyOn(vm, 'forward').mockReturnValue();
vm.$nextTick(() => { vm.$nextTick(() => {
vm.$el.querySelectorAll('.ide-navigator-btn')[1].click(); vm.$el.querySelectorAll('.ide-navigator-btn')[1].click();
...@@ -74,7 +77,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -74,7 +77,7 @@ describe('IDE clientside preview navigator', () => {
describe('onUrlChange', () => { describe('onUrlChange', () => {
it('updates the path', () => { it('updates the path', () => {
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url`, url: `${TEST_HOST}/url`,
}); });
expect(vm.path).toBe('/url'); expect(vm.path).toBe('/url');
...@@ -82,7 +85,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -82,7 +85,7 @@ describe('IDE clientside preview navigator', () => {
it('sets currentBrowsingIndex 0 if not already set', () => { it('sets currentBrowsingIndex 0 if not already set', () => {
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url`, url: `${TEST_HOST}/url`,
}); });
expect(vm.currentBrowsingIndex).toBe(0); expect(vm.currentBrowsingIndex).toBe(0);
...@@ -90,11 +93,11 @@ describe('IDE clientside preview navigator', () => { ...@@ -90,11 +93,11 @@ describe('IDE clientside preview navigator', () => {
it('increases currentBrowsingIndex if path doesnt match', () => { it('increases currentBrowsingIndex if path doesnt match', () => {
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url`, url: `${TEST_HOST}/url`,
}); });
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url2`, url: `${TEST_HOST}/url2`,
}); });
expect(vm.currentBrowsingIndex).toBe(1); expect(vm.currentBrowsingIndex).toBe(1);
...@@ -102,11 +105,11 @@ describe('IDE clientside preview navigator', () => { ...@@ -102,11 +105,11 @@ describe('IDE clientside preview navigator', () => {
it('does not increase currentBrowsingIndex if path matches', () => { it('does not increase currentBrowsingIndex if path matches', () => {
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url`, url: `${TEST_HOST}/url`,
}); });
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url`, url: `${TEST_HOST}/url`,
}); });
expect(vm.currentBrowsingIndex).toBe(0); expect(vm.currentBrowsingIndex).toBe(0);
...@@ -114,7 +117,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -114,7 +117,7 @@ describe('IDE clientside preview navigator', () => {
it('pushes path into navigation stack', () => { it('pushes path into navigation stack', () => {
vm.onUrlChange({ vm.onUrlChange({
url: `${gl.TEST_HOST}/url`, url: `${TEST_HOST}/url`,
}); });
expect(vm.navigationStack).toEqual(['/url']); expect(vm.navigationStack).toEqual(['/url']);
...@@ -128,7 +131,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -128,7 +131,7 @@ describe('IDE clientside preview navigator', () => {
vm.navigationStack.push('/test'); vm.navigationStack.push('/test');
vm.navigationStack.push('/test2'); vm.navigationStack.push('/test2');
spyOn(vm, 'visitPath'); jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.back(); vm.back();
}); });
...@@ -152,7 +155,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -152,7 +155,7 @@ describe('IDE clientside preview navigator', () => {
describe('forward', () => { describe('forward', () => {
it('calls visitPath with first entry in forwardNavigationStack', () => { it('calls visitPath with first entry in forwardNavigationStack', () => {
spyOn(vm, 'visitPath'); jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.forwardNavigationStack.push('/test'); vm.forwardNavigationStack.push('/test');
vm.forwardNavigationStack.push('/test2'); vm.forwardNavigationStack.push('/test2');
...@@ -165,7 +168,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -165,7 +168,7 @@ describe('IDE clientside preview navigator', () => {
describe('refresh', () => { describe('refresh', () => {
it('calls refresh with current path', () => { it('calls refresh with current path', () => {
spyOn(vm, 'visitPath'); jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.path = '/test'; vm.path = '/test';
...@@ -179,7 +182,7 @@ describe('IDE clientside preview navigator', () => { ...@@ -179,7 +182,7 @@ describe('IDE clientside preview navigator', () => {
it('updates iframe src with passed in path', () => { it('updates iframe src with passed in path', () => {
vm.visitPath('/testpath'); 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', () => { ...@@ -31,7 +31,7 @@ describe('IDE router', () => {
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}`, `/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}`,
].forEach(route => { ].forEach(route => {
it(`finds project path when route is "${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); router.push(route);
......
...@@ -45,7 +45,9 @@ describe('IDE store getters', () => { ...@@ -45,7 +45,9 @@ describe('IDE store getters', () => {
localState.currentMergeRequestId = 1; localState.currentMergeRequestId = 1;
localState.projects.abcproject = { localState.projects.abcproject = {
mergeRequests: { mergeRequests: {
1: { mergeId: 1 }, 1: {
mergeId: 1,
},
}, },
}; };
...@@ -62,9 +64,21 @@ describe('IDE store getters', () => { ...@@ -62,9 +64,21 @@ describe('IDE store getters', () => {
describe('allBlobs', () => { describe('allBlobs', () => {
beforeEach(() => { beforeEach(() => {
Object.assign(localState.entries, { Object.assign(localState.entries, {
index: { type: 'blob', name: 'index', lastOpenedAt: 0 }, index: {
app: { type: 'blob', name: 'blob', lastOpenedAt: 0 }, type: 'blob',
folder: { type: 'folder', name: 'folder', lastOpenedAt: 0 }, 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', () => { ...@@ -174,7 +188,7 @@ describe('IDE store getters', () => {
}, },
}; };
const localGetters = { const localGetters = {
findBranch: jasmine.createSpy('findBranchSpy'), findBranch: jest.fn(),
}; };
getters.currentBranch(localState, localGetters); getters.currentBranch(localState, localGetters);
...@@ -251,7 +265,9 @@ describe('IDE store getters', () => { ...@@ -251,7 +265,9 @@ describe('IDE store getters', () => {
describe('packageJson', () => { describe('packageJson', () => {
it('returns package.json entry', () => { it('returns package.json entry', () => {
localState.entries['package.json'] = { name: 'package.json' }; localState.entries['package.json'] = {
name: 'package.json',
};
expect(getters.packageJson(localState)).toEqual({ expect(getters.packageJson(localState)).toEqual({
name: 'package.json', name: 'package.json',
...@@ -273,7 +289,9 @@ describe('IDE store getters', () => { ...@@ -273,7 +289,9 @@ describe('IDE store getters', () => {
currentProject: { currentProject: {
default_branch: 'master', default_branch: 'master',
}, },
currentBranch: { can_push: true }, currentBranch: {
can_push: true,
},
}; };
expect(getters.canPushToBranch({}, localGetters)).toBeTruthy(); expect(getters.canPushToBranch({}, localGetters)).toBeTruthy();
...@@ -284,7 +302,9 @@ describe('IDE store getters', () => { ...@@ -284,7 +302,9 @@ describe('IDE store getters', () => {
currentProject: { currentProject: {
default_branch: 'master', default_branch: 'master',
}, },
currentBranch: { can_push: false }, currentBranch: {
can_push: false,
},
}; };
expect(getters.canPushToBranch({}, localGetters)).toBeFalsy(); expect(getters.canPushToBranch({}, localGetters)).toBeFalsy();
......
import MockAdapter from 'axios-mock-adapter'; 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 axios from '~/lib/utils/axios_utils';
import state from '~/ide/stores/modules/branches/state'; import state from '~/ide/stores/modules/branches/state';
import * as types from '~/ide/stores/modules/branches/mutation_types'; import * as types from '~/ide/stores/modules/branches/mutation_types';
...@@ -51,7 +51,11 @@ describe('IDE branches actions', () => { ...@@ -51,7 +51,11 @@ describe('IDE branches actions', () => {
requestBranches, requestBranches,
null, null,
mockedContext.state, mockedContext.state,
[{ type: types.REQUEST_BRANCHES }], [
{
type: types.REQUEST_BRANCHES,
},
],
[], [],
done, done,
); );
...@@ -62,17 +66,25 @@ describe('IDE branches actions', () => { ...@@ -62,17 +66,25 @@ describe('IDE branches actions', () => {
it('should commit error', done => { it('should commit error', done => {
testAction( testAction(
receiveBranchesError, receiveBranchesError,
{ search: TEST_SEARCH }, {
search: TEST_SEARCH,
},
mockedContext.state, mockedContext.state,
[{ type: types.RECEIVE_BRANCHES_ERROR }], [
{
type: types.RECEIVE_BRANCHES_ERROR,
},
],
[ [
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
text: 'Error loading branches.', text: 'Error loading branches.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { search: TEST_SEARCH }, actionPayload: {
search: TEST_SEARCH,
},
}, },
}, },
], ],
...@@ -87,7 +99,12 @@ describe('IDE branches actions', () => { ...@@ -87,7 +99,12 @@ describe('IDE branches actions', () => {
receiveBranchesSuccess, receiveBranchesSuccess,
branches, branches,
mockedContext.state, mockedContext.state,
[{ type: types.RECEIVE_BRANCHES_SUCCESS, payload: branches }], [
{
type: types.RECEIVE_BRANCHES_SUCCESS,
payload: branches,
},
],
[], [],
done, done,
); );
...@@ -105,12 +122,14 @@ describe('IDE branches actions', () => { ...@@ -105,12 +122,14 @@ describe('IDE branches actions', () => {
}); });
it('calls API with params', () => { 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(), { expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: jasmine.objectContaining({ params: expect.objectContaining({
search: TEST_SEARCH, search: TEST_SEARCH,
sort: 'updated_desc', sort: 'updated_desc',
}), }),
...@@ -120,12 +139,18 @@ describe('IDE branches actions', () => { ...@@ -120,12 +139,18 @@ describe('IDE branches actions', () => {
it('dispatches success with received data', done => { it('dispatches success with received data', done => {
testAction( testAction(
fetchBranches, fetchBranches,
{ search: TEST_SEARCH }, {
search: TEST_SEARCH,
},
mockedState, mockedState,
[], [],
[ [
{ type: 'requestBranches' }, {
{ type: 'resetBranches' }, type: 'requestBranches',
},
{
type: 'resetBranches',
},
{ {
type: 'receiveBranchesSuccess', type: 'receiveBranchesSuccess',
payload: branches, payload: branches,
...@@ -144,15 +169,23 @@ describe('IDE branches actions', () => { ...@@ -144,15 +169,23 @@ describe('IDE branches actions', () => {
it('dispatches error', done => { it('dispatches error', done => {
testAction( testAction(
fetchBranches, fetchBranches,
{ search: TEST_SEARCH }, {
search: TEST_SEARCH,
},
mockedState, mockedState,
[], [],
[ [
{ type: 'requestBranches' }, {
{ type: 'resetBranches' }, type: 'requestBranches',
},
{
type: 'resetBranches',
},
{ {
type: 'receiveBranchesError', type: 'receiveBranchesError',
payload: { search: TEST_SEARCH }, payload: {
search: TEST_SEARCH,
},
}, },
], ],
done, done,
...@@ -166,7 +199,11 @@ describe('IDE branches actions', () => { ...@@ -166,7 +199,11 @@ describe('IDE branches actions', () => {
resetBranches, resetBranches,
null, null,
mockedContext.state, mockedContext.state,
[{ type: types.RESET_BRANCHES }], [
{
type: types.RESET_BRANCHES,
},
],
[], [],
done, done,
); );
......
...@@ -10,7 +10,7 @@ describe('IDE branches mutations', () => { ...@@ -10,7 +10,7 @@ describe('IDE branches mutations', () => {
mockedState = state(); mockedState = state();
}); });
describe(types.REQUEST_BRANCHES, () => { describe('REQUEST_BRANCHES', () => {
it('sets loading to true', () => { it('sets loading to true', () => {
mutations[types.REQUEST_BRANCHES](mockedState); mutations[types.REQUEST_BRANCHES](mockedState);
...@@ -18,7 +18,7 @@ describe('IDE branches mutations', () => { ...@@ -18,7 +18,7 @@ describe('IDE branches mutations', () => {
}); });
}); });
describe(types.RECEIVE_BRANCHES_ERROR, () => { describe('RECEIVE_BRANCHES_ERROR', () => {
it('sets loading to false', () => { it('sets loading to false', () => {
mutations[types.RECEIVE_BRANCHES_ERROR](mockedState); mutations[types.RECEIVE_BRANCHES_ERROR](mockedState);
...@@ -26,7 +26,7 @@ describe('IDE branches mutations', () => { ...@@ -26,7 +26,7 @@ describe('IDE branches mutations', () => {
}); });
}); });
describe(types.RECEIVE_BRANCHES_SUCCESS, () => { describe('RECEIVE_BRANCHES_SUCCESS', () => {
it('sets branches', () => { it('sets branches', () => {
const expectedBranches = branches.map(branch => ({ const expectedBranches = branches.map(branch => ({
name: branch.name, name: branch.name,
...@@ -39,7 +39,7 @@ describe('IDE branches mutations', () => { ...@@ -39,7 +39,7 @@ describe('IDE branches mutations', () => {
}); });
}); });
describe(types.RESET_BRANCHES, () => { describe('RESET_BRANCHES', () => {
it('clears branches array', () => { it('clears branches array', () => {
mockedState.branches = ['test']; mockedState.branches = ['test'];
......
import MockAdapter from 'axios-mock-adapter'; 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 axios from '~/lib/utils/axios_utils';
import createState from '~/ide/stores/modules/file_templates/state'; import createState from '~/ide/stores/modules/file_templates/state';
import * as actions from '~/ide/stores/modules/file_templates/actions'; import * as actions from '~/ide/stores/modules/file_templates/actions';
...@@ -25,7 +25,11 @@ describe('IDE file templates actions', () => { ...@@ -25,7 +25,11 @@ describe('IDE file templates actions', () => {
actions.requestTemplateTypes, actions.requestTemplateTypes,
null, null,
state, state,
[{ type: types.REQUEST_TEMPLATE_TYPES }], [
{
type: types.REQUEST_TEMPLATE_TYPES,
},
],
[], [],
done, done,
); );
...@@ -38,12 +42,16 @@ describe('IDE file templates actions', () => { ...@@ -38,12 +42,16 @@ describe('IDE file templates actions', () => {
actions.receiveTemplateTypesError, actions.receiveTemplateTypesError,
null, null,
state, state,
[{ type: types.RECEIVE_TEMPLATE_TYPES_ERROR }], [
{
type: types.RECEIVE_TEMPLATE_TYPES_ERROR,
},
],
[ [
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
text: 'Error loading template types.', text: 'Error loading template types.',
}, },
...@@ -60,7 +68,12 @@ describe('IDE file templates actions', () => { ...@@ -60,7 +68,12 @@ describe('IDE file templates actions', () => {
actions.receiveTemplateTypesSuccess, actions.receiveTemplateTypesSuccess,
'test', 'test',
state, state,
[{ type: types.RECEIVE_TEMPLATE_TYPES_SUCCESS, payload: 'test' }], [
{
type: types.RECEIVE_TEMPLATE_TYPES_SUCCESS,
payload: 'test',
},
],
[], [],
done, done,
); );
...@@ -69,7 +82,23 @@ describe('IDE file templates actions', () => { ...@@ -69,7 +82,23 @@ describe('IDE file templates actions', () => {
describe('fetchTemplateTypes', () => { describe('fetchTemplateTypes', () => {
describe('success', () => { describe('success', () => {
const pages = [[{ name: 'MIT' }], [{ name: 'Apache' }], [{ name: 'CC' }]]; const pages = [
[
{
name: 'MIT',
},
],
[
{
name: 'Apache',
},
],
[
{
name: 'CC',
},
],
];
beforeEach(() => { beforeEach(() => {
mock.onGet(/api\/(.*)\/templates\/licenses/).reply(({ params }) => { mock.onGet(/api\/(.*)\/templates\/licenses/).reply(({ params }) => {
...@@ -77,15 +106,26 @@ describe('IDE file templates actions', () => { ...@@ -77,15 +106,26 @@ describe('IDE file templates actions', () => {
const page = pages[pageNum - 1]; const page = pages[pageNum - 1];
const hasNextPage = pageNum < pages.length; const hasNextPage = pageNum < pages.length;
return [200, page, hasNextPage ? { 'X-NEXT-PAGE': pageNum + 1 } : {}]; return [
200,
page,
hasNextPage
? {
'X-NEXT-PAGE': pageNum + 1,
}
: {},
];
}); });
}); });
it('rejects if selectedTemplateType is empty', done => { it('rejects if selectedTemplateType is empty', done => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
actions actions
.fetchTemplateTypes({ dispatch, state }) .fetchTemplateTypes({
dispatch,
state,
})
.then(done.fail) .then(done.fail)
.catch(() => { .catch(() => {
expect(dispatch).not.toHaveBeenCalled(); expect(dispatch).not.toHaveBeenCalled();
...@@ -157,7 +197,7 @@ describe('IDE file templates actions', () => { ...@@ -157,7 +197,7 @@ describe('IDE file templates actions', () => {
describe('setSelectedTemplateType', () => { describe('setSelectedTemplateType', () => {
it('commits SET_SELECTED_TEMPLATE_TYPE', () => { it('commits SET_SELECTED_TEMPLATE_TYPE', () => {
const commit = jasmine.createSpy('commit'); const commit = jest.fn().mockName('commit');
const options = { const options = {
commit, commit,
dispatch() {}, dispatch() {},
...@@ -169,15 +209,20 @@ describe('IDE file templates actions', () => { ...@@ -169,15 +209,20 @@ describe('IDE file templates actions', () => {
}, },
}; };
actions.setSelectedTemplateType(options, { name: 'test' }); actions.setSelectedTemplateType(options, {
name: 'test',
});
expect(commit).toHaveBeenCalledWith(types.SET_SELECTED_TEMPLATE_TYPE, { name: 'test' }); expect(commit).toHaveBeenCalledWith(types.SET_SELECTED_TEMPLATE_TYPE, {
name: 'test',
});
}); });
it('dispatches discardFileChanges if prevPath matches templates name', () => { it('dispatches discardFileChanges if prevPath matches templates name', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const options = { const options = {
commit() {}, commit() {},
dispatch, dispatch,
rootGetters: { rootGetters: {
activeFile: { activeFile: {
...@@ -188,15 +233,20 @@ describe('IDE file templates actions', () => { ...@@ -188,15 +233,20 @@ describe('IDE file templates actions', () => {
}, },
}; };
actions.setSelectedTemplateType(options, { name: 'test' }); actions.setSelectedTemplateType(options, {
name: 'test',
});
expect(dispatch).toHaveBeenCalledWith('discardFileChanges', 'test', { root: true }); expect(dispatch).toHaveBeenCalledWith('discardFileChanges', 'test', {
root: true,
});
}); });
it('dispatches renameEntry if file name doesnt match', () => { it('dispatches renameEntry if file name doesnt match', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const options = { const options = {
commit() {}, commit() {},
dispatch, dispatch,
rootGetters: { rootGetters: {
activeFile: { activeFile: {
...@@ -207,7 +257,9 @@ describe('IDE file templates actions', () => { ...@@ -207,7 +257,9 @@ describe('IDE file templates actions', () => {
}, },
}; };
actions.setSelectedTemplateType(options, { name: 'test' }); actions.setSelectedTemplateType(options, {
name: 'test',
});
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith(
'renameEntry', 'renameEntry',
...@@ -215,7 +267,9 @@ describe('IDE file templates actions', () => { ...@@ -215,7 +267,9 @@ describe('IDE file templates actions', () => {
path: 'oldtest', path: 'oldtest',
name: 'test', name: 'test',
}, },
{ root: true }, {
root: true,
},
); );
}); });
}); });
...@@ -231,7 +285,7 @@ describe('IDE file templates actions', () => { ...@@ -231,7 +285,7 @@ describe('IDE file templates actions', () => {
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
text: 'Error loading template.', text: 'Error loading template.',
actionPayload: 'test', actionPayload: 'test',
...@@ -264,7 +318,12 @@ describe('IDE file templates actions', () => { ...@@ -264,7 +318,12 @@ describe('IDE file templates actions', () => {
template, template,
state, state,
[], [],
[{ type: 'setFileTemplate', payload: template }], [
{
type: 'setFileTemplate',
payload: template,
},
],
done, done,
); );
}); });
...@@ -283,7 +342,14 @@ describe('IDE file templates actions', () => { ...@@ -283,7 +342,14 @@ describe('IDE file templates actions', () => {
template, template,
state, state,
[], [],
[{ type: 'setFileTemplate', payload: { content: 'MIT content' } }], [
{
type: 'setFileTemplate',
payload: {
content: 'MIT content',
},
},
],
done, done,
); );
}); });
...@@ -302,7 +368,14 @@ describe('IDE file templates actions', () => { ...@@ -302,7 +368,14 @@ describe('IDE file templates actions', () => {
template, template,
state, state,
[], [],
[{ type: 'setFileTemplate', payload: { content: 'testing content' } }], [
{
type: 'setFileTemplate',
payload: {
content: 'testing content',
},
},
],
done, done,
); );
}); });
...@@ -327,7 +400,12 @@ describe('IDE file templates actions', () => { ...@@ -327,7 +400,12 @@ describe('IDE file templates actions', () => {
template, template,
state, state,
[], [],
[{ type: 'receiveTemplateError', payload: template }], [
{
type: 'receiveTemplateError',
payload: template,
},
],
done, done,
); );
}); });
...@@ -336,29 +414,56 @@ describe('IDE file templates actions', () => { ...@@ -336,29 +414,56 @@ describe('IDE file templates actions', () => {
describe('setFileTemplate', () => { describe('setFileTemplate', () => {
it('dispatches changeFileContent', () => { it('dispatches changeFileContent', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const commit = jasmine.createSpy('commit'); const commit = jest.fn().mockName('commit');
const rootGetters = { const rootGetters = {
activeFile: { path: 'test' }, activeFile: {
path: 'test',
},
}; };
actions.setFileTemplate({ dispatch, commit, rootGetters }, { content: 'content' }); actions.setFileTemplate(
{
dispatch,
commit,
rootGetters,
},
{
content: 'content',
},
);
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith(
'changeFileContent', 'changeFileContent',
{ path: 'test', content: 'content' }, {
{ root: true }, path: 'test',
content: 'content',
},
{
root: true,
},
); );
}); });
it('commits SET_UPDATE_SUCCESS', () => { it('commits SET_UPDATE_SUCCESS', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const commit = jasmine.createSpy('commit'); const commit = jest.fn().mockName('commit');
const rootGetters = { const rootGetters = {
activeFile: { path: 'test' }, activeFile: {
path: 'test',
},
}; };
actions.setFileTemplate({ dispatch, commit, rootGetters }, { content: 'content' }); actions.setFileTemplate(
{
dispatch,
commit,
rootGetters,
},
{
content: 'content',
},
);
expect(commit).toHaveBeenCalledWith('SET_UPDATE_SUCCESS', true); expect(commit).toHaveBeenCalledWith('SET_UPDATE_SUCCESS', true);
}); });
...@@ -366,46 +471,71 @@ describe('IDE file templates actions', () => { ...@@ -366,46 +471,71 @@ describe('IDE file templates actions', () => {
describe('undoFileTemplate', () => { describe('undoFileTemplate', () => {
it('dispatches changeFileContent', () => { it('dispatches changeFileContent', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const commit = jasmine.createSpy('commit'); const commit = jest.fn().mockName('commit');
const rootGetters = { const rootGetters = {
activeFile: { path: 'test', raw: 'raw content' }, activeFile: {
path: 'test',
raw: 'raw content',
},
}; };
actions.undoFileTemplate({ dispatch, commit, rootGetters }); actions.undoFileTemplate({
dispatch,
commit,
rootGetters,
});
expect(dispatch).toHaveBeenCalledWith( expect(dispatch).toHaveBeenCalledWith(
'changeFileContent', 'changeFileContent',
{ path: 'test', content: 'raw content' }, {
{ root: true }, path: 'test',
content: 'raw content',
},
{
root: true,
},
); );
}); });
it('commits SET_UPDATE_SUCCESS', () => { it('commits SET_UPDATE_SUCCESS', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const commit = jasmine.createSpy('commit'); const commit = jest.fn().mockName('commit');
const rootGetters = { const rootGetters = {
activeFile: { path: 'test', raw: 'raw content' }, activeFile: {
path: 'test',
raw: 'raw content',
},
}; };
actions.undoFileTemplate({ dispatch, commit, rootGetters }); actions.undoFileTemplate({
dispatch,
commit,
rootGetters,
});
expect(commit).toHaveBeenCalledWith('SET_UPDATE_SUCCESS', false); expect(commit).toHaveBeenCalledWith('SET_UPDATE_SUCCESS', false);
}); });
it('dispatches discardFileChanges if file has prevPath', () => { it('dispatches discardFileChanges if file has prevPath', () => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const rootGetters = { const rootGetters = {
activeFile: { path: 'test', prevPath: 'newtest', raw: 'raw content' }, activeFile: {
path: 'test',
prevPath: 'newtest',
raw: 'raw content',
},
}; };
actions.undoFileTemplate({ dispatch, commit() {}, rootGetters }); actions.undoFileTemplate({
dispatch,
commit() {},
rootGetters,
});
expect(dispatch.calls.mostRecent().args).toEqual([ expect(dispatch).toHaveBeenCalledWith('discardFileChanges', 'test', {
'discardFileChanges', root: true,
'test', });
{ root: true },
]);
}); });
}); });
}); });
...@@ -35,7 +35,11 @@ describe('IDE merge requests actions', () => { ...@@ -35,7 +35,11 @@ describe('IDE merge requests actions', () => {
requestMergeRequests, requestMergeRequests,
null, null,
mockedState, mockedState,
[{ type: types.REQUEST_MERGE_REQUESTS }], [
{
type: types.REQUEST_MERGE_REQUESTS,
},
],
[], [],
done, done,
); );
...@@ -46,17 +50,27 @@ describe('IDE merge requests actions', () => { ...@@ -46,17 +50,27 @@ describe('IDE merge requests actions', () => {
it('should commit error', done => { it('should commit error', done => {
testAction( testAction(
receiveMergeRequestsError, receiveMergeRequestsError,
{ type: 'created', search: '' }, {
type: 'created',
search: '',
},
mockedState, mockedState,
[{ type: types.RECEIVE_MERGE_REQUESTS_ERROR }], [
{
type: types.RECEIVE_MERGE_REQUESTS_ERROR,
},
],
[ [
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
text: 'Error loading merge requests.', text: 'Error loading merge requests.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { type: 'created', search: '' }, actionPayload: {
type: 'created',
search: '',
},
}, },
}, },
], ],
...@@ -94,14 +108,19 @@ describe('IDE merge requests actions', () => { ...@@ -94,14 +108,19 @@ describe('IDE merge requests actions', () => {
}); });
it('calls API with params', () => { it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests( 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: { params: {
scope: 'created-by-me', scope: 'created-by-me',
state: 'opened', state: 'opened',
...@@ -111,14 +130,20 @@ describe('IDE merge requests actions', () => { ...@@ -111,14 +130,20 @@ describe('IDE merge requests actions', () => {
}); });
it('calls API with search', () => { it('calls API with search', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests( 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: { params: {
scope: 'created-by-me', scope: 'created-by-me',
state: 'opened', state: 'opened',
...@@ -130,12 +155,18 @@ describe('IDE merge requests actions', () => { ...@@ -130,12 +155,18 @@ describe('IDE merge requests actions', () => {
it('dispatches success with received data', done => { it('dispatches success with received data', done => {
testAction( testAction(
fetchMergeRequests, fetchMergeRequests,
{ type: 'created' }, {
type: 'created',
},
mockedState, mockedState,
[], [],
[ [
{ type: 'requestMergeRequests' }, {
{ type: 'resetMergeRequests' }, type: 'requestMergeRequests',
},
{
type: 'resetMergeRequests',
},
{ {
type: 'receiveMergeRequestsSuccess', type: 'receiveMergeRequestsSuccess',
payload: mergeRequests, payload: mergeRequests,
...@@ -152,15 +183,21 @@ describe('IDE merge requests actions', () => { ...@@ -152,15 +183,21 @@ describe('IDE merge requests actions', () => {
}); });
it('calls API with project', () => { it('calls API with project', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough(); const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests( fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState }, {
{ type: null, search: 'testing search' }, dispatch() {},
);
state: mockedState,
rootState: mockedRootState,
},
{
type: null,
search: 'testing search',
},
);
expect(apiSpy).toHaveBeenCalledWith( expect(apiSpy).toHaveBeenCalledWith(
jasmine.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`), expect.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`),
{ {
params: { params: {
state: 'opened', state: 'opened',
...@@ -173,12 +210,18 @@ describe('IDE merge requests actions', () => { ...@@ -173,12 +210,18 @@ describe('IDE merge requests actions', () => {
it('dispatches success with received data', done => { it('dispatches success with received data', done => {
testAction( testAction(
fetchMergeRequests, fetchMergeRequests,
{ type: null }, {
type: null,
},
{ ...mockedState, ...mockedRootState }, { ...mockedState, ...mockedRootState },
[], [],
[ [
{ type: 'requestMergeRequests' }, {
{ type: 'resetMergeRequests' }, type: 'requestMergeRequests',
},
{
type: 'resetMergeRequests',
},
{ {
type: 'receiveMergeRequestsSuccess', type: 'receiveMergeRequestsSuccess',
payload: mergeRequests, payload: mergeRequests,
...@@ -197,13 +240,26 @@ describe('IDE merge requests actions', () => { ...@@ -197,13 +240,26 @@ describe('IDE merge requests actions', () => {
it('dispatches error', done => { it('dispatches error', done => {
testAction( testAction(
fetchMergeRequests, fetchMergeRequests,
{ type: 'created', search: '' }, {
type: 'created',
search: '',
},
mockedState, mockedState,
[], [],
[ [
{ type: 'requestMergeRequests' }, {
{ type: 'resetMergeRequests' }, type: 'requestMergeRequests',
{ type: 'receiveMergeRequestsError', payload: { type: 'created', search: '' } }, },
{
type: 'resetMergeRequests',
},
{
type: 'receiveMergeRequestsError',
payload: {
type: 'created',
search: '',
},
},
], ],
done, done,
); );
...@@ -217,7 +273,11 @@ describe('IDE merge requests actions', () => { ...@@ -217,7 +273,11 @@ describe('IDE merge requests actions', () => {
resetMergeRequests, resetMergeRequests,
null, null,
mockedState, mockedState,
[{ type: types.RESET_MERGE_REQUESTS }], [
{
type: types.RESET_MERGE_REQUESTS,
},
],
[], [],
done, done,
); );
......
import { TEST_HOST } from 'helpers/test_constants';
import state from '~/ide/stores/modules/merge_requests/state'; import state from '~/ide/stores/modules/merge_requests/state';
import mutations from '~/ide/stores/modules/merge_requests/mutations'; import mutations from '~/ide/stores/modules/merge_requests/mutations';
import * as types from '~/ide/stores/modules/merge_requests/mutation_types'; import * as types from '~/ide/stores/modules/merge_requests/mutation_types';
...@@ -10,7 +11,7 @@ describe('IDE merge requests mutations', () => { ...@@ -10,7 +11,7 @@ describe('IDE merge requests mutations', () => {
mockedState = state(); mockedState = state();
}); });
describe(types.REQUEST_MERGE_REQUESTS, () => { describe('REQUEST_MERGE_REQUESTS', () => {
it('sets loading to true', () => { it('sets loading to true', () => {
mutations[types.REQUEST_MERGE_REQUESTS](mockedState); mutations[types.REQUEST_MERGE_REQUESTS](mockedState);
...@@ -18,7 +19,7 @@ describe('IDE merge requests mutations', () => { ...@@ -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', () => { it('sets loading to false', () => {
mutations[types.RECEIVE_MERGE_REQUESTS_ERROR](mockedState); mutations[types.RECEIVE_MERGE_REQUESTS_ERROR](mockedState);
...@@ -26,9 +27,9 @@ describe('IDE merge requests mutations', () => { ...@@ -26,9 +27,9 @@ describe('IDE merge requests mutations', () => {
}); });
}); });
describe(types.RECEIVE_MERGE_REQUESTS_SUCCESS, () => { describe('RECEIVE_MERGE_REQUESTS_SUCCESS', () => {
it('sets merge requests', () => { it('sets merge requests', () => {
gon.gitlab_url = gl.TEST_HOST; gon.gitlab_url = TEST_HOST;
mutations[types.RECEIVE_MERGE_REQUESTS_SUCCESS](mockedState, mergeRequests); mutations[types.RECEIVE_MERGE_REQUESTS_SUCCESS](mockedState, mergeRequests);
expect(mockedState.mergeRequests).toEqual([ expect(mockedState.mergeRequests).toEqual([
...@@ -43,7 +44,7 @@ describe('IDE merge requests mutations', () => { ...@@ -43,7 +44,7 @@ describe('IDE merge requests mutations', () => {
}); });
}); });
describe(types.RESET_MERGE_REQUESTS, () => { describe('RESET_MERGE_REQUESTS', () => {
it('clears merge request array', () => { it('clears merge request array', () => {
mockedState.mergeRequests = ['test']; 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,
);
});
});
});
import Visibility from 'visibilityjs'; import Visibility from 'visibilityjs';
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'helpers/test_constants';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { import {
requestLatestPipeline, requestLatestPipeline,
...@@ -48,7 +49,11 @@ describe('IDE pipelines actions', () => { ...@@ -48,7 +49,11 @@ describe('IDE pipelines actions', () => {
requestLatestPipeline, requestLatestPipeline,
null, null,
mockedState, mockedState,
[{ type: types.REQUEST_LATEST_PIPELINE }], [
{
type: types.REQUEST_LATEST_PIPELINE,
},
],
[], [],
done, done,
); );
...@@ -59,10 +64,20 @@ describe('IDE pipelines actions', () => { ...@@ -59,10 +64,20 @@ describe('IDE pipelines actions', () => {
it('commits error', done => { it('commits error', done => {
testAction( testAction(
receiveLatestPipelineError, receiveLatestPipelineError,
{ status: 404 }, {
status: 404,
},
mockedState, mockedState,
[{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }], [
[{ type: 'stopPipelinePolling' }], {
type: types.RECEIVE_LASTEST_PIPELINE_ERROR,
},
],
[
{
type: 'stopPipelinePolling',
},
],
done, done,
); );
}); });
...@@ -70,20 +85,28 @@ describe('IDE pipelines actions', () => { ...@@ -70,20 +85,28 @@ describe('IDE pipelines actions', () => {
it('dispatches setErrorMessage is not 404', done => { it('dispatches setErrorMessage is not 404', done => {
testAction( testAction(
receiveLatestPipelineError, receiveLatestPipelineError,
{ status: 500 }, {
status: 500,
},
mockedState, mockedState,
[{ type: types.RECEIVE_LASTEST_PIPELINE_ERROR }], [
{
type: types.RECEIVE_LASTEST_PIPELINE_ERROR,
},
],
[ [
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
text: 'An error occurred whilst fetching the latest pipeline.', text: 'An error occurred whilst fetching the latest pipeline.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: null, actionPayload: null,
}, },
}, },
{ type: 'stopPipelinePolling' }, {
type: 'stopPipelinePolling',
},
], ],
done, done,
); );
...@@ -92,85 +115,108 @@ describe('IDE pipelines actions', () => { ...@@ -92,85 +115,108 @@ describe('IDE pipelines actions', () => {
describe('receiveLatestPipelineSuccess', () => { describe('receiveLatestPipelineSuccess', () => {
const rootGetters = { const rootGetters = {
lastCommit: { id: '123' }, lastCommit: {
id: '123',
},
}; };
let commit; let commit;
beforeEach(() => { beforeEach(() => {
commit = jasmine.createSpy('commit'); commit = jest.fn().mockName('commit');
}); });
it('commits pipeline', () => { it('commits pipeline', () => {
receiveLatestPipelineSuccess({ rootGetters, commit }, { pipelines }); receiveLatestPipelineSuccess(
{
expect(commit.calls.argsFor(0)).toEqual([ rootGetters,
types.RECEIVE_LASTEST_PIPELINE_SUCCESS, commit,
pipelines[0], },
]); {
pipelines,
},
);
expect(commit).toHaveBeenCalledWith(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, pipelines[0]);
}); });
it('commits false when there are no pipelines', () => { it('commits false when there are no pipelines', () => {
receiveLatestPipelineSuccess({ rootGetters, commit }, { pipelines: [] }); receiveLatestPipelineSuccess(
{
expect(commit.calls.argsFor(0)).toEqual([types.RECEIVE_LASTEST_PIPELINE_SUCCESS, false]); rootGetters,
commit,
},
{
pipelines: [],
},
);
expect(commit).toHaveBeenCalledWith(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, false);
}); });
}); });
describe('fetchLatestPipeline', () => { describe('fetchLatestPipeline', () => {
beforeEach(() => { beforeEach(() => {});
jasmine.clock().install();
});
afterEach(() => { afterEach(() => {
jasmine.clock().uninstall();
stopPipelinePolling(); stopPipelinePolling();
clearEtagPoll(); clearEtagPoll();
}); });
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
mock mock.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines').reply(
.onGet('/abc/def/commit/abc123def456ghi789jkl/pipelines') 200,
.reply(200, { data: { foo: 'bar' } }, { 'poll-interval': '10000' }); {
data: {
foo: 'bar',
},
},
{
'poll-interval': '10000',
},
);
}); });
it('dispatches request', done => { it('dispatches request', done => {
spyOn(axios, 'get').and.callThrough(); jest.spyOn(axios, 'get');
spyOn(Visibility, 'hidden').and.returnValue(false); jest.spyOn(Visibility, 'hidden').mockReturnValue(false);
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const rootGetters = { const rootGetters = {
lastCommit: { id: 'abc123def456ghi789jkl' }, lastCommit: {
currentProject: { path_with_namespace: 'abc/def' }, id: 'abc123def456ghi789jkl',
},
currentProject: {
path_with_namespace: 'abc/def',
},
}; };
fetchLatestPipeline({ dispatch, rootGetters }); fetchLatestPipeline({
dispatch,
rootGetters,
});
expect(dispatch.calls.argsFor(0)).toEqual(['requestLatestPipeline']); expect(dispatch).toHaveBeenCalledWith('requestLatestPipeline');
jasmine.clock().tick(1000); jest.advanceTimersByTime(1000);
new Promise(resolve => requestAnimationFrame(resolve)) new Promise(resolve => requestAnimationFrame(resolve))
.then(() => { .then(() => {
expect(axios.get).toHaveBeenCalled(); expect(axios.get).toHaveBeenCalled();
expect(axios.get.calls.count()).toBe(1); expect(axios.get).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith(
expect(dispatch.calls.argsFor(1)).toEqual([
'receiveLatestPipelineSuccess', 'receiveLatestPipelineSuccess',
jasmine.anything(), expect.anything(),
]); );
jasmine.clock().tick(10000); jest.advanceTimersByTime(10000);
}) })
.then(() => new Promise(resolve => requestAnimationFrame(resolve))) .then(() => new Promise(resolve => requestAnimationFrame(resolve)))
.then(() => { .then(() => {
expect(axios.get).toHaveBeenCalled(); expect(axios.get).toHaveBeenCalled();
expect(axios.get.calls.count()).toBe(2); expect(axios.get).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenCalledWith(
expect(dispatch.calls.argsFor(2)).toEqual([
'receiveLatestPipelineSuccess', 'receiveLatestPipelineSuccess',
jasmine.anything(), expect.anything(),
]); );
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -183,22 +229,26 @@ describe('IDE pipelines actions', () => { ...@@ -183,22 +229,26 @@ describe('IDE pipelines actions', () => {
}); });
it('dispatches error', done => { it('dispatches error', done => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn().mockName('dispatch');
const rootGetters = { const rootGetters = {
lastCommit: { id: 'abc123def456ghi789jkl' }, lastCommit: {
currentProject: { path_with_namespace: 'abc/def' }, id: 'abc123def456ghi789jkl',
},
currentProject: {
path_with_namespace: 'abc/def',
},
}; };
fetchLatestPipeline({ dispatch, rootGetters }); fetchLatestPipeline({
dispatch,
rootGetters,
});
jasmine.clock().tick(1500); jest.advanceTimersByTime(1500);
new Promise(resolve => requestAnimationFrame(resolve)) new Promise(resolve => requestAnimationFrame(resolve))
.then(() => { .then(() => {
expect(dispatch.calls.argsFor(1)).toEqual([ expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything());
'receiveLatestPipelineError',
jasmine.anything(),
]);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -208,7 +258,19 @@ describe('IDE pipelines actions', () => { ...@@ -208,7 +258,19 @@ describe('IDE pipelines actions', () => {
describe('requestJobs', () => { describe('requestJobs', () => {
it('commits request', done => { it('commits request', done => {
testAction(requestJobs, 1, mockedState, [{ type: types.REQUEST_JOBS, payload: 1 }], [], done); testAction(
requestJobs,
1,
mockedState,
[
{
type: types.REQUEST_JOBS,
payload: 1,
},
],
[],
done,
);
}); });
}); });
...@@ -216,17 +278,26 @@ describe('IDE pipelines actions', () => { ...@@ -216,17 +278,26 @@ describe('IDE pipelines actions', () => {
it('commits error', done => { it('commits error', done => {
testAction( testAction(
receiveJobsError, receiveJobsError,
{ id: 1 }, {
id: 1,
},
mockedState, mockedState,
[{ type: types.RECEIVE_JOBS_ERROR, payload: 1 }], [
{
type: types.RECEIVE_JOBS_ERROR,
payload: 1,
},
],
[ [
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
text: 'An error occurred whilst loading the pipelines jobs.', text: 'An error occurred whilst loading the pipelines jobs.',
action: jasmine.anything(), action: expect.anything(),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { id: 1 }, actionPayload: {
id: 1,
},
}, },
}, },
], ],
...@@ -239,9 +310,20 @@ describe('IDE pipelines actions', () => { ...@@ -239,9 +310,20 @@ describe('IDE pipelines actions', () => {
it('commits data', done => { it('commits data', done => {
testAction( testAction(
receiveJobsSuccess, receiveJobsSuccess,
{ id: 1, data: jobs }, {
id: 1,
data: jobs,
},
mockedState, mockedState,
[{ type: types.RECEIVE_JOBS_SUCCESS, payload: { id: 1, data: jobs } }], [
{
type: types.RECEIVE_JOBS_SUCCESS,
payload: {
id: 1,
data: jobs,
},
},
],
[], [],
done, done,
); );
...@@ -251,7 +333,7 @@ describe('IDE pipelines actions', () => { ...@@ -251,7 +333,7 @@ describe('IDE pipelines actions', () => {
describe('fetchJobs', () => { describe('fetchJobs', () => {
const stage = { const stage = {
id: 1, id: 1,
dropdownPath: `${gl.TEST_HOST}/jobs`, dropdownPath: `${TEST_HOST}/jobs`,
}; };
describe('success', () => { describe('success', () => {
...@@ -266,8 +348,17 @@ describe('IDE pipelines actions', () => { ...@@ -266,8 +348,17 @@ describe('IDE pipelines actions', () => {
mockedState, mockedState,
[], [],
[ [
{ type: 'requestJobs', payload: stage.id }, {
{ type: 'receiveJobsSuccess', payload: { id: stage.id, data: jobs } }, type: 'requestJobs',
payload: stage.id,
},
{
type: 'receiveJobsSuccess',
payload: {
id: stage.id,
data: jobs,
},
},
], ],
done, done,
); );
...@@ -286,8 +377,14 @@ describe('IDE pipelines actions', () => { ...@@ -286,8 +377,14 @@ describe('IDE pipelines actions', () => {
mockedState, mockedState,
[], [],
[ [
{ type: 'requestJobs', payload: stage.id }, {
{ type: 'receiveJobsError', payload: stage }, type: 'requestJobs',
payload: stage.id,
},
{
type: 'receiveJobsError',
payload: stage,
},
], ],
done, done,
); );
...@@ -301,7 +398,12 @@ describe('IDE pipelines actions', () => { ...@@ -301,7 +398,12 @@ describe('IDE pipelines actions', () => {
toggleStageCollapsed, toggleStageCollapsed,
1, 1,
mockedState, mockedState,
[{ type: types.TOGGLE_STAGE_COLLAPSE, payload: 1 }], [
{
type: types.TOGGLE_STAGE_COLLAPSE,
payload: 1,
},
],
[], [],
done, done,
); );
...@@ -314,8 +416,18 @@ describe('IDE pipelines actions', () => { ...@@ -314,8 +416,18 @@ describe('IDE pipelines actions', () => {
setDetailJob, setDetailJob,
'job', 'job',
mockedState, mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }], [
[{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }], {
type: types.SET_DETAIL_JOB,
payload: 'job',
},
],
[
{
type: 'rightPane/open',
payload: rightSidebarViews.jobsDetail,
},
],
done, done,
); );
}); });
...@@ -325,8 +437,18 @@ describe('IDE pipelines actions', () => { ...@@ -325,8 +437,18 @@ describe('IDE pipelines actions', () => {
setDetailJob, setDetailJob,
null, null,
mockedState, mockedState,
[{ type: types.SET_DETAIL_JOB, payload: null }], [
[{ type: 'rightPane/open', payload: rightSidebarViews.pipelines }], {
type: types.SET_DETAIL_JOB,
payload: null,
},
],
[
{
type: 'rightPane/open',
payload: rightSidebarViews.pipelines,
},
],
done, done,
); );
}); });
...@@ -336,8 +458,18 @@ describe('IDE pipelines actions', () => { ...@@ -336,8 +458,18 @@ describe('IDE pipelines actions', () => {
setDetailJob, setDetailJob,
'job', 'job',
mockedState, mockedState,
[{ type: types.SET_DETAIL_JOB, payload: 'job' }], [
[{ type: 'rightPane/open', payload: rightSidebarViews.jobsDetail }], {
type: types.SET_DETAIL_JOB,
payload: 'job',
},
],
[
{
type: 'rightPane/open',
payload: rightSidebarViews.jobsDetail,
},
],
done, done,
); );
}); });
...@@ -345,7 +477,18 @@ describe('IDE pipelines actions', () => { ...@@ -345,7 +477,18 @@ describe('IDE pipelines actions', () => {
describe('requestJobTrace', () => { describe('requestJobTrace', () => {
it('commits request', done => { it('commits request', done => {
testAction(requestJobTrace, null, mockedState, [{ type: types.REQUEST_JOB_TRACE }], [], done); testAction(
requestJobTrace,
null,
mockedState,
[
{
type: types.REQUEST_JOB_TRACE,
},
],
[],
done,
);
}); });
}); });
...@@ -355,13 +498,17 @@ describe('IDE pipelines actions', () => { ...@@ -355,13 +498,17 @@ describe('IDE pipelines actions', () => {
receiveJobTraceError, receiveJobTraceError,
null, null,
mockedState, mockedState,
[{ type: types.RECEIVE_JOB_TRACE_ERROR }], [
{
type: types.RECEIVE_JOB_TRACE_ERROR,
},
],
[ [
{ {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
text: 'An error occurred whilst fetching the job trace.', text: 'An error occurred whilst fetching the job trace.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: null, actionPayload: null,
}, },
...@@ -378,7 +525,12 @@ describe('IDE pipelines actions', () => { ...@@ -378,7 +525,12 @@ describe('IDE pipelines actions', () => {
receiveJobTraceSuccess, receiveJobTraceSuccess,
'data', 'data',
mockedState, mockedState,
[{ type: types.RECEIVE_JOB_TRACE_SUCCESS, payload: 'data' }], [
{
type: types.RECEIVE_JOB_TRACE_SUCCESS,
payload: 'data',
},
],
[], [],
done, done,
); );
...@@ -388,14 +540,16 @@ describe('IDE pipelines actions', () => { ...@@ -388,14 +540,16 @@ describe('IDE pipelines actions', () => {
describe('fetchJobTrace', () => { describe('fetchJobTrace', () => {
beforeEach(() => { beforeEach(() => {
mockedState.detailJob = { mockedState.detailJob = {
path: `${gl.TEST_HOST}/project/builds`, path: `${TEST_HOST}/project/builds`,
}; };
}); });
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
spyOn(axios, 'get').and.callThrough(); jest.spyOn(axios, 'get');
mock.onGet(`${gl.TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' }); mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, {
html: 'html',
});
}); });
it('dispatches request', done => { it('dispatches request', done => {
...@@ -405,25 +559,37 @@ describe('IDE pipelines actions', () => { ...@@ -405,25 +559,37 @@ describe('IDE pipelines actions', () => {
mockedState, mockedState,
[], [],
[ [
{ type: 'requestJobTrace' }, {
{ type: 'receiveJobTraceSuccess', payload: { html: 'html' } }, type: 'requestJobTrace',
},
{
type: 'receiveJobTraceSuccess',
payload: {
html: 'html',
},
},
], ],
done, done,
); );
}); });
it('sends get request to correct URL', () => { it('sends get request to correct URL', () => {
fetchJobTrace({ state: mockedState, dispatch() {} }); fetchJobTrace({
state: mockedState,
expect(axios.get).toHaveBeenCalledWith(`${gl.TEST_HOST}/project/builds/trace`, { dispatch() {},
params: { format: 'json' }, });
expect(axios.get).toHaveBeenCalledWith(`${TEST_HOST}/project/builds/trace`, {
params: {
format: 'json',
},
}); });
}); });
}); });
describe('error', () => { describe('error', () => {
beforeEach(() => { beforeEach(() => {
mock.onGet(`${gl.TEST_HOST}/project/builds/trace`).replyOnce(500); mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500);
}); });
it('dispatches error', done => { it('dispatches error', done => {
...@@ -432,7 +598,14 @@ describe('IDE pipelines actions', () => { ...@@ -432,7 +598,14 @@ describe('IDE pipelines actions', () => {
null, null,
mockedState, mockedState,
[], [],
[{ type: 'requestJobTrace' }, { type: 'receiveJobTraceError' }], [
{
type: 'requestJobTrace',
},
{
type: 'receiveJobTraceError',
},
],
done, done,
); );
}); });
...@@ -446,8 +619,14 @@ describe('IDE pipelines actions', () => { ...@@ -446,8 +619,14 @@ describe('IDE pipelines actions', () => {
null, null,
mockedState, mockedState,
[ [
{ type: types.RECEIVE_LASTEST_PIPELINE_SUCCESS, payload: null }, {
{ type: types.SET_DETAIL_JOB, payload: null }, type: types.RECEIVE_LASTEST_PIPELINE_SUCCESS,
payload: null,
},
{
type: types.SET_DETAIL_JOB,
payload: null,
},
], ],
[], [],
done, done,
......
...@@ -10,7 +10,7 @@ describe('IDE pipelines mutations', () => { ...@@ -10,7 +10,7 @@ describe('IDE pipelines mutations', () => {
mockedState = state(); mockedState = state();
}); });
describe(types.REQUEST_LATEST_PIPELINE, () => { describe('REQUEST_LATEST_PIPELINE', () => {
it('sets loading to true', () => { it('sets loading to true', () => {
mutations[types.REQUEST_LATEST_PIPELINE](mockedState); mutations[types.REQUEST_LATEST_PIPELINE](mockedState);
...@@ -18,7 +18,7 @@ describe('IDE pipelines mutations', () => { ...@@ -18,7 +18,7 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.RECEIVE_LASTEST_PIPELINE_ERROR, () => { describe('RECEIVE_LASTEST_PIPELINE_ERROR', () => {
it('sets loading to false', () => { it('sets loading to false', () => {
mutations[types.RECEIVE_LASTEST_PIPELINE_ERROR](mockedState); mutations[types.RECEIVE_LASTEST_PIPELINE_ERROR](mockedState);
...@@ -26,7 +26,7 @@ describe('IDE pipelines mutations', () => { ...@@ -26,7 +26,7 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, () => { describe('RECEIVE_LASTEST_PIPELINE_SUCCESS', () => {
const itSetsPipelineLoadingStates = () => { const itSetsPipelineLoadingStates = () => {
it('sets has loaded to true', () => { it('sets has loaded to true', () => {
expect(mockedState.hasLoadedPipeline).toBe(true); expect(mockedState.hasLoadedPipeline).toBe(true);
...@@ -51,8 +51,12 @@ describe('IDE pipelines mutations', () => { ...@@ -51,8 +51,12 @@ describe('IDE pipelines mutations', () => {
expect(mockedState.latestPipeline).toEqual({ expect(mockedState.latestPipeline).toEqual({
id: '51', id: '51',
path: 'test', path: 'test',
commit: { id: '123' }, commit: {
details: { status: jasmine.any(Object) }, id: '123',
},
details: {
status: expect.any(Object),
},
yamlError: undefined, yamlError: undefined,
}); });
}); });
...@@ -95,12 +99,9 @@ describe('IDE pipelines mutations', () => { ...@@ -95,12 +99,9 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.REQUEST_JOBS, () => { describe('REQUEST_JOBS', () => {
beforeEach(() => { beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({ mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
...stage,
id: i,
}));
}); });
it('sets isLoading on stage', () => { it('sets isLoading on stage', () => {
...@@ -110,12 +111,9 @@ describe('IDE pipelines mutations', () => { ...@@ -110,12 +111,9 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.RECEIVE_JOBS_ERROR, () => { describe('RECEIVE_JOBS_ERROR', () => {
beforeEach(() => { beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({ mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
...stage,
id: i,
}));
}); });
it('sets isLoading on stage after error', () => { it('sets isLoading on stage after error', () => {
...@@ -125,14 +123,11 @@ describe('IDE pipelines mutations', () => { ...@@ -125,14 +123,11 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.RECEIVE_JOBS_SUCCESS, () => { describe('RECEIVE_JOBS_SUCCESS', () => {
let data; let data;
beforeEach(() => { beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({ mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
...stage,
id: i,
}));
data = { data = {
latest_statuses: [...jobs], latest_statuses: [...jobs],
...@@ -140,14 +135,18 @@ describe('IDE pipelines mutations', () => { ...@@ -140,14 +135,18 @@ describe('IDE pipelines mutations', () => {
}); });
it('updates loading', () => { 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); expect(mockedState.stages[0].isLoading).toBe(false);
}); });
it('sets jobs on stage', () => { 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.length).toBe(jobs.length);
expect(mockedState.stages[0].jobs).toEqual( expect(mockedState.stages[0].jobs).toEqual(
jobs.map(job => ({ jobs.map(job => ({
...@@ -164,13 +163,9 @@ describe('IDE pipelines mutations', () => { ...@@ -164,13 +163,9 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.TOGGLE_STAGE_COLLAPSE, () => { describe('TOGGLE_STAGE_COLLAPSE', () => {
beforeEach(() => { beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({ mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i, isCollapsed: false }));
...stage,
id: i,
isCollapsed: false,
}));
}); });
it('toggles collapsed state', () => { it('toggles collapsed state', () => {
...@@ -184,7 +179,7 @@ describe('IDE pipelines mutations', () => { ...@@ -184,7 +179,7 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.SET_DETAIL_JOB, () => { describe('SET_DETAIL_JOB', () => {
it('sets detail job', () => { it('sets detail job', () => {
mutations[types.SET_DETAIL_JOB](mockedState, jobs[0]); mutations[types.SET_DETAIL_JOB](mockedState, jobs[0]);
...@@ -192,7 +187,7 @@ describe('IDE pipelines mutations', () => { ...@@ -192,7 +187,7 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.REQUEST_JOB_TRACE, () => { describe('REQUEST_JOB_TRACE', () => {
beforeEach(() => { beforeEach(() => {
mockedState.detailJob = { ...jobs[0] }; mockedState.detailJob = { ...jobs[0] };
}); });
...@@ -204,7 +199,7 @@ describe('IDE pipelines mutations', () => { ...@@ -204,7 +199,7 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.RECEIVE_JOB_TRACE_ERROR, () => { describe('RECEIVE_JOB_TRACE_ERROR', () => {
beforeEach(() => { beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true }; mockedState.detailJob = { ...jobs[0], isLoading: true };
}); });
...@@ -216,14 +211,15 @@ describe('IDE pipelines mutations', () => { ...@@ -216,14 +211,15 @@ describe('IDE pipelines mutations', () => {
}); });
}); });
describe(types.RECEIVE_JOB_TRACE_SUCCESS, () => { describe('RECEIVE_JOB_TRACE_SUCCESS', () => {
beforeEach(() => { beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true }; mockedState.detailJob = { ...jobs[0], isLoading: true };
}); });
it('sets output on detail job', () => { 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.output).toBe('html');
expect(mockedState.detailJob.isLoading).toBe(false); expect(mockedState.detailJob.isLoading).toBe(false);
}); });
......
...@@ -9,10 +9,7 @@ describe('IDE store file mutations', () => { ...@@ -9,10 +9,7 @@ describe('IDE store file mutations', () => {
beforeEach(() => { beforeEach(() => {
localState = state(); localState = state();
localFile = { localFile = { ...file(), type: 'blob' };
...file(),
type: 'blob',
};
localState.entries[localFile.path] = localFile; localState.entries[localFile.path] = localFile;
}); });
...@@ -28,11 +25,7 @@ describe('IDE store file mutations', () => { ...@@ -28,11 +25,7 @@ describe('IDE store file mutations', () => {
}); });
it('sets pending tab as not active', () => { it('sets pending tab as not active', () => {
localState.openFiles.push({ localState.openFiles.push({ ...localFile, pending: true, active: true });
...localFile,
pending: true,
active: true,
});
mutations.SET_FILE_ACTIVE(localState, { mutations.SET_FILE_ACTIVE(localState, {
path: localFile.path, path: localFile.path,
...@@ -132,7 +125,7 @@ describe('IDE store file mutations', () => { ...@@ -132,7 +125,7 @@ describe('IDE store file mutations', () => {
localFile, localFile,
].forEach(f => { ].forEach(f => {
expect(f).toEqual( expect(f).toEqual(
jasmine.objectContaining({ expect.objectContaining({
path, path,
name, name,
raw: null, raw: null,
...@@ -154,10 +147,7 @@ describe('IDE store file mutations', () => { ...@@ -154,10 +147,7 @@ describe('IDE store file mutations', () => {
}); });
it('adds raw data to open pending file', () => { it('adds raw data to open pending file', () => {
localState.openFiles.push({ localState.openFiles.push({ ...localFile, pending: true });
...localFile,
pending: true,
});
mutations.SET_FILE_RAW_DATA(localState, { mutations.SET_FILE_RAW_DATA(localState, {
file: localFile, file: localFile,
...@@ -168,11 +158,7 @@ describe('IDE store file mutations', () => { ...@@ -168,11 +158,7 @@ describe('IDE store file mutations', () => {
}); });
it('does not add raw data to open pending tempFile file', () => { it('does not add raw data to open pending tempFile file', () => {
localState.openFiles.push({ localState.openFiles.push({ ...localFile, pending: true, tempFile: true });
...localFile,
pending: true,
tempFile: true,
});
mutations.SET_FILE_RAW_DATA(localState, { mutations.SET_FILE_RAW_DATA(localState, {
file: localFile, file: localFile,
...@@ -234,7 +220,9 @@ describe('IDE store file mutations', () => { ...@@ -234,7 +220,9 @@ describe('IDE store file mutations', () => {
it('sets file mr change', () => { it('sets file mr change', () => {
mutations.SET_FILE_MERGE_REQUEST_CHANGE(localState, { mutations.SET_FILE_MERGE_REQUEST_CHANGE(localState, {
file: localFile, file: localFile,
mrChange: { diff: 'ABC' }, mrChange: {
diff: 'ABC',
},
}); });
expect(localFile.mrChange.diff).toBe('ABC'); expect(localFile.mrChange.diff).toBe('ABC');
...@@ -311,12 +299,7 @@ describe('IDE store file mutations', () => { ...@@ -311,12 +299,7 @@ describe('IDE store file mutations', () => {
mutations.DISCARD_FILE_CHANGES(localState, localFile.path); mutations.DISCARD_FILE_CHANGES(localState, localFile.path);
expect(localState.trees['gitlab-ce/master'].tree).toEqual([ expect(localState.trees['gitlab-ce/master'].tree).toEqual([{ ...localFile, deleted: false }]);
{
...localFile,
deleted: false,
},
]);
}); });
it('adds to parent tree if deleted', () => { it('adds to parent tree if deleted', () => {
...@@ -328,12 +311,7 @@ describe('IDE store file mutations', () => { ...@@ -328,12 +311,7 @@ describe('IDE store file mutations', () => {
mutations.DISCARD_FILE_CHANGES(localState, localFile.path); mutations.DISCARD_FILE_CHANGES(localState, localFile.path);
expect(localState.entries.parentPath.tree).toEqual([ expect(localState.entries.parentPath.tree).toEqual([{ ...localFile, deleted: false }]);
{
...localFile,
deleted: false,
},
]);
}); });
}); });
...@@ -379,11 +357,7 @@ describe('IDE store file mutations', () => { ...@@ -379,11 +357,7 @@ describe('IDE store file mutations', () => {
let f; let f;
beforeEach(() => { beforeEach(() => {
f = { f = { ...file(), type: 'blob', staged: true };
...file(),
type: 'blob',
staged: true,
};
localState.stagedFiles.push(f); localState.stagedFiles.push(f);
localState.changedFiles.push(f); localState.changedFiles.push(f);
...@@ -422,19 +396,16 @@ describe('IDE store file mutations', () => { ...@@ -422,19 +396,16 @@ describe('IDE store file mutations', () => {
describe('ADD_PENDING_TAB', () => { describe('ADD_PENDING_TAB', () => {
beforeEach(() => { beforeEach(() => {
const f = { const f = { ...file('openFile'), path: 'openFile', active: true, opened: true };
...file('openFile'),
path: 'openFile',
active: true,
opened: true,
};
localState.entries[f.path] = f; localState.entries[f.path] = f;
localState.openFiles.push(f); localState.openFiles.push(f);
}); });
it('adds file into openFiles as pending', () => { 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.length).toBe(1);
expect(localState.openFiles[0].pending).toBe(true); expect(localState.openFiles[0].pending).toBe(true);
...@@ -445,11 +416,15 @@ describe('IDE store file mutations', () => { ...@@ -445,11 +416,15 @@ describe('IDE store file mutations', () => {
const newFile = file('test'); const newFile = file('test');
localState.entries[newFile.path] = newFile; 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); 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.length).toBe(1);
expect(localState.openFiles[0].name).toBe('test'); expect(localState.openFiles[0].name).toBe('test');
......
...@@ -51,7 +51,9 @@ describe('Multi-file store tree mutations', () => { ...@@ -51,7 +51,9 @@ describe('Multi-file store tree mutations', () => {
}); });
it('keeps loading state', () => { it('keeps loading state', () => {
mutations.CREATE_TREE(localState, { treePath: 'project/master' }); mutations.CREATE_TREE(localState, {
treePath: 'project/master',
});
mutations.SET_DIRECTORY_DATA(localState, { mutations.SET_DIRECTORY_DATA(localState, {
data, data,
treePath: 'project/master', treePath: 'project/master',
......
import { TEST_HOST } from 'helpers/test_constants';
import mutations from '~/ide/stores/mutations'; import mutations from '~/ide/stores/mutations';
import state from '~/ide/stores/state'; import state from '~/ide/stores/state';
import { file } from '../helpers'; import { file } from '../helpers';
...@@ -25,21 +26,30 @@ describe('Multi-file store mutations', () => { ...@@ -25,21 +26,30 @@ describe('Multi-file store mutations', () => {
describe('TOGGLE_LOADING', () => { describe('TOGGLE_LOADING', () => {
it('toggles loading of entry', () => { it('toggles loading of entry', () => {
mutations.TOGGLE_LOADING(localState, { entry }); mutations.TOGGLE_LOADING(localState, {
entry,
});
expect(entry.loading).toBeTruthy(); expect(entry.loading).toBeTruthy();
mutations.TOGGLE_LOADING(localState, { entry }); mutations.TOGGLE_LOADING(localState, {
entry,
});
expect(entry.loading).toBeFalsy(); expect(entry.loading).toBeFalsy();
}); });
it('toggles loading of entry and sets specific value', () => { it('toggles loading of entry and sets specific value', () => {
mutations.TOGGLE_LOADING(localState, { entry }); mutations.TOGGLE_LOADING(localState, {
entry,
});
expect(entry.loading).toBeTruthy(); expect(entry.loading).toBeTruthy();
mutations.TOGGLE_LOADING(localState, { entry, forceValue: true }); mutations.TOGGLE_LOADING(localState, {
entry,
forceValue: true,
});
expect(entry.loading).toBeTruthy(); expect(entry.loading).toBeTruthy();
}); });
...@@ -123,11 +133,7 @@ describe('Multi-file store mutations', () => { ...@@ -123,11 +133,7 @@ describe('Multi-file store mutations', () => {
mutations.CREATE_TMP_ENTRY(localState, { mutations.CREATE_TMP_ENTRY(localState, {
data: { data: {
entries: { entries: {
test: { test: { ...tmpFile, tempFile: true, changed: true },
...tmpFile,
tempFile: true,
changed: true,
},
}, },
treeList: [tmpFile], treeList: [tmpFile],
}, },
...@@ -141,18 +147,11 @@ describe('Multi-file store mutations', () => { ...@@ -141,18 +147,11 @@ describe('Multi-file store mutations', () => {
it('marks entry as replacing previous entry if the old one has been deleted', () => { it('marks entry as replacing previous entry if the old one has been deleted', () => {
const tmpFile = file('test'); const tmpFile = file('test');
localState.entries.test = { localState.entries.test = { ...tmpFile, deleted: true };
...tmpFile,
deleted: true,
};
mutations.CREATE_TMP_ENTRY(localState, { mutations.CREATE_TMP_ENTRY(localState, {
data: { data: {
entries: { entries: {
test: { test: { ...tmpFile, tempFile: true, changed: true },
...tmpFile,
tempFile: true,
changed: true,
},
}, },
treeList: [tmpFile], treeList: [tmpFile],
}, },
...@@ -167,21 +166,23 @@ describe('Multi-file store mutations', () => { ...@@ -167,21 +166,23 @@ describe('Multi-file store mutations', () => {
describe('UPDATE_TEMP_FLAG', () => { describe('UPDATE_TEMP_FLAG', () => {
beforeEach(() => { beforeEach(() => {
localState.entries.test = { localState.entries.test = { ...file(), tempFile: true, changed: true };
...file(),
tempFile: true,
changed: true,
};
}); });
it('updates tempFile flag', () => { it('updates tempFile flag', () => {
mutations.UPDATE_TEMP_FLAG(localState, { path: 'test', tempFile: false }); mutations.UPDATE_TEMP_FLAG(localState, {
path: 'test',
tempFile: false,
});
expect(localState.entries.test.tempFile).toBe(false); expect(localState.entries.test.tempFile).toBe(false);
}); });
it('updates changed flag', () => { it('updates changed flag', () => {
mutations.UPDATE_TEMP_FLAG(localState, { path: 'test', tempFile: false }); mutations.UPDATE_TEMP_FLAG(localState, {
path: 'test',
tempFile: false,
});
expect(localState.entries.test.changed).toBe(false); expect(localState.entries.test.changed).toBe(false);
}); });
...@@ -303,23 +304,28 @@ describe('Multi-file store mutations', () => { ...@@ -303,23 +304,28 @@ describe('Multi-file store mutations', () => {
const f = { const f = {
...file('test'), ...file('test'),
prevPath: 'testing-123', prevPath: 'testing-123',
rawPath: `${gl.TEST_HOST}/testing-123`, rawPath: `${TEST_HOST}/testing-123`,
permalink: `${gl.TEST_HOST}/testing-123`, permalink: `${TEST_HOST}/testing-123`,
commitsPath: `${gl.TEST_HOST}/testing-123`, commitsPath: `${TEST_HOST}/testing-123`,
blamePath: `${gl.TEST_HOST}/testing-123`, blamePath: `${TEST_HOST}/testing-123`,
replaces: true, replaces: true,
}; };
localState.entries.test = f; localState.entries.test = f;
localState.changedFiles.push(f); localState.changedFiles.push(f);
mutations.UPDATE_FILE_AFTER_COMMIT(localState, { file: f, lastCommit: { commit: {} } }); mutations.UPDATE_FILE_AFTER_COMMIT(localState, {
file: f,
lastCommit: {
commit: {},
},
});
expect(f).toEqual( expect(f).toEqual(
jasmine.objectContaining({ expect.objectContaining({
rawPath: `${gl.TEST_HOST}/test`, rawPath: `${TEST_HOST}/test`,
permalink: `${gl.TEST_HOST}/test`, permalink: `${TEST_HOST}/test`,
commitsPath: `${gl.TEST_HOST}/test`, commitsPath: `${TEST_HOST}/test`,
blamePath: `${gl.TEST_HOST}/test`, blamePath: `${TEST_HOST}/test`,
replaces: false, replaces: false,
prevId: undefined, prevId: undefined,
prevPath: undefined, prevPath: undefined,
...@@ -335,7 +341,10 @@ describe('Multi-file store mutations', () => { ...@@ -335,7 +341,10 @@ describe('Multi-file store mutations', () => {
it('sets entryModal', () => { it('sets entryModal', () => {
localState.entries.testPath = file(); localState.entries.testPath = file();
mutations.OPEN_NEW_ENTRY_MODAL(localState, { type: 'test', path: 'testPath' }); mutations.OPEN_NEW_ENTRY_MODAL(localState, {
type: 'test',
path: 'testPath',
});
expect(localState.entryModal).toEqual({ expect(localState.entryModal).toEqual({
type: 'test', type: 'test',
...@@ -348,7 +357,9 @@ describe('Multi-file store mutations', () => { ...@@ -348,7 +357,9 @@ describe('Multi-file store mutations', () => {
describe('RENAME_ENTRY', () => { describe('RENAME_ENTRY', () => {
beforeEach(() => { beforeEach(() => {
localState.trees = { localState.trees = {
'gitlab-ce/master': { tree: [] }, 'gitlab-ce/master': {
tree: [],
},
}; };
localState.currentProjectId = 'gitlab-ce'; localState.currentProjectId = 'gitlab-ce';
localState.currentBranchId = 'master'; localState.currentBranchId = 'master';
...@@ -365,7 +376,7 @@ describe('Multi-file store mutations', () => { ...@@ -365,7 +376,7 @@ describe('Multi-file store mutations', () => {
}); });
expect(localState.entries).toEqual({ expect(localState.entries).toEqual({
newPath: jasmine.objectContaining({ newPath: expect.objectContaining({
path: 'newPath', path: 'newPath',
prevPath: 'oldPath', prevPath: 'oldPath',
}), }),
...@@ -386,7 +397,7 @@ describe('Multi-file store mutations', () => { ...@@ -386,7 +397,7 @@ describe('Multi-file store mutations', () => {
}); });
expect(localState.entries).toEqual({ expect(localState.entries).toEqual({
newestPath: jasmine.objectContaining({ newestPath: expect.objectContaining({
path: 'newestPath', path: 'newestPath',
prevPath: 'oldPath', prevPath: 'oldPath',
}), }),
...@@ -396,10 +407,7 @@ describe('Multi-file store mutations', () => { ...@@ -396,10 +407,7 @@ describe('Multi-file store mutations', () => {
it('correctly handles the same entry within a consecutively renamed folder', () => { it('correctly handles the same entry within a consecutively renamed folder', () => {
const oldPath = file('root-folder/oldPath', 'root-folder/oldPath', 'blob'); const oldPath = file('root-folder/oldPath', 'root-folder/oldPath', 'blob');
localState.entries = { localState.entries = {
'root-folder': { 'root-folder': { ...file('root-folder', 'root-folder', 'tree'), tree: [oldPath] },
...file('root-folder', 'root-folder', 'tree'),
tree: [oldPath],
},
'root-folder/oldPath': oldPath, 'root-folder/oldPath': oldPath,
}; };
Object.assign(localState.entries['root-folder/oldPath'], { Object.assign(localState.entries['root-folder/oldPath'], {
...@@ -422,10 +430,10 @@ describe('Multi-file store mutations', () => { ...@@ -422,10 +430,10 @@ describe('Multi-file store mutations', () => {
}); });
expect(localState.entries).toEqual({ expect(localState.entries).toEqual({
'root-folder': jasmine.objectContaining({ 'root-folder': expect.objectContaining({
path: 'root-folder', path: 'root-folder',
}), }),
'simply-renamed/oldPath': jasmine.objectContaining({ 'simply-renamed/oldPath': expect.objectContaining({
path: 'simply-renamed/oldPath', path: 'simply-renamed/oldPath',
prevPath: 'root-folder/oldPath', prevPath: 'root-folder/oldPath',
}), }),
...@@ -450,8 +458,7 @@ describe('Multi-file store mutations', () => { ...@@ -450,8 +458,7 @@ describe('Multi-file store mutations', () => {
path: 'newPath', path: 'newPath',
name: 'newPath', name: 'newPath',
url: `project/-/newPath`, url: `project/-/newPath`,
key: jasmine.stringMatching('newPath'), key: expect.stringMatching('newPath'),
prevId: 'oldPath', prevId: 'oldPath',
prevName: 'oldPath', prevName: 'oldPath',
prevPath: 'oldPath', prevPath: 'oldPath',
...@@ -473,13 +480,13 @@ describe('Multi-file store mutations', () => { ...@@ -473,13 +480,13 @@ describe('Multi-file store mutations', () => {
}); });
expect(localState.entries.newPath).not.toEqual( expect(localState.entries.newPath).not.toEqual(
jasmine.objectContaining({ expect.objectContaining({
prevId: jasmine.anything(), prevId: expect.anything(),
prevName: jasmine.anything(), prevName: expect.anything(),
prevPath: jasmine.anything(), prevPath: expect.anything(),
prevUrl: jasmine.anything(), prevUrl: expect.anything(),
prevKey: jasmine.anything(), prevKey: expect.anything(),
prevParentPath: jasmine.anything(), prevParentPath: expect.anything(),
}), }),
); );
}); });
...@@ -487,10 +494,7 @@ describe('Multi-file store mutations', () => { ...@@ -487,10 +494,7 @@ describe('Multi-file store mutations', () => {
it('properly handles files with spaces in name', () => { it('properly handles files with spaces in name', () => {
const path = 'my fancy path'; const path = 'my fancy path';
const newPath = 'new path'; const newPath = 'new path';
const oldEntry = { const oldEntry = { ...file(path, path, 'blob'), url: `project/-/${encodeURI(path)}` };
...file(path, path, 'blob'),
url: `project/-/${encodeURI(path)}`,
};
localState.entries[path] = oldEntry; localState.entries[path] = oldEntry;
...@@ -507,8 +511,7 @@ describe('Multi-file store mutations', () => { ...@@ -507,8 +511,7 @@ describe('Multi-file store mutations', () => {
path: newPath, path: newPath,
name: newPath, name: newPath,
url: `project/-/new%20path`, url: `project/-/new%20path`,
key: jasmine.stringMatching(newPath), key: expect.stringMatching(newPath),
prevId: path, prevId: path,
prevName: path, prevName: path,
prevPath: path, prevPath: path,
...@@ -540,7 +543,11 @@ describe('Multi-file store mutations', () => { ...@@ -540,7 +543,11 @@ describe('Multi-file store mutations', () => {
const alpha = file('alpha', 'alpha', 'blob'); const alpha = file('alpha', 'alpha', 'blob');
const beta = file('beta', 'beta', 'blob'); const beta = file('beta', 'beta', 'blob');
const gamma = file('gamma', 'gamma', 'blob'); const gamma = file('gamma', 'gamma', 'blob');
localState.entries = { alpha, beta, gamma }; localState.entries = {
alpha,
beta,
gamma,
};
localState.trees['gitlab-ce/master'].tree = [alpha, beta, gamma]; localState.trees['gitlab-ce/master'].tree = [alpha, beta, gamma];
...@@ -552,9 +559,13 @@ describe('Multi-file store mutations', () => { ...@@ -552,9 +559,13 @@ describe('Multi-file store mutations', () => {
}); });
expect(localState.trees['gitlab-ce/master'].tree).toEqual([ expect(localState.trees['gitlab-ce/master'].tree).toEqual([
jasmine.objectContaining({ name: 'beta' }), expect.objectContaining({
jasmine.objectContaining({ name: 'gamma' }), name: 'beta',
jasmine.objectContaining({ }),
expect.objectContaining({
name: 'gamma',
}),
expect.objectContaining({
path: 'theta', path: 'theta',
name: 'theta', name: 'theta',
}), }),
...@@ -570,23 +581,26 @@ describe('Multi-file store mutations', () => { ...@@ -570,23 +581,26 @@ describe('Multi-file store mutations', () => {
openFiles: [localState.entries.oldPath], openFiles: [localState.entries.oldPath],
}); });
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath',
name: 'newPath',
});
expect(localState.openFiles.length).toBe(1); expect(localState.openFiles.length).toBe(1);
expect(localState.openFiles[0].path).toBe('newPath'); expect(localState.openFiles[0].path).toBe('newPath');
}); });
it('does not add renamed entry to changedFiles', () => { it('does not add renamed entry to changedFiles', () => {
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath',
name: 'newPath',
});
expect(localState.changedFiles.length).toBe(0); expect(localState.changedFiles.length).toBe(0);
}); });
it('updates existing changedFiles entry with the renamed one', () => { it('updates existing changedFiles entry with the renamed one', () => {
const origFile = { const origFile = { ...file('oldPath', 'oldPath', 'blob'), content: 'Foo' };
...file('oldPath', 'oldPath', 'blob'),
content: 'Foo',
};
Object.assign(localState, { Object.assign(localState, {
changedFiles: [origFile], changedFiles: [origFile],
...@@ -595,10 +609,13 @@ describe('Multi-file store mutations', () => { ...@@ -595,10 +609,13 @@ describe('Multi-file store mutations', () => {
oldPath: origFile, oldPath: origFile,
}); });
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath',
name: 'newPath',
});
expect(localState.changedFiles).toEqual([ expect(localState.changedFiles).toEqual([
jasmine.objectContaining({ expect.objectContaining({
path: 'newPath', path: 'newPath',
content: 'Foo', content: 'Foo',
}), }),
...@@ -613,13 +630,19 @@ describe('Multi-file store mutations', () => { ...@@ -613,13 +630,19 @@ describe('Multi-file store mutations', () => {
{}, {},
); );
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath',
name: 'newPath',
});
expect(localState.entries.newPath).toEqual(jasmine.objectContaining(expectedObj)); expect(localState.entries.newPath).toEqual(expect.objectContaining(expectedObj));
mutations.RENAME_ENTRY(localState, { path: 'newPath', name: 'newer' }); mutations.RENAME_ENTRY(localState, {
path: 'newPath',
name: 'newer',
});
expect(localState.entries.newer).toEqual(jasmine.objectContaining(expectedObj)); expect(localState.entries.newer).toEqual(expect.objectContaining(expectedObj));
}); });
describe('renaming back to original', () => { describe('renaming back to original', () => {
...@@ -638,12 +661,16 @@ describe('Multi-file store mutations', () => { ...@@ -638,12 +661,16 @@ describe('Multi-file store mutations', () => {
renamed: renamedEntry, renamed: renamedEntry,
}; };
mutations.RENAME_ENTRY(localState, { path: 'renamed', name: 'orig', parentPath: 'lorem' }); mutations.RENAME_ENTRY(localState, {
path: 'renamed',
name: 'orig',
parentPath: 'lorem',
});
}); });
it('renames entry and clears prev properties', () => { it('renames entry and clears prev properties', () => {
expect(localState.entries).toEqual({ expect(localState.entries).toEqual({
'lorem/orig': jasmine.objectContaining({ 'lorem/orig': expect.objectContaining({
id: 'lorem/orig', id: 'lorem/orig',
path: 'lorem/orig', path: 'lorem/orig',
name: 'orig', name: 'orig',
...@@ -672,7 +699,10 @@ describe('Multi-file store mutations', () => { ...@@ -672,7 +699,10 @@ describe('Multi-file store mutations', () => {
it('sets properly constucted key while preserving the original one', () => { it('sets properly constucted key while preserving the original one', () => {
const key = 'oldPath.txt-blob-oldPath.txt'; const key = 'oldPath.txt-blob-oldPath.txt';
localState.entries['oldPath.txt'].key = key; localState.entries['oldPath.txt'].key = key;
mutations.RENAME_ENTRY(localState, { path: 'oldPath.txt', name: 'newPath.md' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath.txt',
name: 'newPath.md',
});
expect(localState.entries['newPath.md'].key).toBe('newPath.md-blob-newPath.md'); expect(localState.entries['newPath.md'].key).toBe('newPath.md-blob-newPath.md');
expect(localState.entries['newPath.md'].prevKey).toBe(key); expect(localState.entries['newPath.md'].prevKey).toBe(key);
...@@ -680,14 +710,20 @@ describe('Multi-file store mutations', () => { ...@@ -680,14 +710,20 @@ describe('Multi-file store mutations', () => {
it('correctly updates key for an entry without an extension', () => { it('correctly updates key for an entry without an extension', () => {
localState.entries.oldPath.key = 'oldPath-blob-oldPath'; localState.entries.oldPath.key = 'oldPath-blob-oldPath';
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath.md' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath',
name: 'newPath.md',
});
expect(localState.entries['newPath.md'].key).toBe('newPath.md-blob-newPath.md'); expect(localState.entries['newPath.md'].key).toBe('newPath.md-blob-newPath.md');
}); });
it('correctly updates key when new name does not have an extension', () => { it('correctly updates key when new name does not have an extension', () => {
localState.entries['oldPath.txt'].key = 'oldPath.txt-blob-oldPath.txt'; localState.entries['oldPath.txt'].key = 'oldPath.txt-blob-oldPath.txt';
mutations.RENAME_ENTRY(localState, { path: 'oldPath.txt', name: 'newPath' }); mutations.RENAME_ENTRY(localState, {
path: 'oldPath.txt',
name: 'newPath',
});
expect(localState.entries.newPath.key).toBe('newPath-blob-newPath'); expect(localState.entries.newPath.key).toBe('newPath-blob-newPath');
}); });
......
...@@ -104,21 +104,9 @@ describe('Multi-file store utils', () => { ...@@ -104,21 +104,9 @@ describe('Multi-file store utils', () => {
base64: true, base64: true,
lastCommitSha: '123456789', lastCommitSha: '123456789',
}, },
{ { ...file('deletedFile'), path: 'deletedFile', deleted: true },
...file('deletedFile'), { ...file('renamedFile'), path: 'renamedFile', prevPath: 'prevPath' },
path: 'deletedFile', { ...file('replacingFile'), path: 'replacingFile', replaces: true },
deleted: true,
},
{
...file('renamedFile'),
path: 'renamedFile',
prevPath: 'prevPath',
},
{
...file('replacingFile'),
path: 'replacingFile',
replaces: true,
},
], ],
currentBranchId: 'master', currentBranchId: 'master',
}; };
...@@ -237,15 +225,27 @@ describe('Multi-file store utils', () => { ...@@ -237,15 +225,27 @@ describe('Multi-file store utils', () => {
describe('commitActionForFile', () => { describe('commitActionForFile', () => {
it('returns deleted for deleted file', () => { it('returns deleted for deleted file', () => {
expect(utils.commitActionForFile({ deleted: true })).toBe(commitActionTypes.delete); expect(
utils.commitActionForFile({
deleted: true,
}),
).toBe(commitActionTypes.delete);
}); });
it('returns create for tempFile', () => { it('returns create for tempFile', () => {
expect(utils.commitActionForFile({ tempFile: true })).toBe(commitActionTypes.create); expect(
utils.commitActionForFile({
tempFile: true,
}),
).toBe(commitActionTypes.create);
}); });
it('returns move for moved file', () => { it('returns move for moved file', () => {
expect(utils.commitActionForFile({ prevPath: 'test' })).toBe(commitActionTypes.move); expect(
utils.commitActionForFile({
prevPath: 'test',
}),
).toBe(commitActionTypes.move);
}); });
it('returns update by default', () => { it('returns update by default', () => {
...@@ -341,12 +341,7 @@ describe('Multi-file store utils', () => { ...@@ -341,12 +341,7 @@ describe('Multi-file store utils', () => {
fromTree[0].tree.push({ fromTree[0].tree.push({
...file('alpha'), ...file('alpha'),
path: 'foo/alpha', path: 'foo/alpha',
tree: [ tree: [{ ...file('beta.md'), path: 'foo/alpha/beta.md' }],
{
...file('beta.md'),
path: 'foo/alpha/beta.md',
},
],
}); });
toTree.push({ toTree.push({
...@@ -355,12 +350,7 @@ describe('Multi-file store utils', () => { ...@@ -355,12 +350,7 @@ describe('Multi-file store utils', () => {
{ {
...file('alpha'), ...file('alpha'),
path: 'foo/alpha', path: 'foo/alpha',
tree: [ tree: [{ ...file('gamma.md'), path: 'foo/alpha/gamma.md' }],
{
...file('gamma.md'),
path: 'foo/alpha/gamma.md',
},
],
}, },
], ],
}); });
...@@ -381,12 +371,7 @@ describe('Multi-file store utils', () => { ...@@ -381,12 +371,7 @@ describe('Multi-file store utils', () => {
fromTree[0].tree.push({ fromTree[0].tree.push({
...file('alpha'), ...file('alpha'),
path: 'foo/alpha', path: 'foo/alpha',
tree: [ tree: [{ ...file('beta.md'), path: 'foo/alpha/beta.md' }],
{
...file('beta.md'),
path: 'foo/alpha/beta.md',
},
],
}); });
toTree.push({ toTree.push({
...@@ -395,12 +380,7 @@ describe('Multi-file store utils', () => { ...@@ -395,12 +380,7 @@ describe('Multi-file store utils', () => {
{ {
...file('alpha'), ...file('alpha'),
path: 'foo/alpha', path: 'foo/alpha',
tree: [ tree: [{ ...file('gamma.md'), path: 'foo/alpha/gamma.md' }],
{
...file('gamma.md'),
path: 'foo/alpha/gamma.md',
},
],
}, },
], ],
}); });
...@@ -431,10 +411,7 @@ describe('Multi-file store utils', () => { ...@@ -431,10 +411,7 @@ describe('Multi-file store utils', () => {
}); });
it('swaps existing entry with a new one', () => { it('swaps existing entry with a new one', () => {
const file1 = { const file1 = { ...file('old'), key: 'foo' };
...file('old'),
key: 'foo',
};
const file2 = file('new'); const file2 = file('new');
const arr = [file1]; const arr = [file1];
...@@ -511,8 +488,12 @@ describe('Multi-file store utils', () => { ...@@ -511,8 +488,12 @@ describe('Multi-file store utils', () => {
expect(branchInfo.tree.length).toBe(2); expect(branchInfo.tree.length).toBe(2);
expect(branchInfo.tree).toEqual([ expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'newPath' }), expect.objectContaining({
jasmine.objectContaining({ name: 'oldPath' }), name: 'newPath',
}),
expect.objectContaining({
name: 'oldPath',
}),
]); ]);
}); });
...@@ -521,7 +502,9 @@ describe('Multi-file store utils', () => { ...@@ -521,7 +502,9 @@ describe('Multi-file store utils', () => {
expect(localState.entries.parentPath.tree.length).toBe(1); expect(localState.entries.parentPath.tree.length).toBe(1);
expect(localState.entries.parentPath.tree).toEqual([ expect(localState.entries.parentPath.tree).toEqual([
jasmine.objectContaining({ name: 'newPath' }), expect.objectContaining({
name: 'newPath',
}),
]); ]);
localState.entries.parentPath.tree = [localState.entries.oldPath]; localState.entries.parentPath.tree = [localState.entries.oldPath];
...@@ -530,8 +513,12 @@ describe('Multi-file store utils', () => { ...@@ -530,8 +513,12 @@ describe('Multi-file store utils', () => {
expect(localState.entries.parentPath.tree.length).toBe(2); expect(localState.entries.parentPath.tree.length).toBe(2);
expect(localState.entries.parentPath.tree).toEqual([ expect(localState.entries.parentPath.tree).toEqual([
jasmine.objectContaining({ name: 'newPath' }), expect.objectContaining({
jasmine.objectContaining({ name: 'oldPath' }), name: 'newPath',
}),
expect.objectContaining({
name: 'oldPath',
}),
]); ]);
}); });
}); });
...@@ -542,11 +529,19 @@ describe('Multi-file store utils', () => { ...@@ -542,11 +529,19 @@ describe('Multi-file store utils', () => {
utils.swapInParentTreeWithSorting(localState, localState.entries.oldPath.key, 'newPath'); utils.swapInParentTreeWithSorting(localState, localState.entries.oldPath.key, 'newPath');
expect(branchInfo.tree).toEqual([jasmine.objectContaining({ name: 'newPath' })]); expect(branchInfo.tree).toEqual([
expect.objectContaining({
name: 'newPath',
}),
]);
utils.swapInParentTreeWithSorting(localState, localState.entries.newPath.key, 'oldPath'); utils.swapInParentTreeWithSorting(localState, localState.entries.newPath.key, 'oldPath');
expect(branchInfo.tree).toEqual([jasmine.objectContaining({ name: 'oldPath' })]); expect(branchInfo.tree).toEqual([
expect.objectContaining({
name: 'oldPath',
}),
]);
}); });
it('sorts tree after swapping the entries', () => { it('sorts tree after swapping the entries', () => {
...@@ -554,32 +549,55 @@ describe('Multi-file store utils', () => { ...@@ -554,32 +549,55 @@ describe('Multi-file store utils', () => {
const beta = file('beta', 'beta', 'blob'); const beta = file('beta', 'beta', 'blob');
const gamma = file('gamma', 'gamma', 'blob'); const gamma = file('gamma', 'gamma', 'blob');
const theta = file('theta', 'theta', 'blob'); const theta = file('theta', 'theta', 'blob');
localState.entries = { alpha, beta, gamma, theta }; localState.entries = {
alpha,
beta,
gamma,
theta,
};
branchInfo.tree = [alpha, beta, gamma]; branchInfo.tree = [alpha, beta, gamma];
utils.swapInParentTreeWithSorting(localState, alpha.key, 'theta'); utils.swapInParentTreeWithSorting(localState, alpha.key, 'theta');
expect(branchInfo.tree).toEqual([ expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'beta' }), expect.objectContaining({
jasmine.objectContaining({ name: 'gamma' }), name: 'beta',
jasmine.objectContaining({ name: 'theta' }), }),
expect.objectContaining({
name: 'gamma',
}),
expect.objectContaining({
name: 'theta',
}),
]); ]);
utils.swapInParentTreeWithSorting(localState, gamma.key, 'alpha'); utils.swapInParentTreeWithSorting(localState, gamma.key, 'alpha');
expect(branchInfo.tree).toEqual([ expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'alpha' }), expect.objectContaining({
jasmine.objectContaining({ name: 'beta' }), name: 'alpha',
jasmine.objectContaining({ name: 'theta' }), }),
expect.objectContaining({
name: 'beta',
}),
expect.objectContaining({
name: 'theta',
}),
]); ]);
utils.swapInParentTreeWithSorting(localState, beta.key, 'gamma'); utils.swapInParentTreeWithSorting(localState, beta.key, 'gamma');
expect(branchInfo.tree).toEqual([ expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'alpha' }), expect.objectContaining({
jasmine.objectContaining({ name: 'gamma' }), name: 'alpha',
jasmine.objectContaining({ name: 'theta' }), }),
expect.objectContaining({
name: 'gamma',
}),
expect.objectContaining({
name: 'theta',
}),
]); ]);
}); });
}); });
...@@ -587,11 +605,26 @@ describe('Multi-file store utils', () => { ...@@ -587,11 +605,26 @@ describe('Multi-file store utils', () => {
describe('cleanTrailingSlash', () => { describe('cleanTrailingSlash', () => {
[ [
{ input: '', output: '' }, {
{ input: 'abc', output: 'abc' }, input: '',
{ input: 'abc/', output: 'abc' }, output: '',
{ input: 'abc/def', output: 'abc/def' }, },
{ input: 'abc/def/', output: 'abc/def' }, {
input: 'abc',
output: 'abc',
},
{
input: 'abc/',
output: 'abc',
},
{
input: 'abc/def',
output: 'abc/def',
},
{
input: 'abc/def/',
output: 'abc/def',
},
].forEach(({ input, output }) => { ].forEach(({ input, output }) => {
it(`cleans trailing slash from string "${input}"`, () => { it(`cleans trailing slash from string "${input}"`, () => {
expect(utils.cleanTrailingSlash(input)).toEqual(output); expect(utils.cleanTrailingSlash(input)).toEqual(output);
...@@ -601,13 +634,34 @@ describe('Multi-file store utils', () => { ...@@ -601,13 +634,34 @@ describe('Multi-file store utils', () => {
describe('pathsAreEqual', () => { describe('pathsAreEqual', () => {
[ [
{ args: ['abc', 'abc'], output: true }, {
{ args: ['abc', 'def'], output: false }, args: ['abc', 'abc'],
{ args: ['abc/', 'abc'], output: true }, output: true,
{ args: ['abc/abc', 'abc'], output: false }, },
{ args: ['/', ''], output: true }, {
{ args: ['', '/'], output: true }, args: ['abc', 'def'],
{ args: [false, '/'], output: true }, output: false,
},
{
args: ['abc/', 'abc'],
output: true,
},
{
args: ['abc/abc', 'abc'],
output: false,
},
{
args: ['/', ''],
output: true,
},
{
args: ['', '/'],
output: true,
},
{
args: [false, '/'],
output: true,
},
].forEach(({ args, output }) => { ].forEach(({ args, output }) => {
it(`cleans and tests equality (${JSON.stringify(args)})`, () => { it(`cleans and tests equality (${JSON.stringify(args)})`, () => {
expect(utils.pathsAreEqual(...args)).toEqual(output); expect(utils.pathsAreEqual(...args)).toEqual(output);
...@@ -618,10 +672,22 @@ describe('Multi-file store utils', () => { ...@@ -618,10 +672,22 @@ describe('Multi-file store utils', () => {
describe('addFinalNewlineIfNeeded', () => { describe('addFinalNewlineIfNeeded', () => {
it('adds a newline if it doesnt already exist', () => { it('adds a newline if it doesnt already exist', () => {
[ [
{ input: 'some text', output: 'some text\n' }, {
{ input: 'some text\n', output: 'some text\n' }, input: 'some text',
{ input: 'some text\n\n', output: 'some text\n\n' }, output: 'some text\n',
{ input: 'some\n text', output: 'some\n text\n' }, },
{
input: 'some text\n',
output: 'some text\n',
},
{
input: 'some text\n\n',
output: 'some text\n\n',
},
{
input: 'some\n text',
output: 'some\n text\n',
},
].forEach(({ input, output }) => { ].forEach(({ input, output }) => {
expect(utils.addFinalNewlineIfNeeded(input)).toEqual(output); expect(utils.addFinalNewlineIfNeeded(input)).toEqual(output);
}); });
......
...@@ -26,15 +26,18 @@ describe('WebIDE utils', () => { ...@@ -26,15 +26,18 @@ describe('WebIDE utils', () => {
entry.deleted = true; entry.deleted = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.deleted); expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.deleted);
}); });
it('renders "addition" icon for temp entries', () => { it('renders "addition" icon for temp entries', () => {
entry.tempFile = true; entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.addition); expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.addition);
}); });
it('renders "modified" icon for newly-renamed entries', () => { it('renders "modified" icon for newly-renamed entries', () => {
entry.prevPath = 'foo/bar'; entry.prevPath = 'foo/bar';
entry.tempFile = false; entry.tempFile = false;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified); expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
}); });
it('renders "modified" icon even for temp entries if they are newly-renamed', () => { it('renders "modified" icon even for temp entries if they are newly-renamed', () => {
entry.prevPath = 'foo/bar'; entry.prevPath = 'foo/bar';
entry.tempFile = true; entry.tempFile = true;
......
import * as pathUtils from 'path'; export * from '../../frontend/ide/helpers';
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,
};
}, {});
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