Commit 6095983a authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'convert-ide-specs-to-jest' into 'master'

Convert Web IDE specs to jest

See merge request gitlab-org/gitlab!21153
parents 469169ef 198a5886
<script>
import { mapActions, mapState } from 'vuex';
import _ from 'underscore';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import Item from './item.vue';
export default {
......
<script>
import $ from 'jquery';
import { mapActions, mapState } from 'vuex';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
export default {
components: {
......
<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import Icon from '~/vue_shared/components/icon.vue';
import { GlSkeletonLoading } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import FileRow from '~/vue_shared/components/file_row.vue';
import NavDropdown from './nav_dropdown.vue';
import FileRowExtra from './file_row_extra.vue';
......
<script>
import { mapActions, mapState } from 'vuex';
import _ from 'underscore';
import { GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Item from './item.vue';
import TokenedInput from '../shared/tokened_input.vue';
......
<script>
import $ from 'jquery';
import { mapActions, mapState, mapGetters } from 'vuex';
import flash from '~/flash';
import { __, sprintf, s__ } from '~/locale';
import { mapActions, mapState, mapGetters } from 'vuex';
import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue';
import { modalTypes } from '../../constants';
......
<script>
import { listen } from 'codesandbox-api';
import Icon from '~/vue_shared/components/icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
export default {
components: {
......
<script>
import { __, sprintf } from '~/locale';
import { mapActions } from 'vuex';
import { __, sprintf } from '~/locale';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import Icon from '~/vue_shared/components/icon.vue';
......
import $ from 'jquery';
import Vue from 'vue';
import _ from 'underscore';
import { __, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility';
import flash from '~/flash';
import _ from 'underscore';
import * as types from './mutation_types';
import { decorateFiles } from '../lib/files';
import { stageKeys } from '../constants';
......
import Vue from 'vue';
import mountCompontent from 'spec/helpers/vue_mount_component_helper';
import mountCompontent from 'helpers/vue_mount_component_helper';
import router from '~/ide/ide_router';
import Item from '~/ide/components/branches/item.vue';
import { getTimeago } from '~/lib/utils/datetime_utility';
......@@ -30,7 +30,7 @@ describe('IDE branch item', () => {
it('renders branch name and timeago', () => {
const timeText = getTimeago().format(TEST_BRANCH.committedDate);
expect(vm.$el).toContainText(TEST_BRANCH.name);
expect(vm.$el.textContent).toContain(TEST_BRANCH.name);
expect(vm.$el.querySelector('time')).toHaveText(timeText);
expect(vm.$el.querySelector('.ic-mobile-issue-close')).toBe(null);
});
......@@ -39,7 +39,7 @@ describe('IDE branch item', () => {
const expectedHref = router.resolve(`/project/${TEST_PROJECT_ID}/edit/${TEST_BRANCH.name}`)
.href;
expect(vm.$el).toMatch('a');
expect(vm.$el.textContent).toMatch('a');
expect(vm.$el).toHaveAttr('href', expectedHref);
});
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import List from '~/ide/components/branches/search_list.vue';
import Item from '~/ide/components/branches/item.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { branches } from '../../mock_data';
const localVue = createLocalVue();
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import List from '~/ide/components/merge_requests/list.vue';
import Item from '~/ide/components/merge_requests/item.vue';
import TokenedInput from '~/ide/components/shared/tokened_input.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { mergeRequests as mergeRequestsMock } from '../../mock_data';
const localVue = createLocalVue();
......
......@@ -3,7 +3,7 @@ import '~/behaviors/markdown/render_gfm';
import { createStore } from '~/ide/stores';
import RightPane from '~/ide/components/panes/right.vue';
import { rightSidebarViews } from '~/ide/constants';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
describe('IDE right pane', () => {
let Component;
......@@ -56,7 +56,7 @@ describe('IDE right pane', () => {
describe('click', () => {
beforeEach(() => {
spyOn(vm, 'open');
jest.spyOn(vm, 'open').mockReturnValue();
});
it('sets view to merge request', done => {
......@@ -74,7 +74,9 @@ describe('IDE right pane', () => {
describe('live preview', () => {
it('renders live preview button', done => {
Vue.set(vm.$store.state.entries, 'package.json', { name: 'package.json' });
Vue.set(vm.$store.state.entries, 'package.json', {
name: 'package.json',
});
vm.$store.state.clientsidePreviewEnabled = true;
vm.$nextTick(() => {
......
import { shallowMount, createLocalVue } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import List from '~/ide/components/pipelines/list.vue';
import JobsList from '~/ide/components/jobs/list.vue';
import Tab from '~/vue_shared/components/tabs/tab.vue';
import CiIcon from '~/vue_shared/components/ci_icon.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { TEST_HOST } from 'helpers/test_constants';
import { pipelines } from '../../../../javascripts/ide/mock_data';
const localVue = createLocalVue();
......
import Vue from 'vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import mountComponent from 'helpers/vue_mount_component_helper';
import { TEST_HOST } from 'helpers/test_constants';
import ClientsideNavigator from '~/ide/components/preview/navigator.vue';
describe('IDE clientside preview navigator', () => {
......@@ -12,14 +13,9 @@ describe('IDE clientside preview navigator', () => {
});
beforeEach(() => {
manager = {
bundlerURL: gl.TEST_HOST,
iframe: { src: '' },
};
manager = { bundlerURL: TEST_HOST, iframe: { src: '' } };
vm = mountComponent(Component, {
manager,
});
vm = mountComponent(Component, { manager });
});
afterEach(() => {
......@@ -47,7 +43,7 @@ describe('IDE clientside preview navigator', () => {
it('calls back method when clicking back button', done => {
vm.navigationStack.push('/test');
vm.navigationStack.push('/test2');
spyOn(vm, 'back');
jest.spyOn(vm, 'back').mockReturnValue();
vm.$nextTick(() => {
vm.$el.querySelector('.ide-navigator-btn').click();
......@@ -60,7 +56,7 @@ describe('IDE clientside preview navigator', () => {
it('calls forward method when clicking forward button', done => {
vm.forwardNavigationStack.push('/test');
spyOn(vm, 'forward');
jest.spyOn(vm, 'forward').mockReturnValue();
vm.$nextTick(() => {
vm.$el.querySelectorAll('.ide-navigator-btn')[1].click();
......@@ -73,49 +69,35 @@ describe('IDE clientside preview navigator', () => {
describe('onUrlChange', () => {
it('updates the path', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url` });
expect(vm.path).toBe('/url');
});
it('sets currentBrowsingIndex 0 if not already set', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url` });
expect(vm.currentBrowsingIndex).toBe(0);
});
it('increases currentBrowsingIndex if path doesnt match', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url` });
vm.onUrlChange({
url: `${gl.TEST_HOST}/url2`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url2` });
expect(vm.currentBrowsingIndex).toBe(1);
});
it('does not increase currentBrowsingIndex if path matches', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url` });
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url` });
expect(vm.currentBrowsingIndex).toBe(0);
});
it('pushes path into navigation stack', () => {
vm.onUrlChange({
url: `${gl.TEST_HOST}/url`,
});
vm.onUrlChange({ url: `${TEST_HOST}/url` });
expect(vm.navigationStack).toEqual(['/url']);
});
......@@ -128,7 +110,7 @@ describe('IDE clientside preview navigator', () => {
vm.navigationStack.push('/test');
vm.navigationStack.push('/test2');
spyOn(vm, 'visitPath');
jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.back();
});
......@@ -152,7 +134,7 @@ describe('IDE clientside preview navigator', () => {
describe('forward', () => {
it('calls visitPath with first entry in forwardNavigationStack', () => {
spyOn(vm, 'visitPath');
jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.forwardNavigationStack.push('/test');
vm.forwardNavigationStack.push('/test2');
......@@ -165,7 +147,7 @@ describe('IDE clientside preview navigator', () => {
describe('refresh', () => {
it('calls refresh with current path', () => {
spyOn(vm, 'visitPath');
jest.spyOn(vm, 'visitPath').mockReturnValue();
vm.path = '/test';
......@@ -179,7 +161,7 @@ describe('IDE clientside preview navigator', () => {
it('updates iframe src with passed in path', () => {
vm.visitPath('/testpath');
expect(manager.iframe.src).toBe(`${gl.TEST_HOST}/testpath`);
expect(manager.iframe.src).toBe(`${TEST_HOST}/testpath`);
});
});
});
import * as pathUtils from 'path';
import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
import mergeRequestsState from '~/ide/stores/modules/merge_requests/state';
import pipelinesState from '~/ide/stores/modules/pipelines/state';
import branchesState from '~/ide/stores/modules/branches/state';
import fileTemplatesState from '~/ide/stores/modules/file_templates/state';
import paneState from '~/ide/stores/modules/pane/state';
export const resetStore = store => {
const newState = {
...state(),
commit: commitState(),
mergeRequests: mergeRequestsState(),
pipelines: pipelinesState(),
branches: branchesState(),
fileTemplates: fileTemplatesState(),
rightPane: paneState(),
};
store.replaceState(newState);
};
export const file = (name = 'name', id = name, type = '', parent = null) =>
decorateData({
id,
type,
icon: 'icon',
url: 'url',
name,
path: parent ? `${parent.path}/${name}` : name,
parentPath: parent ? parent.path : '',
lastCommit: {},
});
export const createEntriesFromPaths = paths =>
paths
.map(path => ({
name: pathUtils.basename(path),
dir: pathUtils.dirname(path),
ext: pathUtils.extname(path),
}))
.reduce((entries, path, idx) => {
const { name } = path;
const parent = path.dir ? entries[path.dir] : null;
const type = path.ext ? 'blob' : 'tree';
const entry = file(name, (idx + 1).toString(), type, parent);
return {
[entry.path]: entry,
...entries,
};
}, {});
......@@ -31,7 +31,7 @@ describe('IDE router', () => {
`/project/${PROJECT_NAMESPACE}/${PROJECT_NAME}`,
].forEach(route => {
it(`finds project path when route is "${route}"`, () => {
spyOn(store, 'dispatch').and.returnValue(new Promise(() => {}));
jest.spyOn(store, 'dispatch').mockReturnValue(new Promise(() => {}));
router.push(route);
......
......@@ -45,7 +45,9 @@ describe('IDE store getters', () => {
localState.currentMergeRequestId = 1;
localState.projects.abcproject = {
mergeRequests: {
1: { mergeId: 1 },
1: {
mergeId: 1,
},
},
};
......@@ -62,9 +64,21 @@ describe('IDE store getters', () => {
describe('allBlobs', () => {
beforeEach(() => {
Object.assign(localState.entries, {
index: { type: 'blob', name: 'index', lastOpenedAt: 0 },
app: { type: 'blob', name: 'blob', lastOpenedAt: 0 },
folder: { type: 'folder', name: 'folder', lastOpenedAt: 0 },
index: {
type: 'blob',
name: 'index',
lastOpenedAt: 0,
},
app: {
type: 'blob',
name: 'blob',
lastOpenedAt: 0,
},
folder: {
type: 'folder',
name: 'folder',
lastOpenedAt: 0,
},
});
});
......@@ -174,7 +188,7 @@ describe('IDE store getters', () => {
},
};
const localGetters = {
findBranch: jasmine.createSpy('findBranchSpy'),
findBranch: jest.fn(),
};
getters.currentBranch(localState, localGetters);
......@@ -251,7 +265,9 @@ describe('IDE store getters', () => {
describe('packageJson', () => {
it('returns package.json entry', () => {
localState.entries['package.json'] = { name: 'package.json' };
localState.entries['package.json'] = {
name: 'package.json',
};
expect(getters.packageJson(localState)).toEqual({
name: 'package.json',
......@@ -273,7 +289,9 @@ describe('IDE store getters', () => {
currentProject: {
default_branch: 'master',
},
currentBranch: { can_push: true },
currentBranch: {
can_push: true,
},
};
expect(getters.canPushToBranch({}, localGetters)).toBeTruthy();
......@@ -284,7 +302,9 @@ describe('IDE store getters', () => {
currentProject: {
default_branch: 'master',
},
currentBranch: { can_push: false },
currentBranch: {
can_push: false,
},
};
expect(getters.canPushToBranch({}, localGetters)).toBeFalsy();
......
import MockAdapter from 'axios-mock-adapter';
import testAction from 'spec/helpers/vuex_action_helper';
import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils';
import state from '~/ide/stores/modules/branches/state';
import * as types from '~/ide/stores/modules/branches/mutation_types';
......@@ -21,12 +21,8 @@ describe('IDE branches actions', () => {
beforeEach(() => {
mockedContext = {
dispatch() {},
rootState: {
currentProjectId: projectData.name_with_namespace,
},
rootGetters: {
currentProject: projectData,
},
rootState: { currentProjectId: projectData.name_with_namespace },
rootGetters: { currentProject: projectData },
state: state(),
};
......@@ -70,7 +66,7 @@ describe('IDE branches actions', () => {
type: 'setErrorMessage',
payload: {
text: 'Error loading branches.',
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: { search: TEST_SEARCH },
},
......@@ -105,15 +101,12 @@ describe('IDE branches actions', () => {
});
it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchBranches(mockedContext, { search: TEST_SEARCH });
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: jasmine.objectContaining({
search: TEST_SEARCH,
sort: 'updated_desc',
}),
expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: expect.objectContaining({ search: TEST_SEARCH, sort: 'updated_desc' }),
});
});
......@@ -126,10 +119,7 @@ describe('IDE branches actions', () => {
[
{ type: 'requestBranches' },
{ type: 'resetBranches' },
{
type: 'receiveBranchesSuccess',
payload: branches,
},
{ type: 'receiveBranchesSuccess', payload: branches },
],
done,
);
......@@ -150,10 +140,7 @@ describe('IDE branches actions', () => {
[
{ type: 'requestBranches' },
{ type: 'resetBranches' },
{
type: 'receiveBranchesError',
payload: { search: TEST_SEARCH },
},
{ type: 'receiveBranchesError', payload: { search: TEST_SEARCH } },
],
done,
);
......
......@@ -10,7 +10,7 @@ describe('IDE branches mutations', () => {
mockedState = state();
});
describe(types.REQUEST_BRANCHES, () => {
describe('REQUEST_BRANCHES', () => {
it('sets loading to true', () => {
mutations[types.REQUEST_BRANCHES](mockedState);
......@@ -18,7 +18,7 @@ describe('IDE branches mutations', () => {
});
});
describe(types.RECEIVE_BRANCHES_ERROR, () => {
describe('RECEIVE_BRANCHES_ERROR', () => {
it('sets loading to false', () => {
mutations[types.RECEIVE_BRANCHES_ERROR](mockedState);
......@@ -26,7 +26,7 @@ describe('IDE branches mutations', () => {
});
});
describe(types.RECEIVE_BRANCHES_SUCCESS, () => {
describe('RECEIVE_BRANCHES_SUCCESS', () => {
it('sets branches', () => {
const expectedBranches = branches.map(branch => ({
name: branch.name,
......@@ -39,7 +39,7 @@ describe('IDE branches mutations', () => {
});
});
describe(types.RESET_BRANCHES, () => {
describe('RESET_BRANCHES', () => {
it('clears branches array', () => {
mockedState.branches = ['test'];
......
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 createState from '~/ide/stores/modules/file_templates/state';
import * as actions from '~/ide/stores/modules/file_templates/actions';
......@@ -43,7 +43,7 @@ describe('IDE file templates actions', () => {
{
type: 'setErrorMessage',
payload: {
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
text: 'Error loading template types.',
},
......@@ -82,7 +82,7 @@ describe('IDE file templates actions', () => {
});
it('rejects if selectedTemplateType is empty', done => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
actions
.fetchTemplateTypes({ dispatch, state })
......@@ -95,9 +95,7 @@ describe('IDE file templates actions', () => {
});
it('dispatches actions', done => {
state.selectedTemplateType = {
key: 'licenses',
};
state.selectedTemplateType = { key: 'licenses' };
testAction(
actions.fetchTemplateTypes,
......@@ -105,17 +103,9 @@ describe('IDE file templates actions', () => {
state,
[],
[
{
type: 'requestTemplateTypes',
},
{
type: 'receiveTemplateTypesSuccess',
payload: pages[0],
},
{
type: 'receiveTemplateTypesSuccess',
payload: pages[0].concat(pages[1]),
},
{ type: 'requestTemplateTypes' },
{ type: 'receiveTemplateTypesSuccess', payload: pages[0] },
{ type: 'receiveTemplateTypesSuccess', payload: pages[0].concat(pages[1]) },
{
type: 'receiveTemplateTypesSuccess',
payload: pages[0].concat(pages[1]).concat(pages[2]),
......@@ -132,23 +122,14 @@ describe('IDE file templates actions', () => {
});
it('dispatches actions', done => {
state.selectedTemplateType = {
key: 'licenses',
};
state.selectedTemplateType = { key: 'licenses' };
testAction(
actions.fetchTemplateTypes,
null,
state,
[],
[
{
type: 'requestTemplateTypes',
},
{
type: 'receiveTemplateTypesError',
},
],
[{ type: 'requestTemplateTypes' }, { type: 'receiveTemplateTypesError' }],
done,
);
});
......@@ -157,16 +138,11 @@ describe('IDE file templates actions', () => {
describe('setSelectedTemplateType', () => {
it('commits SET_SELECTED_TEMPLATE_TYPE', () => {
const commit = jasmine.createSpy('commit');
const commit = jest.fn().mockName('commit');
const options = {
commit,
dispatch() {},
rootGetters: {
activeFile: {
name: 'test',
prevPath: '',
},
},
rootGetters: { activeFile: { name: 'test', prevPath: '' } },
};
actions.setSelectedTemplateType(options, { name: 'test' });
......@@ -175,17 +151,12 @@ describe('IDE file templates actions', () => {
});
it('dispatches discardFileChanges if prevPath matches templates name', () => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
const options = {
commit() {},
dispatch,
rootGetters: {
activeFile: {
name: 'test',
path: 'test',
prevPath: 'test',
},
},
rootGetters: { activeFile: { name: 'test', path: 'test', prevPath: 'test' } },
};
actions.setSelectedTemplateType(options, { name: 'test' });
......@@ -194,27 +165,19 @@ describe('IDE file templates actions', () => {
});
it('dispatches renameEntry if file name doesnt match', () => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
const options = {
commit() {},
dispatch,
rootGetters: {
activeFile: {
name: 'oldtest',
path: 'oldtest',
prevPath: '',
},
},
rootGetters: { activeFile: { name: 'oldtest', path: 'oldtest', prevPath: '' } },
};
actions.setSelectedTemplateType(options, { name: 'test' });
expect(dispatch).toHaveBeenCalledWith(
'renameEntry',
{
path: 'oldtest',
name: 'test',
},
{ path: 'oldtest', name: 'test' },
{ root: true },
);
});
......@@ -231,7 +194,7 @@ describe('IDE file templates actions', () => {
{
type: 'setErrorMessage',
payload: {
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
text: 'Error loading template.',
actionPayload: 'test',
......@@ -246,18 +209,16 @@ describe('IDE file templates actions', () => {
describe('fetchTemplate', () => {
describe('success', () => {
beforeEach(() => {
mock.onGet(/api\/(.*)\/templates\/licenses\/mit/).replyOnce(200, {
content: 'MIT content',
});
mock.onGet(/api\/(.*)\/templates\/licenses\/testing/).replyOnce(200, {
content: 'testing content',
});
mock
.onGet(/api\/(.*)\/templates\/licenses\/mit/)
.replyOnce(200, { content: 'MIT content' });
mock
.onGet(/api\/(.*)\/templates\/licenses\/testing/)
.replyOnce(200, { content: 'testing content' });
});
it('dispatches setFileTemplate if template already has content', done => {
const template = {
content: 'already has content',
};
const template = { content: 'already has content' };
testAction(
actions.fetchTemplate,
......@@ -270,13 +231,9 @@ describe('IDE file templates actions', () => {
});
it('dispatches success', done => {
const template = {
key: 'mit',
};
const template = { key: 'mit' };
state.selectedTemplateType = {
key: 'licenses',
};
state.selectedTemplateType = { key: 'licenses' };
testAction(
actions.fetchTemplate,
......@@ -289,13 +246,9 @@ describe('IDE file templates actions', () => {
});
it('dispatches success and uses name key for API call', done => {
const template = {
name: 'testing',
};
const template = { name: 'testing' };
state.selectedTemplateType = {
key: 'licenses',
};
state.selectedTemplateType = { key: 'licenses' };
testAction(
actions.fetchTemplate,
......@@ -314,13 +267,9 @@ describe('IDE file templates actions', () => {
});
it('dispatches error', done => {
const template = {
name: 'testing',
};
const template = { name: 'testing' };
state.selectedTemplateType = {
key: 'licenses',
};
state.selectedTemplateType = { key: 'licenses' };
testAction(
actions.fetchTemplate,
......@@ -336,11 +285,9 @@ describe('IDE file templates actions', () => {
describe('setFileTemplate', () => {
it('dispatches changeFileContent', () => {
const dispatch = jasmine.createSpy('dispatch');
const commit = jasmine.createSpy('commit');
const rootGetters = {
activeFile: { path: 'test' },
};
const dispatch = jest.fn().mockName('dispatch');
const commit = jest.fn().mockName('commit');
const rootGetters = { activeFile: { path: 'test' } };
actions.setFileTemplate({ dispatch, commit, rootGetters }, { content: 'content' });
......@@ -352,11 +299,9 @@ describe('IDE file templates actions', () => {
});
it('commits SET_UPDATE_SUCCESS', () => {
const dispatch = jasmine.createSpy('dispatch');
const commit = jasmine.createSpy('commit');
const rootGetters = {
activeFile: { path: 'test' },
};
const dispatch = jest.fn().mockName('dispatch');
const commit = jest.fn().mockName('commit');
const rootGetters = { activeFile: { path: 'test' } };
actions.setFileTemplate({ dispatch, commit, rootGetters }, { content: 'content' });
......@@ -366,11 +311,9 @@ describe('IDE file templates actions', () => {
describe('undoFileTemplate', () => {
it('dispatches changeFileContent', () => {
const dispatch = jasmine.createSpy('dispatch');
const commit = jasmine.createSpy('commit');
const rootGetters = {
activeFile: { path: 'test', raw: 'raw content' },
};
const dispatch = jest.fn().mockName('dispatch');
const commit = jest.fn().mockName('commit');
const rootGetters = { activeFile: { path: 'test', raw: 'raw content' } };
actions.undoFileTemplate({ dispatch, commit, rootGetters });
......@@ -382,11 +325,9 @@ describe('IDE file templates actions', () => {
});
it('commits SET_UPDATE_SUCCESS', () => {
const dispatch = jasmine.createSpy('dispatch');
const commit = jasmine.createSpy('commit');
const rootGetters = {
activeFile: { path: 'test', raw: 'raw content' },
};
const dispatch = jest.fn().mockName('dispatch');
const commit = jest.fn().mockName('commit');
const rootGetters = { activeFile: { path: 'test', raw: 'raw content' } };
actions.undoFileTemplate({ dispatch, commit, rootGetters });
......@@ -394,18 +335,12 @@ describe('IDE file templates actions', () => {
});
it('dispatches discardFileChanges if file has prevPath', () => {
const dispatch = jasmine.createSpy('dispatch');
const rootGetters = {
activeFile: { path: 'test', prevPath: 'newtest', raw: 'raw content' },
};
const dispatch = jest.fn().mockName('dispatch');
const rootGetters = { activeFile: { path: 'test', prevPath: 'newtest', raw: 'raw content' } };
actions.undoFileTemplate({ dispatch, commit() {}, rootGetters });
expect(dispatch.calls.mostRecent().args).toEqual([
'discardFileChanges',
'test',
{ root: true },
]);
expect(dispatch).toHaveBeenCalledWith('discardFileChanges', 'test', { root: true });
});
});
});
......@@ -19,9 +19,7 @@ describe('IDE merge requests actions', () => {
beforeEach(() => {
mockedState = state();
mockedRootState = {
currentProjectId: 7,
};
mockedRootState = { currentProjectId: 7 };
mock = new MockAdapter(axios);
});
......@@ -54,7 +52,7 @@ describe('IDE merge requests actions', () => {
type: 'setErrorMessage',
payload: {
text: 'Error loading merge requests.',
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: { type: 'created', search: '' },
},
......@@ -71,12 +69,7 @@ describe('IDE merge requests actions', () => {
receiveMergeRequestsSuccess,
mergeRequests,
mockedState,
[
{
type: types.RECEIVE_MERGE_REQUESTS_SUCCESS,
payload: mergeRequests,
},
],
[{ type: types.RECEIVE_MERGE_REQUESTS_SUCCESS, payload: mergeRequests }],
[],
done,
);
......@@ -94,36 +87,34 @@ describe('IDE merge requests actions', () => {
});
it('calls API with params', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: 'created' },
);
{
dispatch() {},
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: {
scope: 'created-by-me',
state: 'opened',
search: '',
state: mockedState,
rootState: mockedRootState,
},
{ type: 'created' },
);
expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: { scope: 'created-by-me', state: 'opened', search: '' },
});
});
it('calls API with search', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{ type: 'created', search: 'testing search' },
);
{
dispatch() {},
expect(apiSpy).toHaveBeenCalledWith(jasmine.anything(), {
params: {
scope: 'created-by-me',
state: 'opened',
search: 'testing search',
state: mockedState,
rootState: mockedRootState,
},
{ type: 'created', search: 'testing search' },
);
expect(apiSpy).toHaveBeenCalledWith(expect.anything(), {
params: { scope: 'created-by-me', state: 'opened', search: 'testing search' },
});
});
......@@ -136,10 +127,7 @@ describe('IDE merge requests actions', () => {
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{
type: 'receiveMergeRequestsSuccess',
payload: mergeRequests,
},
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests },
],
done,
);
......@@ -152,21 +140,19 @@ describe('IDE merge requests actions', () => {
});
it('calls API with project', () => {
const apiSpy = spyOn(axios, 'get').and.callThrough();
const apiSpy = jest.spyOn(axios, 'get');
fetchMergeRequests(
{ dispatch() {}, state: mockedState, rootState: mockedRootState },
{
dispatch() {},
state: mockedState,
rootState: mockedRootState,
},
{ type: null, search: 'testing search' },
);
expect(apiSpy).toHaveBeenCalledWith(
jasmine.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`),
{
params: {
state: 'opened',
search: 'testing search',
},
},
expect.stringMatching(`projects/${mockedRootState.currentProjectId}/merge_requests`),
{ params: { state: 'opened', search: 'testing search' } },
);
});
......@@ -179,10 +165,7 @@ describe('IDE merge requests actions', () => {
[
{ type: 'requestMergeRequests' },
{ type: 'resetMergeRequests' },
{
type: 'receiveMergeRequestsSuccess',
payload: mergeRequests,
},
{ type: 'receiveMergeRequestsSuccess', payload: mergeRequests },
],
done,
);
......
import { TEST_HOST } from 'helpers/test_constants';
import state from '~/ide/stores/modules/merge_requests/state';
import mutations from '~/ide/stores/modules/merge_requests/mutations';
import * as types from '~/ide/stores/modules/merge_requests/mutation_types';
......@@ -10,7 +11,7 @@ describe('IDE merge requests mutations', () => {
mockedState = state();
});
describe(types.REQUEST_MERGE_REQUESTS, () => {
describe('REQUEST_MERGE_REQUESTS', () => {
it('sets loading to true', () => {
mutations[types.REQUEST_MERGE_REQUESTS](mockedState);
......@@ -18,7 +19,7 @@ describe('IDE merge requests mutations', () => {
});
});
describe(types.RECEIVE_MERGE_REQUESTS_ERROR, () => {
describe('RECEIVE_MERGE_REQUESTS_ERROR', () => {
it('sets loading to false', () => {
mutations[types.RECEIVE_MERGE_REQUESTS_ERROR](mockedState);
......@@ -26,9 +27,9 @@ describe('IDE merge requests mutations', () => {
});
});
describe(types.RECEIVE_MERGE_REQUESTS_SUCCESS, () => {
describe('RECEIVE_MERGE_REQUESTS_SUCCESS', () => {
it('sets merge requests', () => {
gon.gitlab_url = gl.TEST_HOST;
gon.gitlab_url = TEST_HOST;
mutations[types.RECEIVE_MERGE_REQUESTS_SUCCESS](mockedState, mergeRequests);
expect(mockedState.mergeRequests).toEqual([
......@@ -43,7 +44,7 @@ describe('IDE merge requests mutations', () => {
});
});
describe(types.RESET_MERGE_REQUESTS, () => {
describe('RESET_MERGE_REQUESTS', () => {
it('clears merge request array', () => {
mockedState.mergeRequests = ['test'];
......
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/ide/stores/modules/pane/actions';
import * as types from '~/ide/stores/modules/pane/mutation_types';
describe('IDE pane module actions', () => {
const TEST_VIEW = { name: 'test' };
const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true };
describe('toggleOpen', () => {
it('dispatches open if closed', done => {
testAction(
actions.toggleOpen,
TEST_VIEW,
{ isOpen: false },
[],
[{ type: 'open', payload: TEST_VIEW }],
done,
);
});
it('dispatches close if opened', done => {
testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }], done);
});
});
describe('open', () => {
it('commits SET_OPEN', done => {
testAction(actions.open, null, {}, [{ type: types.SET_OPEN, payload: true }], [], done);
});
it('commits SET_CURRENT_VIEW if view is given', done => {
testAction(
actions.open,
TEST_VIEW,
{},
[
{ type: types.SET_OPEN, payload: true },
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name },
],
[],
done,
);
});
it('commits KEEP_ALIVE_VIEW if keepAlive is true', done => {
testAction(
actions.open,
TEST_VIEW_KEEP_ALIVE,
{},
[
{ type: types.SET_OPEN, payload: true },
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
{ type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
],
[],
done,
);
});
});
describe('close', () => {
it('commits SET_OPEN', done => {
testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], [], done);
});
});
});
import Visibility from 'visibilityjs';
import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'helpers/test_constants';
import axios from '~/lib/utils/axios_utils';
import {
requestLatestPipeline,
......@@ -78,7 +79,7 @@ describe('IDE pipelines actions', () => {
type: 'setErrorMessage',
payload: {
text: 'An error occurred whilst fetching the latest pipeline.',
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: null,
},
......@@ -91,38 +92,28 @@ describe('IDE pipelines actions', () => {
});
describe('receiveLatestPipelineSuccess', () => {
const rootGetters = {
lastCommit: { id: '123' },
};
const rootGetters = { lastCommit: { id: '123' } };
let commit;
beforeEach(() => {
commit = jasmine.createSpy('commit');
commit = jest.fn().mockName('commit');
});
it('commits pipeline', () => {
receiveLatestPipelineSuccess({ rootGetters, commit }, { pipelines });
expect(commit.calls.argsFor(0)).toEqual([
types.RECEIVE_LASTEST_PIPELINE_SUCCESS,
pipelines[0],
]);
expect(commit).toHaveBeenCalledWith(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, pipelines[0]);
});
it('commits false when there are no pipelines', () => {
receiveLatestPipelineSuccess({ rootGetters, commit }, { pipelines: [] });
expect(commit.calls.argsFor(0)).toEqual([types.RECEIVE_LASTEST_PIPELINE_SUCCESS, false]);
expect(commit).toHaveBeenCalledWith(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, false);
});
});
describe('fetchLatestPipeline', () => {
beforeEach(() => {
jasmine.clock().install();
});
beforeEach(() => {});
afterEach(() => {
jasmine.clock().uninstall();
stopPipelinePolling();
clearEtagPoll();
});
......@@ -135,10 +126,10 @@ describe('IDE pipelines actions', () => {
});
it('dispatches request', done => {
spyOn(axios, 'get').and.callThrough();
spyOn(Visibility, 'hidden').and.returnValue(false);
jest.spyOn(axios, 'get');
jest.spyOn(Visibility, 'hidden').mockReturnValue(false);
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
const rootGetters = {
lastCommit: { id: 'abc123def456ghi789jkl' },
currentProject: { path_with_namespace: 'abc/def' },
......@@ -146,31 +137,29 @@ describe('IDE pipelines actions', () => {
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))
.then(() => {
expect(axios.get).toHaveBeenCalled();
expect(axios.get.calls.count()).toBe(1);
expect(dispatch.calls.argsFor(1)).toEqual([
expect(axios.get).toHaveBeenCalledTimes(1);
expect(dispatch).toHaveBeenCalledWith(
'receiveLatestPipelineSuccess',
jasmine.anything(),
]);
expect.anything(),
);
jasmine.clock().tick(10000);
jest.advanceTimersByTime(10000);
})
.then(() => new Promise(resolve => requestAnimationFrame(resolve)))
.then(() => {
expect(axios.get).toHaveBeenCalled();
expect(axios.get.calls.count()).toBe(2);
expect(dispatch.calls.argsFor(2)).toEqual([
expect(axios.get).toHaveBeenCalledTimes(2);
expect(dispatch).toHaveBeenCalledWith(
'receiveLatestPipelineSuccess',
jasmine.anything(),
]);
expect.anything(),
);
})
.then(done)
.catch(done.fail);
......@@ -183,7 +172,7 @@ describe('IDE pipelines actions', () => {
});
it('dispatches error', done => {
const dispatch = jasmine.createSpy('dispatch');
const dispatch = jest.fn().mockName('dispatch');
const rootGetters = {
lastCommit: { id: 'abc123def456ghi789jkl' },
currentProject: { path_with_namespace: 'abc/def' },
......@@ -191,14 +180,11 @@ describe('IDE pipelines actions', () => {
fetchLatestPipeline({ dispatch, rootGetters });
jasmine.clock().tick(1500);
jest.advanceTimersByTime(1500);
new Promise(resolve => requestAnimationFrame(resolve))
.then(() => {
expect(dispatch.calls.argsFor(1)).toEqual([
'receiveLatestPipelineError',
jasmine.anything(),
]);
expect(dispatch).toHaveBeenCalledWith('receiveLatestPipelineError', expect.anything());
})
.then(done)
.catch(done.fail);
......@@ -224,7 +210,7 @@ describe('IDE pipelines actions', () => {
type: 'setErrorMessage',
payload: {
text: 'An error occurred whilst loading the pipelines jobs.',
action: jasmine.anything(),
action: expect.anything(),
actionText: 'Please try again',
actionPayload: { id: 1 },
},
......@@ -249,10 +235,7 @@ describe('IDE pipelines actions', () => {
});
describe('fetchJobs', () => {
const stage = {
id: 1,
dropdownPath: `${gl.TEST_HOST}/jobs`,
};
const stage = { id: 1, dropdownPath: `${TEST_HOST}/jobs` };
describe('success', () => {
beforeEach(() => {
......@@ -361,7 +344,7 @@ describe('IDE pipelines actions', () => {
type: 'setErrorMessage',
payload: {
text: 'An error occurred whilst fetching the job trace.',
action: jasmine.any(Function),
action: expect.any(Function),
actionText: 'Please try again',
actionPayload: null,
},
......@@ -387,15 +370,13 @@ describe('IDE pipelines actions', () => {
describe('fetchJobTrace', () => {
beforeEach(() => {
mockedState.detailJob = {
path: `${gl.TEST_HOST}/project/builds`,
};
mockedState.detailJob = { path: `${TEST_HOST}/project/builds` };
});
describe('success', () => {
beforeEach(() => {
spyOn(axios, 'get').and.callThrough();
mock.onGet(`${gl.TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' });
jest.spyOn(axios, 'get');
mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(200, { html: 'html' });
});
it('dispatches request', done => {
......@@ -413,9 +394,12 @@ describe('IDE pipelines actions', () => {
});
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() {},
});
expect(axios.get).toHaveBeenCalledWith(`${TEST_HOST}/project/builds/trace`, {
params: { format: 'json' },
});
});
......@@ -423,7 +407,7 @@ describe('IDE pipelines actions', () => {
describe('error', () => {
beforeEach(() => {
mock.onGet(`${gl.TEST_HOST}/project/builds/trace`).replyOnce(500);
mock.onGet(`${TEST_HOST}/project/builds/trace`).replyOnce(500);
});
it('dispatches error', done => {
......
......@@ -10,7 +10,7 @@ describe('IDE pipelines mutations', () => {
mockedState = state();
});
describe(types.REQUEST_LATEST_PIPELINE, () => {
describe('REQUEST_LATEST_PIPELINE', () => {
it('sets loading to true', () => {
mutations[types.REQUEST_LATEST_PIPELINE](mockedState);
......@@ -18,7 +18,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_LASTEST_PIPELINE_ERROR, () => {
describe('RECEIVE_LASTEST_PIPELINE_ERROR', () => {
it('sets loading to false', () => {
mutations[types.RECEIVE_LASTEST_PIPELINE_ERROR](mockedState);
......@@ -26,7 +26,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_LASTEST_PIPELINE_SUCCESS, () => {
describe('RECEIVE_LASTEST_PIPELINE_SUCCESS', () => {
const itSetsPipelineLoadingStates = () => {
it('sets has loaded to true', () => {
expect(mockedState.hasLoadedPipeline).toBe(true);
......@@ -52,7 +52,7 @@ describe('IDE pipelines mutations', () => {
id: '51',
path: 'test',
commit: { id: '123' },
details: { status: jasmine.any(Object) },
details: { status: expect.any(Object) },
yamlError: undefined,
});
});
......@@ -95,12 +95,9 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.REQUEST_JOBS, () => {
describe('REQUEST_JOBS', () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
});
it('sets isLoading on stage', () => {
......@@ -110,12 +107,9 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOBS_ERROR, () => {
describe('RECEIVE_JOBS_ERROR', () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
});
it('sets isLoading on stage after error', () => {
......@@ -125,29 +119,22 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOBS_SUCCESS, () => {
describe('RECEIVE_JOBS_SUCCESS', () => {
let data;
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i }));
data = {
latest_statuses: [...jobs],
};
data = { latest_statuses: [...jobs] };
});
it('updates loading', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });
expect(mockedState.stages[0].isLoading).toBe(false);
});
it('sets jobs on stage', () => {
mutations[types.RECEIVE_JOBS_SUCCESS](mockedState, { id: mockedState.stages[0].id, data });
expect(mockedState.stages[0].jobs.length).toBe(jobs.length);
expect(mockedState.stages[0].jobs).toEqual(
jobs.map(job => ({
......@@ -164,13 +151,9 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.TOGGLE_STAGE_COLLAPSE, () => {
describe('TOGGLE_STAGE_COLLAPSE', () => {
beforeEach(() => {
mockedState.stages = stages.map((stage, i) => ({
...stage,
id: i,
isCollapsed: false,
}));
mockedState.stages = stages.map((stage, i) => ({ ...stage, id: i, isCollapsed: false }));
});
it('toggles collapsed state', () => {
......@@ -184,7 +167,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.SET_DETAIL_JOB, () => {
describe('SET_DETAIL_JOB', () => {
it('sets detail job', () => {
mutations[types.SET_DETAIL_JOB](mockedState, jobs[0]);
......@@ -192,7 +175,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.REQUEST_JOB_TRACE, () => {
describe('REQUEST_JOB_TRACE', () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0] };
});
......@@ -204,7 +187,7 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOB_TRACE_ERROR, () => {
describe('RECEIVE_JOB_TRACE_ERROR', () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true };
});
......@@ -216,14 +199,13 @@ describe('IDE pipelines mutations', () => {
});
});
describe(types.RECEIVE_JOB_TRACE_SUCCESS, () => {
describe('RECEIVE_JOB_TRACE_SUCCESS', () => {
beforeEach(() => {
mockedState.detailJob = { ...jobs[0], isLoading: true };
});
it('sets output on detail job', () => {
mutations[types.RECEIVE_JOB_TRACE_SUCCESS](mockedState, { html: 'html' });
expect(mockedState.detailJob.output).toBe('html');
expect(mockedState.detailJob.isLoading).toBe(false);
});
......
......@@ -9,10 +9,7 @@ describe('IDE store file mutations', () => {
beforeEach(() => {
localState = state();
localFile = {
...file(),
type: 'blob',
};
localFile = { ...file(), type: 'blob' };
localState.entries[localFile.path] = localFile;
});
......@@ -28,11 +25,7 @@ describe('IDE store file mutations', () => {
});
it('sets pending tab as not active', () => {
localState.openFiles.push({
...localFile,
pending: true,
active: true,
});
localState.openFiles.push({ ...localFile, pending: true, active: true });
mutations.SET_FILE_ACTIVE(localState, {
path: localFile.path,
......@@ -132,7 +125,7 @@ describe('IDE store file mutations', () => {
localFile,
].forEach(f => {
expect(f).toEqual(
jasmine.objectContaining({
expect.objectContaining({
path,
name,
raw: null,
......@@ -154,10 +147,7 @@ describe('IDE store file mutations', () => {
});
it('adds raw data to open pending file', () => {
localState.openFiles.push({
...localFile,
pending: true,
});
localState.openFiles.push({ ...localFile, pending: true });
mutations.SET_FILE_RAW_DATA(localState, {
file: localFile,
......@@ -168,11 +158,7 @@ describe('IDE store file mutations', () => {
});
it('does not add raw data to open pending tempFile file', () => {
localState.openFiles.push({
...localFile,
pending: true,
tempFile: true,
});
localState.openFiles.push({ ...localFile, pending: true, tempFile: true });
mutations.SET_FILE_RAW_DATA(localState, {
file: localFile,
......@@ -234,7 +220,9 @@ describe('IDE store file mutations', () => {
it('sets file mr change', () => {
mutations.SET_FILE_MERGE_REQUEST_CHANGE(localState, {
file: localFile,
mrChange: { diff: 'ABC' },
mrChange: {
diff: 'ABC',
},
});
expect(localFile.mrChange.diff).toBe('ABC');
......@@ -311,12 +299,7 @@ describe('IDE store file mutations', () => {
mutations.DISCARD_FILE_CHANGES(localState, localFile.path);
expect(localState.trees['gitlab-ce/master'].tree).toEqual([
{
...localFile,
deleted: false,
},
]);
expect(localState.trees['gitlab-ce/master'].tree).toEqual([{ ...localFile, deleted: false }]);
});
it('adds to parent tree if deleted', () => {
......@@ -328,12 +311,7 @@ describe('IDE store file mutations', () => {
mutations.DISCARD_FILE_CHANGES(localState, localFile.path);
expect(localState.entries.parentPath.tree).toEqual([
{
...localFile,
deleted: false,
},
]);
expect(localState.entries.parentPath.tree).toEqual([{ ...localFile, deleted: false }]);
});
});
......@@ -379,11 +357,7 @@ describe('IDE store file mutations', () => {
let f;
beforeEach(() => {
f = {
...file(),
type: 'blob',
staged: true,
};
f = { ...file(), type: 'blob', staged: true };
localState.stagedFiles.push(f);
localState.changedFiles.push(f);
......@@ -422,19 +396,16 @@ describe('IDE store file mutations', () => {
describe('ADD_PENDING_TAB', () => {
beforeEach(() => {
const f = {
...file('openFile'),
path: 'openFile',
active: true,
opened: true,
};
const f = { ...file('openFile'), path: 'openFile', active: true, opened: true };
localState.entries[f.path] = f;
localState.openFiles.push(f);
});
it('adds file into openFiles as pending', () => {
mutations.ADD_PENDING_TAB(localState, { file: localFile });
mutations.ADD_PENDING_TAB(localState, {
file: localFile,
});
expect(localState.openFiles.length).toBe(1);
expect(localState.openFiles[0].pending).toBe(true);
......@@ -445,11 +416,15 @@ describe('IDE store file mutations', () => {
const newFile = file('test');
localState.entries[newFile.path] = newFile;
mutations.ADD_PENDING_TAB(localState, { file: localFile });
mutations.ADD_PENDING_TAB(localState, {
file: localFile,
});
expect(localState.openFiles.length).toBe(1);
mutations.ADD_PENDING_TAB(localState, { file: file('test') });
mutations.ADD_PENDING_TAB(localState, {
file: file('test'),
});
expect(localState.openFiles.length).toBe(1);
expect(localState.openFiles[0].name).toBe('test');
......
......@@ -51,7 +51,9 @@ describe('Multi-file store tree mutations', () => {
});
it('keeps loading state', () => {
mutations.CREATE_TREE(localState, { treePath: 'project/master' });
mutations.CREATE_TREE(localState, {
treePath: 'project/master',
});
mutations.SET_DIRECTORY_DATA(localState, {
data,
treePath: 'project/master',
......
import { TEST_HOST } from 'helpers/test_constants';
import mutations from '~/ide/stores/mutations';
import state from '~/ide/stores/state';
import { file } from '../helpers';
......@@ -25,21 +26,30 @@ describe('Multi-file store mutations', () => {
describe('TOGGLE_LOADING', () => {
it('toggles loading of entry', () => {
mutations.TOGGLE_LOADING(localState, { entry });
mutations.TOGGLE_LOADING(localState, {
entry,
});
expect(entry.loading).toBeTruthy();
mutations.TOGGLE_LOADING(localState, { entry });
mutations.TOGGLE_LOADING(localState, {
entry,
});
expect(entry.loading).toBeFalsy();
});
it('toggles loading of entry and sets specific value', () => {
mutations.TOGGLE_LOADING(localState, { entry });
mutations.TOGGLE_LOADING(localState, {
entry,
});
expect(entry.loading).toBeTruthy();
mutations.TOGGLE_LOADING(localState, { entry, forceValue: true });
mutations.TOGGLE_LOADING(localState, {
entry,
forceValue: true,
});
expect(entry.loading).toBeTruthy();
});
......@@ -123,11 +133,7 @@ describe('Multi-file store mutations', () => {
mutations.CREATE_TMP_ENTRY(localState, {
data: {
entries: {
test: {
...tmpFile,
tempFile: true,
changed: true,
},
test: { ...tmpFile, tempFile: true, changed: true },
},
treeList: [tmpFile],
},
......@@ -141,18 +147,11 @@ describe('Multi-file store mutations', () => {
it('marks entry as replacing previous entry if the old one has been deleted', () => {
const tmpFile = file('test');
localState.entries.test = {
...tmpFile,
deleted: true,
};
localState.entries.test = { ...tmpFile, deleted: true };
mutations.CREATE_TMP_ENTRY(localState, {
data: {
entries: {
test: {
...tmpFile,
tempFile: true,
changed: true,
},
test: { ...tmpFile, tempFile: true, changed: true },
},
treeList: [tmpFile],
},
......@@ -167,21 +166,23 @@ describe('Multi-file store mutations', () => {
describe('UPDATE_TEMP_FLAG', () => {
beforeEach(() => {
localState.entries.test = {
...file(),
tempFile: true,
changed: true,
};
localState.entries.test = { ...file(), tempFile: true, changed: true };
});
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);
});
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);
});
......@@ -303,23 +304,28 @@ describe('Multi-file store mutations', () => {
const f = {
...file('test'),
prevPath: 'testing-123',
rawPath: `${gl.TEST_HOST}/testing-123`,
permalink: `${gl.TEST_HOST}/testing-123`,
commitsPath: `${gl.TEST_HOST}/testing-123`,
blamePath: `${gl.TEST_HOST}/testing-123`,
rawPath: `${TEST_HOST}/testing-123`,
permalink: `${TEST_HOST}/testing-123`,
commitsPath: `${TEST_HOST}/testing-123`,
blamePath: `${TEST_HOST}/testing-123`,
replaces: true,
};
localState.entries.test = 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(
jasmine.objectContaining({
rawPath: `${gl.TEST_HOST}/test`,
permalink: `${gl.TEST_HOST}/test`,
commitsPath: `${gl.TEST_HOST}/test`,
blamePath: `${gl.TEST_HOST}/test`,
expect.objectContaining({
rawPath: `${TEST_HOST}/test`,
permalink: `${TEST_HOST}/test`,
commitsPath: `${TEST_HOST}/test`,
blamePath: `${TEST_HOST}/test`,
replaces: false,
prevId: undefined,
prevPath: undefined,
......@@ -335,7 +341,10 @@ describe('Multi-file store mutations', () => {
it('sets entryModal', () => {
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({
type: 'test',
......@@ -348,7 +357,9 @@ describe('Multi-file store mutations', () => {
describe('RENAME_ENTRY', () => {
beforeEach(() => {
localState.trees = {
'gitlab-ce/master': { tree: [] },
'gitlab-ce/master': {
tree: [],
},
};
localState.currentProjectId = 'gitlab-ce';
localState.currentBranchId = 'master';
......@@ -365,7 +376,7 @@ describe('Multi-file store mutations', () => {
});
expect(localState.entries).toEqual({
newPath: jasmine.objectContaining({
newPath: expect.objectContaining({
path: 'newPath',
prevPath: 'oldPath',
}),
......@@ -386,7 +397,7 @@ describe('Multi-file store mutations', () => {
});
expect(localState.entries).toEqual({
newestPath: jasmine.objectContaining({
newestPath: expect.objectContaining({
path: 'newestPath',
prevPath: 'oldPath',
}),
......@@ -396,10 +407,7 @@ describe('Multi-file store mutations', () => {
it('correctly handles the same entry within a consecutively renamed folder', () => {
const oldPath = file('root-folder/oldPath', 'root-folder/oldPath', 'blob');
localState.entries = {
'root-folder': {
...file('root-folder', 'root-folder', 'tree'),
tree: [oldPath],
},
'root-folder': { ...file('root-folder', 'root-folder', 'tree'), tree: [oldPath] },
'root-folder/oldPath': oldPath,
};
Object.assign(localState.entries['root-folder/oldPath'], {
......@@ -422,10 +430,10 @@ describe('Multi-file store mutations', () => {
});
expect(localState.entries).toEqual({
'root-folder': jasmine.objectContaining({
'root-folder': expect.objectContaining({
path: 'root-folder',
}),
'simply-renamed/oldPath': jasmine.objectContaining({
'simply-renamed/oldPath': expect.objectContaining({
path: 'simply-renamed/oldPath',
prevPath: 'root-folder/oldPath',
}),
......@@ -450,8 +458,7 @@ describe('Multi-file store mutations', () => {
path: 'newPath',
name: 'newPath',
url: `project/-/newPath`,
key: jasmine.stringMatching('newPath'),
key: expect.stringMatching('newPath'),
prevId: 'oldPath',
prevName: 'oldPath',
prevPath: 'oldPath',
......@@ -473,13 +480,13 @@ describe('Multi-file store mutations', () => {
});
expect(localState.entries.newPath).not.toEqual(
jasmine.objectContaining({
prevId: jasmine.anything(),
prevName: jasmine.anything(),
prevPath: jasmine.anything(),
prevUrl: jasmine.anything(),
prevKey: jasmine.anything(),
prevParentPath: jasmine.anything(),
expect.objectContaining({
prevId: expect.anything(),
prevName: expect.anything(),
prevPath: expect.anything(),
prevUrl: expect.anything(),
prevKey: expect.anything(),
prevParentPath: expect.anything(),
}),
);
});
......@@ -487,10 +494,7 @@ describe('Multi-file store mutations', () => {
it('properly handles files with spaces in name', () => {
const path = 'my fancy path';
const newPath = 'new path';
const oldEntry = {
...file(path, path, 'blob'),
url: `project/-/${encodeURI(path)}`,
};
const oldEntry = { ...file(path, path, 'blob'), url: `project/-/${encodeURI(path)}` };
localState.entries[path] = oldEntry;
......@@ -507,8 +511,7 @@ describe('Multi-file store mutations', () => {
path: newPath,
name: newPath,
url: `project/-/new%20path`,
key: jasmine.stringMatching(newPath),
key: expect.stringMatching(newPath),
prevId: path,
prevName: path,
prevPath: path,
......@@ -540,7 +543,11 @@ describe('Multi-file store mutations', () => {
const alpha = file('alpha', 'alpha', 'blob');
const beta = file('beta', 'beta', '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];
......@@ -552,9 +559,13 @@ describe('Multi-file store mutations', () => {
});
expect(localState.trees['gitlab-ce/master'].tree).toEqual([
jasmine.objectContaining({ name: 'beta' }),
jasmine.objectContaining({ name: 'gamma' }),
jasmine.objectContaining({
expect.objectContaining({
name: 'beta',
}),
expect.objectContaining({
name: 'gamma',
}),
expect.objectContaining({
path: 'theta',
name: 'theta',
}),
......@@ -570,23 +581,26 @@ describe('Multi-file store mutations', () => {
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[0].path).toBe('newPath');
});
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);
});
it('updates existing changedFiles entry with the renamed one', () => {
const origFile = {
...file('oldPath', 'oldPath', 'blob'),
content: 'Foo',
};
const origFile = { ...file('oldPath', 'oldPath', 'blob'), content: 'Foo' };
Object.assign(localState, {
changedFiles: [origFile],
......@@ -595,10 +609,13 @@ describe('Multi-file store mutations', () => {
oldPath: origFile,
});
mutations.RENAME_ENTRY(localState, { path: 'oldPath', name: 'newPath' });
mutations.RENAME_ENTRY(localState, {
path: 'oldPath',
name: 'newPath',
});
expect(localState.changedFiles).toEqual([
jasmine.objectContaining({
expect.objectContaining({
path: 'newPath',
content: 'Foo',
}),
......@@ -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', () => {
......@@ -638,12 +661,16 @@ describe('Multi-file store mutations', () => {
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', () => {
expect(localState.entries).toEqual({
'lorem/orig': jasmine.objectContaining({
'lorem/orig': expect.objectContaining({
id: 'lorem/orig',
path: 'lorem/orig',
name: 'orig',
......@@ -672,7 +699,10 @@ describe('Multi-file store mutations', () => {
it('sets properly constucted key while preserving the original one', () => {
const key = 'oldPath.txt-blob-oldPath.txt';
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'].prevKey).toBe(key);
......@@ -680,14 +710,20 @@ describe('Multi-file store mutations', () => {
it('correctly updates key for an entry without an extension', () => {
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');
});
it('correctly updates key when new name does not have an extension', () => {
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');
});
......
......@@ -104,21 +104,9 @@ describe('Multi-file store utils', () => {
base64: true,
lastCommitSha: '123456789',
},
{
...file('deletedFile'),
path: 'deletedFile',
deleted: true,
},
{
...file('renamedFile'),
path: 'renamedFile',
prevPath: 'prevPath',
},
{
...file('replacingFile'),
path: 'replacingFile',
replaces: true,
},
{ ...file('deletedFile'), path: 'deletedFile', deleted: true },
{ ...file('renamedFile'), path: 'renamedFile', prevPath: 'prevPath' },
{ ...file('replacingFile'), path: 'replacingFile', replaces: true },
],
currentBranchId: 'master',
};
......@@ -237,15 +225,27 @@ describe('Multi-file store utils', () => {
describe('commitActionForFile', () => {
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', () => {
expect(utils.commitActionForFile({ tempFile: true })).toBe(commitActionTypes.create);
expect(
utils.commitActionForFile({
tempFile: true,
}),
).toBe(commitActionTypes.create);
});
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', () => {
......@@ -341,12 +341,7 @@ describe('Multi-file store utils', () => {
fromTree[0].tree.push({
...file('alpha'),
path: 'foo/alpha',
tree: [
{
...file('beta.md'),
path: 'foo/alpha/beta.md',
},
],
tree: [{ ...file('beta.md'), path: 'foo/alpha/beta.md' }],
});
toTree.push({
......@@ -355,12 +350,7 @@ describe('Multi-file store utils', () => {
{
...file('alpha'),
path: 'foo/alpha',
tree: [
{
...file('gamma.md'),
path: 'foo/alpha/gamma.md',
},
],
tree: [{ ...file('gamma.md'), path: 'foo/alpha/gamma.md' }],
},
],
});
......@@ -381,12 +371,7 @@ describe('Multi-file store utils', () => {
fromTree[0].tree.push({
...file('alpha'),
path: 'foo/alpha',
tree: [
{
...file('beta.md'),
path: 'foo/alpha/beta.md',
},
],
tree: [{ ...file('beta.md'), path: 'foo/alpha/beta.md' }],
});
toTree.push({
......@@ -395,12 +380,7 @@ describe('Multi-file store utils', () => {
{
...file('alpha'),
path: 'foo/alpha',
tree: [
{
...file('gamma.md'),
path: 'foo/alpha/gamma.md',
},
],
tree: [{ ...file('gamma.md'), path: 'foo/alpha/gamma.md' }],
},
],
});
......@@ -431,10 +411,7 @@ describe('Multi-file store utils', () => {
});
it('swaps existing entry with a new one', () => {
const file1 = {
...file('old'),
key: 'foo',
};
const file1 = { ...file('old'), key: 'foo' };
const file2 = file('new');
const arr = [file1];
......@@ -511,8 +488,12 @@ describe('Multi-file store utils', () => {
expect(branchInfo.tree.length).toBe(2);
expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'newPath' }),
jasmine.objectContaining({ name: 'oldPath' }),
expect.objectContaining({
name: 'newPath',
}),
expect.objectContaining({
name: 'oldPath',
}),
]);
});
......@@ -521,7 +502,9 @@ describe('Multi-file store utils', () => {
expect(localState.entries.parentPath.tree.length).toBe(1);
expect(localState.entries.parentPath.tree).toEqual([
jasmine.objectContaining({ name: 'newPath' }),
expect.objectContaining({
name: 'newPath',
}),
]);
localState.entries.parentPath.tree = [localState.entries.oldPath];
......@@ -530,8 +513,12 @@ describe('Multi-file store utils', () => {
expect(localState.entries.parentPath.tree.length).toBe(2);
expect(localState.entries.parentPath.tree).toEqual([
jasmine.objectContaining({ name: 'newPath' }),
jasmine.objectContaining({ name: 'oldPath' }),
expect.objectContaining({
name: 'newPath',
}),
expect.objectContaining({
name: 'oldPath',
}),
]);
});
});
......@@ -542,11 +529,19 @@ describe('Multi-file store utils', () => {
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');
expect(branchInfo.tree).toEqual([jasmine.objectContaining({ name: 'oldPath' })]);
expect(branchInfo.tree).toEqual([
expect.objectContaining({
name: 'oldPath',
}),
]);
});
it('sorts tree after swapping the entries', () => {
......@@ -554,32 +549,55 @@ describe('Multi-file store utils', () => {
const beta = file('beta', 'beta', 'blob');
const gamma = file('gamma', 'gamma', 'blob');
const theta = file('theta', 'theta', 'blob');
localState.entries = { alpha, beta, gamma, theta };
localState.entries = {
alpha,
beta,
gamma,
theta,
};
branchInfo.tree = [alpha, beta, gamma];
utils.swapInParentTreeWithSorting(localState, alpha.key, 'theta');
expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'beta' }),
jasmine.objectContaining({ name: 'gamma' }),
jasmine.objectContaining({ name: 'theta' }),
expect.objectContaining({
name: 'beta',
}),
expect.objectContaining({
name: 'gamma',
}),
expect.objectContaining({
name: 'theta',
}),
]);
utils.swapInParentTreeWithSorting(localState, gamma.key, 'alpha');
expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'alpha' }),
jasmine.objectContaining({ name: 'beta' }),
jasmine.objectContaining({ name: 'theta' }),
expect.objectContaining({
name: 'alpha',
}),
expect.objectContaining({
name: 'beta',
}),
expect.objectContaining({
name: 'theta',
}),
]);
utils.swapInParentTreeWithSorting(localState, beta.key, 'gamma');
expect(branchInfo.tree).toEqual([
jasmine.objectContaining({ name: 'alpha' }),
jasmine.objectContaining({ name: 'gamma' }),
jasmine.objectContaining({ name: 'theta' }),
expect.objectContaining({
name: 'alpha',
}),
expect.objectContaining({
name: 'gamma',
}),
expect.objectContaining({
name: 'theta',
}),
]);
});
});
......@@ -587,11 +605,26 @@ describe('Multi-file store utils', () => {
describe('cleanTrailingSlash', () => {
[
{ input: '', output: '' },
{ input: 'abc', output: 'abc' },
{ input: 'abc/', output: 'abc' },
{ input: 'abc/def', output: 'abc/def' },
{ input: 'abc/def/', output: 'abc/def' },
{
input: '',
output: '',
},
{
input: 'abc',
output: 'abc',
},
{
input: 'abc/',
output: 'abc',
},
{
input: 'abc/def',
output: 'abc/def',
},
{
input: 'abc/def/',
output: 'abc/def',
},
].forEach(({ input, output }) => {
it(`cleans trailing slash from string "${input}"`, () => {
expect(utils.cleanTrailingSlash(input)).toEqual(output);
......@@ -601,13 +634,34 @@ describe('Multi-file store utils', () => {
describe('pathsAreEqual', () => {
[
{ args: ['abc', 'abc'], output: true },
{ args: ['abc', 'def'], output: false },
{ args: ['abc/', 'abc'], output: true },
{ args: ['abc/abc', 'abc'], output: false },
{ args: ['/', ''], output: true },
{ args: ['', '/'], output: true },
{ args: [false, '/'], output: true },
{
args: ['abc', 'abc'],
output: true,
},
{
args: ['abc', 'def'],
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 }) => {
it(`cleans and tests equality (${JSON.stringify(args)})`, () => {
expect(utils.pathsAreEqual(...args)).toEqual(output);
......@@ -618,10 +672,22 @@ describe('Multi-file store utils', () => {
describe('addFinalNewlineIfNeeded', () => {
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\n\n', output: 'some text\n\n' },
{ input: 'some\n text', output: 'some\n text\n' },
{
input: 'some text',
output: 'some 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 }) => {
expect(utils.addFinalNewlineIfNeeded(input)).toEqual(output);
});
......
......@@ -26,15 +26,18 @@ describe('WebIDE utils', () => {
entry.deleted = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.deleted);
});
it('renders "addition" icon for temp entries', () => {
entry.tempFile = true;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.addition);
});
it('renders "modified" icon for newly-renamed entries', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = false;
expect(getCommitIconMap(entry)).toEqual(commitItemIconMap.modified);
});
it('renders "modified" icon even for temp entries if they are newly-renamed', () => {
entry.prevPath = 'foo/bar';
entry.tempFile = true;
......
import * as pathUtils from 'path';
import { decorateData } from '~/ide/stores/utils';
import state from '~/ide/stores/state';
import commitState from '~/ide/stores/modules/commit/state';
import mergeRequestsState from '~/ide/stores/modules/merge_requests/state';
import pipelinesState from '~/ide/stores/modules/pipelines/state';
import branchesState from '~/ide/stores/modules/branches/state';
import fileTemplatesState from '~/ide/stores/modules/file_templates/state';
import paneState from '~/ide/stores/modules/pane/state';
export const resetStore = store => {
const newState = {
...state(),
commit: commitState(),
mergeRequests: mergeRequestsState(),
pipelines: pipelinesState(),
branches: branchesState(),
fileTemplates: fileTemplatesState(),
rightPane: paneState(),
};
store.replaceState(newState);
};
export const file = (name = 'name', id = name, type = '', parent = null) =>
decorateData({
id,
type,
icon: 'icon',
url: 'url',
name,
path: parent ? `${parent.path}/${name}` : name,
parentPath: parent ? parent.path : '',
lastCommit: {},
});
export const createEntriesFromPaths = paths =>
paths
.map(path => ({
name: pathUtils.basename(path),
dir: pathUtils.dirname(path),
ext: pathUtils.extname(path),
}))
.reduce((entries, path, idx) => {
const { name } = path;
const parent = path.dir ? entries[path.dir] : null;
const type = path.ext ? 'blob' : 'tree';
const entry = file(name, (idx + 1).toString(), type, parent);
return {
[entry.path]: entry,
...entries,
};
}, {});
export * from '../../frontend/ide/helpers';
import testAction from 'spec/helpers/vuex_action_helper';
import * as actions from '~/ide/stores/modules/pane/actions';
import * as types from '~/ide/stores/modules/pane/mutation_types';
describe('IDE pane module actions', () => {
const TEST_VIEW = { name: 'test' };
const TEST_VIEW_KEEP_ALIVE = { name: 'test-keep-alive', keepAlive: true };
describe('toggleOpen', () => {
it('dispatches open if closed', done => {
testAction(
actions.toggleOpen,
TEST_VIEW,
{ isOpen: false },
[],
[{ type: 'open', payload: TEST_VIEW }],
done,
);
});
it('dispatches close if opened', done => {
testAction(actions.toggleOpen, TEST_VIEW, { isOpen: true }, [], [{ type: 'close' }], done);
});
});
describe('open', () => {
it('commits SET_OPEN', done => {
testAction(actions.open, null, {}, [{ type: types.SET_OPEN, payload: true }], [], done);
});
it('commits SET_CURRENT_VIEW if view is given', done => {
testAction(
actions.open,
TEST_VIEW,
{},
[
{ type: types.SET_OPEN, payload: true },
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW.name },
],
[],
done,
);
});
it('commits KEEP_ALIVE_VIEW if keepAlive is true', done => {
testAction(
actions.open,
TEST_VIEW_KEEP_ALIVE,
{},
[
{ type: types.SET_OPEN, payload: true },
{ type: types.SET_CURRENT_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
{ type: types.KEEP_ALIVE_VIEW, payload: TEST_VIEW_KEEP_ALIVE.name },
],
[],
done,
);
});
});
describe('close', () => {
it('commits SET_OPEN', done => {
testAction(actions.close, null, {}, [{ type: types.SET_OPEN, payload: false }], [], done);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment