Commit 2c96b5e7 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'himkp-jest-ide' into 'master'

Migrate all app/javascripts/ide specs to Jest

Closes #194238

See merge request gitlab-org/gitlab!32408
parents 6e59f81b 3e6878a6
...@@ -297,6 +297,3 @@ export * from './actions/tree'; ...@@ -297,6 +297,3 @@ export * from './actions/tree';
export * from './actions/file'; export * from './actions/file';
export * from './actions/project'; export * from './actions/project';
export * from './actions/merge_request'; export * from './actions/merge_request';
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -161,6 +161,3 @@ export const canCreateMergeRequests = (state, getters) => ...@@ -161,6 +161,3 @@ export const canCreateMergeRequests = (state, getters) =>
export const canPushCode = (state, getters) => export const canPushCode = (state, getters) =>
Boolean(getters.findProjectPermissions(state.currentProjectId)[PERMISSION_PUSH_CODE]); Boolean(getters.findProjectPermissions(state.currentProjectId)[PERMISSION_PUSH_CODE]);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -8,5 +8,4 @@ export const pingUsage = ({ rootGetters }) => { ...@@ -8,5 +8,4 @@ export const pingUsage = ({ rootGetters }) => {
return axios.post(url); return axios.post(url);
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests export default pingUsage;
export default () => {};
...@@ -234,6 +234,3 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo ...@@ -234,6 +234,3 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
window.dispatchEvent(new Event('resize')); window.dispatchEvent(new Event('resize'));
}); });
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -59,6 +59,3 @@ export const shouldDisableNewMrOption = (state, getters, rootState, rootGetters) ...@@ -59,6 +59,3 @@ export const shouldDisableNewMrOption = (state, getters, rootState, rootGetters)
export const shouldCreateMR = (state, getters) => export const shouldCreateMR = (state, getters) =>
state.shouldCreateMR && !getters.shouldDisableNewMrOption; state.shouldCreateMR && !getters.shouldDisableNewMrOption;
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -117,6 +117,3 @@ export const undoFileTemplate = ({ dispatch, commit, rootGetters }) => { ...@@ -117,6 +117,3 @@ export const undoFileTemplate = ({ dispatch, commit, rootGetters }) => {
dispatch('discardFileChanges', file.path, { root: true }); dispatch('discardFileChanges', file.path, { root: true });
} }
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
...@@ -25,6 +25,3 @@ export const open = ({ state, commit }, view) => { ...@@ -25,6 +25,3 @@ export const open = ({ state, commit }, view) => {
export const close = ({ commit }) => { export const close = ({ commit }) => {
commit(types.SET_OPEN, false); commit(types.SET_OPEN, false);
}; };
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};
// Similar to `lodash/debounce`, `lodash/throttle` also causes flaky specs.
// See `./debounce.js` for more details.
export default fn => fn;
Element.prototype.scrollTo = jest.fn().mockImplementation(function scrollTo(x, y) {
this.scrollLeft = x;
this.scrollTop = y;
this.dispatchEvent(new Event('scroll'));
});
import './element_scroll_into_view'; import './element_scroll_into_view';
import './element_scroll_by'; import './element_scroll_by';
import './element_scroll_to';
import './form_element'; import './form_element';
import './get_client_rects'; import './get_client_rects';
import './inner_text'; import './inner_text';
......
import Vue from 'vue'; import Vue from 'vue';
import createComponent from 'spec/helpers/vue_mount_component_helper'; import createComponent from 'helpers/vue_mount_component_helper';
import CommitMessageField from '~/ide/components/commit_sidebar/message_field.vue'; import CommitMessageField from '~/ide/components/commit_sidebar/message_field.vue';
describe('IDE commit message field', () => { describe('IDE commit message field', () => {
...@@ -54,7 +54,7 @@ describe('IDE commit message field', () => { ...@@ -54,7 +54,7 @@ describe('IDE commit message field', () => {
}); });
it('emits input event on input', () => { it('emits input event on input', () => {
spyOn(vm, '$emit'); jest.spyOn(vm, '$emit').mockImplementation();
const textarea = vm.$el.querySelector('textarea'); const textarea = vm.$el.querySelector('textarea');
textarea.value = 'testing'; textarea.value = 'testing';
...@@ -160,7 +160,7 @@ describe('IDE commit message field', () => { ...@@ -160,7 +160,7 @@ describe('IDE commit message field', () => {
.then(() => { .then(() => {
expect(vm.scrollTop).toBe(50); expect(vm.scrollTop).toBe(50);
expect(vm.$el.querySelector('.highlights').style.transform).toBe( expect(vm.$el.querySelector('.highlights').style.transform).toBe(
'translate3d(0px, -50px, 0px)', 'translate3d(0, -50px, 0)',
); );
}) })
.then(done) .then(done)
......
...@@ -3,44 +3,45 @@ import JobDetail from '~/ide/components/jobs/detail.vue'; ...@@ -3,44 +3,45 @@ import JobDetail from '~/ide/components/jobs/detail.vue';
import { createStore } from '~/ide/stores'; import { createStore } from '~/ide/stores';
import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper'; import { createComponentWithStore } from '../../../helpers/vue_mount_component_helper';
import { jobs } from '../../mock_data'; import { jobs } from '../../mock_data';
import { TEST_HOST } from 'helpers/test_constants';
describe('IDE jobs detail view', () => { describe('IDE jobs detail view', () => {
const Component = Vue.extend(JobDetail);
let vm; let vm;
beforeEach(() => { const createComponent = () => {
const store = createStore(); const store = createStore();
store.state.pipelines.detailJob = { store.state.pipelines.detailJob = {
...jobs[0], ...jobs[0],
isLoading: true, isLoading: true,
output: 'testing', output: 'testing',
rawPath: `${gl.TEST_HOST}/raw`, rawPath: `${TEST_HOST}/raw`,
}; };
vm = createComponentWithStore(Component, store); return createComponentWithStore(Vue.extend(JobDetail), store);
};
spyOn(vm, 'fetchJobTrace').and.returnValue(Promise.resolve());
vm = vm.$mount(); beforeEach(() => {
vm = createComponent();
spyOn(vm.$refs.buildTrace, 'scrollTo'); jest.spyOn(vm, 'fetchJobTrace').mockResolvedValue();
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
}); });
it('calls fetchJobTrace on mount', () => { describe('mounted', () => {
beforeEach(() => {
vm = vm.$mount();
});
it('calls fetchJobTrace', () => {
expect(vm.fetchJobTrace).toHaveBeenCalled(); expect(vm.fetchJobTrace).toHaveBeenCalled();
}); });
it('scrolls to bottom on mount', done => { it('scrolls to bottom', () => {
setTimeout(() => {
expect(vm.$refs.buildTrace.scrollTo).toHaveBeenCalled(); expect(vm.$refs.buildTrace.scrollTo).toHaveBeenCalled();
done();
});
}); });
it('renders job output', () => { it('renders job output', () => {
...@@ -78,7 +79,7 @@ describe('IDE jobs detail view', () => { ...@@ -78,7 +79,7 @@ describe('IDE jobs detail view', () => {
}); });
it('resets detailJob when clicking header button', () => { it('resets detailJob when clicking header button', () => {
spyOn(vm, 'setDetailJob'); jest.spyOn(vm, 'setDetailJob').mockImplementation();
vm.$el.querySelector('.btn').click(); vm.$el.querySelector('.btn').click();
...@@ -87,42 +88,48 @@ describe('IDE jobs detail view', () => { ...@@ -87,42 +88,48 @@ describe('IDE jobs detail view', () => {
it('renders raw path link', () => { it('renders raw path link', () => {
expect(vm.$el.querySelector('.controllers-buttons').getAttribute('href')).toBe( expect(vm.$el.querySelector('.controllers-buttons').getAttribute('href')).toBe(
`${gl.TEST_HOST}/raw`, `${TEST_HOST}/raw`,
); );
}); });
});
describe('scroll buttons', () => { describe('scroll buttons', () => {
it('triggers scrollDown when clicking down button', done => { beforeEach(() => {
spyOn(vm, 'scrollDown'); vm = createComponent();
jest.spyOn(vm, 'fetchJobTrace').mockResolvedValue();
vm.$el.querySelectorAll('.btn-scroll')[1].click();
vm.$nextTick(() => {
expect(vm.scrollDown).toHaveBeenCalled();
done();
}); });
afterEach(() => {
vm.$destroy();
}); });
it('triggers scrollUp when clicking up button', done => { it.each`
spyOn(vm, 'scrollUp'); fnName | btnName | scrollPos
${'scrollDown'} | ${'down'} | ${0}
${'scrollUp'} | ${'up'} | ${1}
`('triggers $fnName when clicking $btnName button', ({ fnName, scrollPos }) => {
jest.spyOn(vm, fnName).mockImplementation();
vm.scrollPos = 1; vm = vm.$mount();
vm.scrollPos = scrollPos;
vm.$nextTick() return vm.$nextTick().then(() => {
.then(() => vm.$el.querySelector('.btn-scroll').click()) vm.$el.querySelector('.btn-scroll:not([disabled])').click();
.then(() => vm.$nextTick()) expect(vm[fnName]).toHaveBeenCalled();
.then(() => { });
expect(vm.scrollUp).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
}); });
}); });
describe('scrollDown', () => { describe('scrollDown', () => {
beforeEach(() => {
vm = vm.$mount();
jest.spyOn(vm.$refs.buildTrace, 'scrollTo').mockImplementation();
});
it('scrolls build trace to bottom', () => { it('scrolls build trace to bottom', () => {
spyOnProperty(vm.$refs.buildTrace, 'scrollHeight').and.returnValue(1000); jest.spyOn(vm.$refs.buildTrace, 'scrollHeight', 'get').mockReturnValue(1000);
vm.scrollDown(); vm.scrollDown();
...@@ -131,6 +138,12 @@ describe('IDE jobs detail view', () => { ...@@ -131,6 +138,12 @@ describe('IDE jobs detail view', () => {
}); });
describe('scrollUp', () => { describe('scrollUp', () => {
beforeEach(() => {
vm = vm.$mount();
jest.spyOn(vm.$refs.buildTrace, 'scrollTo').mockImplementation();
});
it('scrolls build trace to top', () => { it('scrolls build trace to top', () => {
vm.scrollUp(); vm.scrollUp();
...@@ -140,45 +153,35 @@ describe('IDE jobs detail view', () => { ...@@ -140,45 +153,35 @@ describe('IDE jobs detail view', () => {
describe('scrollBuildLog', () => { describe('scrollBuildLog', () => {
beforeEach(() => { beforeEach(() => {
spyOnProperty(vm.$refs.buildTrace, 'offsetHeight').and.returnValue(100); vm = vm.$mount();
spyOnProperty(vm.$refs.buildTrace, 'scrollHeight').and.returnValue(200); jest.spyOn(vm.$refs.buildTrace, 'scrollTo').mockImplementation();
jest.spyOn(vm.$refs.buildTrace, 'offsetHeight', 'get').mockReturnValue(100);
jest.spyOn(vm.$refs.buildTrace, 'scrollHeight', 'get').mockReturnValue(200);
}); });
it('sets scrollPos to bottom when at the bottom', done => { it('sets scrollPos to bottom when at the bottom', () => {
spyOnProperty(vm.$refs.buildTrace, 'scrollTop').and.returnValue(100); jest.spyOn(vm.$refs.buildTrace, 'scrollTop', 'get').mockReturnValue(100);
vm.scrollBuildLog(); vm.scrollBuildLog();
setTimeout(() => {
expect(vm.scrollPos).toBe(1); expect(vm.scrollPos).toBe(1);
done();
});
}); });
it('sets scrollPos to top when at the top', done => { it('sets scrollPos to top when at the top', () => {
spyOnProperty(vm.$refs.buildTrace, 'scrollTop').and.returnValue(0); jest.spyOn(vm.$refs.buildTrace, 'scrollTop', 'get').mockReturnValue(0);
vm.scrollPos = 1; vm.scrollPos = 1;
vm.scrollBuildLog(); vm.scrollBuildLog();
setTimeout(() => {
expect(vm.scrollPos).toBe(0); expect(vm.scrollPos).toBe(0);
done();
});
}); });
it('resets scrollPos when not at top or bottom', done => { it('resets scrollPos when not at top or bottom', () => {
spyOnProperty(vm.$refs.buildTrace, 'scrollTop').and.returnValue(10); jest.spyOn(vm.$refs.buildTrace, 'scrollTop', 'get').mockReturnValue(10);
vm.scrollBuildLog(); vm.scrollBuildLog();
setTimeout(() => {
expect(vm.scrollPos).toBe(''); expect(vm.scrollPos).toBe('');
done();
});
}); });
}); });
}); });
...@@ -6,7 +6,7 @@ import List from '~/ide/components/pipelines/list.vue'; ...@@ -6,7 +6,7 @@ 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 { pipelines } from '../../../../javascripts/ide/mock_data'; import { pipelines } from 'jest/ide/mock_data';
import IDEServices from '~/ide/services'; import IDEServices from '~/ide/services';
const localVue = createLocalVue(); const localVue = createLocalVue();
......
...@@ -7,13 +7,13 @@ import repoEditor from '~/ide/components/repo_editor.vue'; ...@@ -7,13 +7,13 @@ import repoEditor from '~/ide/components/repo_editor.vue';
import Editor from '~/ide/lib/editor'; import Editor from '~/ide/lib/editor';
import { leftSidebarViews, FILE_VIEW_MODE_EDITOR, FILE_VIEW_MODE_PREVIEW } from '~/ide/constants'; import { leftSidebarViews, FILE_VIEW_MODE_EDITOR, FILE_VIEW_MODE_PREVIEW } from '~/ide/constants';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import setTimeoutPromise from '../../helpers/set_timeout_promise_helper'; import waitForPromises from 'helpers/wait_for_promises';
import { file, resetStore } from '../helpers'; import { file, resetStore } from '../helpers';
describe('RepoEditor', () => { describe('RepoEditor', () => {
let vm; let vm;
beforeEach(done => { beforeEach(() => {
const f = { const f = {
...file(), ...file(),
viewMode: FILE_VIEW_MODE_EDITOR, viewMode: FILE_VIEW_MODE_EDITOR,
...@@ -45,12 +45,12 @@ describe('RepoEditor', () => { ...@@ -45,12 +45,12 @@ describe('RepoEditor', () => {
Vue.set(vm.$store.state.entries, f.path, f); Vue.set(vm.$store.state.entries, f.path, f);
spyOn(vm, 'getFileData').and.returnValue(Promise.resolve()); jest.spyOn(vm, 'getFileData').mockResolvedValue();
spyOn(vm, 'getRawFileData').and.returnValue(Promise.resolve()); jest.spyOn(vm, 'getRawFileData').mockResolvedValue();
vm.$mount(); vm.$mount();
Vue.nextTick(() => setTimeout(done)); return vm.$nextTick();
}); });
afterEach(() => { afterEach(() => {
...@@ -161,7 +161,7 @@ describe('RepoEditor', () => { ...@@ -161,7 +161,7 @@ describe('RepoEditor', () => {
.then(() => { .then(() => {
vm.$el.querySelectorAll('.ide-mode-tabs .nav-links a')[1].click(); vm.$el.querySelectorAll('.ide-mode-tabs .nav-links a')[1].click();
}) })
.then(setTimeoutPromise) .then(waitForPromises)
.then(() => { .then(() => {
expect(vm.$el.querySelector('.preview-container').innerHTML).toContain( expect(vm.$el.querySelector('.preview-container').innerHTML).toContain(
'<p>testing 123</p>', '<p>testing 123</p>',
...@@ -186,7 +186,7 @@ describe('RepoEditor', () => { ...@@ -186,7 +186,7 @@ describe('RepoEditor', () => {
describe('createEditorInstance', () => { describe('createEditorInstance', () => {
it('calls createInstance when viewer is editor', done => { it('calls createInstance when viewer is editor', done => {
spyOn(vm.editor, 'createInstance'); jest.spyOn(vm.editor, 'createInstance').mockImplementation();
vm.createEditorInstance(); vm.createEditorInstance();
...@@ -200,7 +200,7 @@ describe('RepoEditor', () => { ...@@ -200,7 +200,7 @@ describe('RepoEditor', () => {
it('calls createDiffInstance when viewer is diff', done => { it('calls createDiffInstance when viewer is diff', done => {
vm.$store.state.viewer = 'diff'; vm.$store.state.viewer = 'diff';
spyOn(vm.editor, 'createDiffInstance'); jest.spyOn(vm.editor, 'createDiffInstance').mockImplementation();
vm.createEditorInstance(); vm.createEditorInstance();
...@@ -214,7 +214,7 @@ describe('RepoEditor', () => { ...@@ -214,7 +214,7 @@ describe('RepoEditor', () => {
it('calls createDiffInstance when viewer is a merge request diff', done => { it('calls createDiffInstance when viewer is a merge request diff', done => {
vm.$store.state.viewer = 'mrdiff'; vm.$store.state.viewer = 'mrdiff';
spyOn(vm.editor, 'createDiffInstance'); jest.spyOn(vm.editor, 'createDiffInstance').mockImplementation();
vm.createEditorInstance(); vm.createEditorInstance();
...@@ -228,7 +228,7 @@ describe('RepoEditor', () => { ...@@ -228,7 +228,7 @@ describe('RepoEditor', () => {
describe('setupEditor', () => { describe('setupEditor', () => {
it('creates new model', () => { it('creates new model', () => {
spyOn(vm.editor, 'createModel').and.callThrough(); jest.spyOn(vm.editor, 'createModel');
Editor.editorInstance.modelManager.dispose(); Editor.editorInstance.modelManager.dispose();
...@@ -239,7 +239,7 @@ describe('RepoEditor', () => { ...@@ -239,7 +239,7 @@ describe('RepoEditor', () => {
}); });
it('attaches model to editor', () => { it('attaches model to editor', () => {
spyOn(vm.editor, 'attachModel').and.callThrough(); jest.spyOn(vm.editor, 'attachModel');
Editor.editorInstance.modelManager.dispose(); Editor.editorInstance.modelManager.dispose();
...@@ -251,7 +251,7 @@ describe('RepoEditor', () => { ...@@ -251,7 +251,7 @@ describe('RepoEditor', () => {
it('attaches model to merge request editor', () => { it('attaches model to merge request editor', () => {
vm.$store.state.viewer = 'mrdiff'; vm.$store.state.viewer = 'mrdiff';
vm.file.mrChange = true; vm.file.mrChange = true;
spyOn(vm.editor, 'attachMergeRequestModel'); jest.spyOn(vm.editor, 'attachMergeRequestModel').mockImplementation();
Editor.editorInstance.modelManager.dispose(); Editor.editorInstance.modelManager.dispose();
...@@ -263,7 +263,7 @@ describe('RepoEditor', () => { ...@@ -263,7 +263,7 @@ describe('RepoEditor', () => {
it('does not attach model to merge request editor when not a MR change', () => { it('does not attach model to merge request editor when not a MR change', () => {
vm.$store.state.viewer = 'mrdiff'; vm.$store.state.viewer = 'mrdiff';
vm.file.mrChange = false; vm.file.mrChange = false;
spyOn(vm.editor, 'attachMergeRequestModel'); jest.spyOn(vm.editor, 'attachMergeRequestModel').mockImplementation();
Editor.editorInstance.modelManager.dispose(); Editor.editorInstance.modelManager.dispose();
...@@ -273,7 +273,7 @@ describe('RepoEditor', () => { ...@@ -273,7 +273,7 @@ describe('RepoEditor', () => {
}); });
it('adds callback methods', () => { it('adds callback methods', () => {
spyOn(vm.editor, 'onPositionChange').and.callThrough(); jest.spyOn(vm.editor, 'onPositionChange');
Editor.editorInstance.modelManager.dispose(); Editor.editorInstance.modelManager.dispose();
...@@ -286,7 +286,7 @@ describe('RepoEditor', () => { ...@@ -286,7 +286,7 @@ describe('RepoEditor', () => {
it('updates state when model content changed', done => { it('updates state when model content changed', done => {
vm.model.setValue('testing 123\n'); vm.model.setValue('testing 123\n');
setTimeout(() => { setImmediate(() => {
expect(vm.file.content).toBe('testing 123\n'); expect(vm.file.content).toBe('testing 123\n');
done(); done();
...@@ -294,7 +294,7 @@ describe('RepoEditor', () => { ...@@ -294,7 +294,7 @@ describe('RepoEditor', () => {
}); });
it('sets head model as staged file', () => { it('sets head model as staged file', () => {
spyOn(vm.editor, 'createModel').and.callThrough(); jest.spyOn(vm.editor, 'createModel');
Editor.editorInstance.modelManager.dispose(); Editor.editorInstance.modelManager.dispose();
...@@ -310,8 +310,8 @@ describe('RepoEditor', () => { ...@@ -310,8 +310,8 @@ describe('RepoEditor', () => {
describe('editor updateDimensions', () => { describe('editor updateDimensions', () => {
beforeEach(() => { beforeEach(() => {
spyOn(vm.editor, 'updateDimensions').and.callThrough(); jest.spyOn(vm.editor, 'updateDimensions');
spyOn(vm.editor, 'updateDiffView'); jest.spyOn(vm.editor, 'updateDiffView').mockImplementation();
}); });
it('calls updateDimensions when panelResizing is false', done => { it('calls updateDimensions when panelResizing is false', done => {
...@@ -381,7 +381,7 @@ describe('RepoEditor', () => { ...@@ -381,7 +381,7 @@ describe('RepoEditor', () => {
describe('when files view mode is preview', () => { describe('when files view mode is preview', () => {
beforeEach(done => { beforeEach(done => {
spyOn(vm.editor, 'updateDimensions'); jest.spyOn(vm.editor, 'updateDimensions').mockImplementation();
vm.file.viewMode = FILE_VIEW_MODE_PREVIEW; vm.file.viewMode = FILE_VIEW_MODE_PREVIEW;
vm.$nextTick(done); vm.$nextTick(done);
}); });
...@@ -392,28 +392,21 @@ describe('RepoEditor', () => { ...@@ -392,28 +392,21 @@ describe('RepoEditor', () => {
}); });
describe('when file view mode changes to editor', () => { describe('when file view mode changes to editor', () => {
beforeEach(done => { it('should update dimensions', () => {
vm.file.viewMode = FILE_VIEW_MODE_EDITOR; vm.file.viewMode = FILE_VIEW_MODE_EDITOR;
// one tick to trigger watch return vm.$nextTick().then(() => {
vm.$nextTick()
// another tick needed until we can update dimensions
.then(() => vm.$nextTick())
.then(done)
.catch(done.fail);
});
it('should update dimensions', () => {
expect(vm.editor.updateDimensions).toHaveBeenCalled(); expect(vm.editor.updateDimensions).toHaveBeenCalled();
}); });
}); });
}); });
});
describe('initEditor', () => { describe('initEditor', () => {
beforeEach(() => { beforeEach(() => {
vm.file.tempFile = false; vm.file.tempFile = false;
spyOn(vm.editor, 'createInstance'); jest.spyOn(vm.editor, 'createInstance').mockImplementation();
spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true); jest.spyOn(vm, 'shouldHideEditor', 'get').mockReturnValue(true);
}); });
it('does not fetch file information for temp entries', done => { it('does not fetch file information for temp entries', done => {
...@@ -459,12 +452,12 @@ describe('RepoEditor', () => { ...@@ -459,12 +452,12 @@ describe('RepoEditor', () => {
describe('updates on file changes', () => { describe('updates on file changes', () => {
beforeEach(() => { beforeEach(() => {
spyOn(vm, 'initEditor'); jest.spyOn(vm, 'initEditor').mockImplementation();
}); });
it('calls removePendingTab when old file is pending', done => { it('calls removePendingTab when old file is pending', done => {
spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true); jest.spyOn(vm, 'shouldHideEditor', 'get').mockReturnValue(true);
spyOn(vm, 'removePendingTab'); jest.spyOn(vm, 'removePendingTab').mockImplementation();
vm.file.pending = true; vm.file.pending = true;
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import store from '~/ide/stores'; import store from '~/ide/stores';
import actions, { import createFlash from '~/flash';
import {
getMergeRequestData, getMergeRequestData,
getMergeRequestChanges, getMergeRequestChanges,
getMergeRequestVersions, getMergeRequestVersions,
...@@ -14,6 +15,8 @@ import { resetStore } from '../../helpers'; ...@@ -14,6 +15,8 @@ import { resetStore } from '../../helpers';
const TEST_PROJECT = 'abcproject'; const TEST_PROJECT = 'abcproject';
const TEST_PROJECT_ID = 17; const TEST_PROJECT_ID = 17;
jest.mock('~/flash');
describe('IDE store merge request actions', () => { describe('IDE store merge request actions', () => {
let mock; let mock;
...@@ -41,7 +44,7 @@ describe('IDE store merge request actions', () => { ...@@ -41,7 +44,7 @@ describe('IDE store merge request actions', () => {
describe('base case', () => { describe('base case', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectMergeRequests').and.callThrough(); jest.spyOn(service, 'getProjectMergeRequests');
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, mockData); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, mockData);
}); });
...@@ -66,7 +69,7 @@ describe('IDE store merge request actions', () => { ...@@ -66,7 +69,7 @@ describe('IDE store merge request actions', () => {
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
.then(() => { .then(() => {
expect(store.state.projects.abcproject.mergeRequests).toEqual({ expect(store.state.projects.abcproject.mergeRequests).toEqual({
'2': jasmine.objectContaining(mrData), '2': expect.objectContaining(mrData),
}); });
done(); done();
}) })
...@@ -99,7 +102,7 @@ describe('IDE store merge request actions', () => { ...@@ -99,7 +102,7 @@ describe('IDE store merge request actions', () => {
describe('no merge requests for branch available case', () => { describe('no merge requests for branch available case', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectMergeRequests').and.callThrough(); jest.spyOn(service, 'getProjectMergeRequests');
mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, []); mock.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests/).reply(200, []);
}); });
...@@ -122,16 +125,11 @@ describe('IDE store merge request actions', () => { ...@@ -122,16 +125,11 @@ describe('IDE store merge request actions', () => {
}); });
it('flashes message, if error', done => { it('flashes message, if error', done => {
const flashSpy = spyOnDependency(actions, 'flash');
store store
.dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' }) .dispatch('getMergeRequestsForBranch', { projectId: TEST_PROJECT, branchId: 'bar' })
.then(() => {
fail('Expected getMergeRequestsForBranch to throw an error');
})
.catch(() => { .catch(() => {
expect(flashSpy).toHaveBeenCalled(); expect(createFlash).toHaveBeenCalled();
expect(flashSpy.calls.argsFor(0)[0]).toEqual('Error fetching merge requests for bar'); expect(createFlash.mock.calls[0][0]).toBe('Error fetching merge requests for bar');
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -142,7 +140,7 @@ describe('IDE store merge request actions', () => { ...@@ -142,7 +140,7 @@ describe('IDE store merge request actions', () => {
describe('getMergeRequestData', () => { describe('getMergeRequestData', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectMergeRequestData').and.callThrough(); jest.spyOn(service, 'getProjectMergeRequestData');
mock mock
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/) .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1/)
...@@ -181,7 +179,7 @@ describe('IDE store merge request actions', () => { ...@@ -181,7 +179,7 @@ describe('IDE store merge request actions', () => {
}); });
it('dispatches error action', done => { it('dispatches error action', done => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn();
getMergeRequestData( getMergeRequestData(
{ {
...@@ -195,7 +193,7 @@ describe('IDE store merge request actions', () => { ...@@ -195,7 +193,7 @@ describe('IDE store merge request actions', () => {
.catch(() => { .catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading the merge request.', text: 'An error occurred while loading the merge request.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { actionPayload: {
projectId: TEST_PROJECT, projectId: TEST_PROJECT,
...@@ -217,7 +215,7 @@ describe('IDE store merge request actions', () => { ...@@ -217,7 +215,7 @@ describe('IDE store merge request actions', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getProjectMergeRequestChanges').and.callThrough(); jest.spyOn(service, 'getProjectMergeRequestChanges');
mock mock
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/) .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/changes/)
...@@ -254,7 +252,7 @@ describe('IDE store merge request actions', () => { ...@@ -254,7 +252,7 @@ describe('IDE store merge request actions', () => {
}); });
it('dispatches error action', done => { it('dispatches error action', done => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn();
getMergeRequestChanges( getMergeRequestChanges(
{ {
...@@ -268,7 +266,7 @@ describe('IDE store merge request actions', () => { ...@@ -268,7 +266,7 @@ describe('IDE store merge request actions', () => {
.catch(() => { .catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading the merge request changes.', text: 'An error occurred while loading the merge request changes.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { actionPayload: {
projectId: TEST_PROJECT, projectId: TEST_PROJECT,
...@@ -293,7 +291,7 @@ describe('IDE store merge request actions', () => { ...@@ -293,7 +291,7 @@ describe('IDE store merge request actions', () => {
mock mock
.onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/) .onGet(/api\/(.*)\/projects\/abcproject\/merge_requests\/1\/versions/)
.reply(200, [{ id: 789 }]); .reply(200, [{ id: 789 }]);
spyOn(service, 'getProjectMergeRequestVersions').and.callThrough(); jest.spyOn(service, 'getProjectMergeRequestVersions');
}); });
it('calls getProjectMergeRequestVersions service method', done => { it('calls getProjectMergeRequestVersions service method', done => {
...@@ -324,7 +322,7 @@ describe('IDE store merge request actions', () => { ...@@ -324,7 +322,7 @@ describe('IDE store merge request actions', () => {
}); });
it('dispatches error action', done => { it('dispatches error action', done => {
const dispatch = jasmine.createSpy('dispatch'); const dispatch = jest.fn();
getMergeRequestVersions( getMergeRequestVersions(
{ {
...@@ -338,7 +336,7 @@ describe('IDE store merge request actions', () => { ...@@ -338,7 +336,7 @@ describe('IDE store merge request actions', () => {
.catch(() => { .catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading the merge request version data.', text: 'An error occurred while loading the merge request version data.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { actionPayload: {
projectId: TEST_PROJECT, projectId: TEST_PROJECT,
...@@ -400,7 +398,7 @@ describe('IDE store merge request actions', () => { ...@@ -400,7 +398,7 @@ describe('IDE store merge request actions', () => {
const originalDispatch = store.dispatch; const originalDispatch = store.dispatch;
spyOn(store, 'dispatch').and.callFake((type, payload) => { jest.spyOn(store, 'dispatch').mockImplementation((type, payload) => {
switch (type) { switch (type) {
case 'getMergeRequestData': case 'getMergeRequestData':
return Promise.resolve(testMergeRequest); return Promise.resolve(testMergeRequest);
...@@ -415,7 +413,7 @@ describe('IDE store merge request actions', () => { ...@@ -415,7 +413,7 @@ describe('IDE store merge request actions', () => {
return originalDispatch(type, payload); return originalDispatch(type, payload);
} }
}); });
spyOn(service, 'getFileData').and.callFake(() => jest.spyOn(service, 'getFileData').mockImplementation(() =>
Promise.resolve({ Promise.resolve({
headers: {}, headers: {},
}), }),
...@@ -425,7 +423,7 @@ describe('IDE store merge request actions', () => { ...@@ -425,7 +423,7 @@ describe('IDE store merge request actions', () => {
it('dispatches actions for merge request data', done => { it('dispatches actions for merge request data', done => {
openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr) openMergeRequest({ state: store.state, dispatch: store.dispatch, getters: mockGetters }, mr)
.then(() => { .then(() => {
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['getMergeRequestData', mr], ['getMergeRequestData', mr],
['setCurrentBranchId', testMergeRequest.source_branch], ['setCurrentBranchId', testMergeRequest.source_branch],
[ [
...@@ -493,15 +491,11 @@ describe('IDE store merge request actions', () => { ...@@ -493,15 +491,11 @@ describe('IDE store merge request actions', () => {
}); });
it('flashes message, if error', done => { it('flashes message, if error', done => {
const flashSpy = spyOnDependency(actions, 'flash'); store.dispatch.mockRejectedValue();
store.dispatch.and.returnValue(Promise.reject());
openMergeRequest(store, mr) openMergeRequest(store, mr)
.then(() => {
fail('Expected openMergeRequest to throw an error');
})
.catch(() => { .catch(() => {
expect(flashSpy).toHaveBeenCalledWith(jasmine.any(String)); expect(createFlash).toHaveBeenCalledWith(expect.any(String));
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { createStore } from '~/ide/stores';
import router from '~/ide/ide_router';
import { import {
refreshLastCommitData, refreshLastCommitData,
showBranchNotFoundError, showBranchNotFoundError,
...@@ -9,10 +11,8 @@ import { ...@@ -9,10 +11,8 @@ import {
loadFile, loadFile,
loadBranch, loadBranch,
} from '~/ide/stores/actions'; } from '~/ide/stores/actions';
import { createStore } from '~/ide/stores';
import service from '~/ide/services'; import service from '~/ide/services';
import api from '~/api'; import api from '~/api';
import router from '~/ide/ide_router';
import { resetStore } from '../../helpers'; import { resetStore } from '../../helpers';
import testAction from '../../../helpers/vuex_action_helper'; import testAction from '../../../helpers/vuex_action_helper';
...@@ -49,13 +49,11 @@ describe('IDE store project actions', () => { ...@@ -49,13 +49,11 @@ describe('IDE store project actions', () => {
}, },
}, },
}; };
spyOn(service, 'getBranchData').and.returnValue( jest.spyOn(service, 'getBranchData').mockResolvedValue({
Promise.resolve({
data: { data: {
commit: { id: '123' }, commit: { id: '123' },
}, },
}), });
);
}); });
it('calls the service', done => { it('calls the service', done => {
...@@ -110,7 +108,7 @@ describe('IDE store project actions', () => { ...@@ -110,7 +108,7 @@ describe('IDE store project actions', () => {
type: 'setErrorMessage', type: 'setErrorMessage',
payload: { payload: {
text: "Branch <strong>master</strong> was not found in this project's repository.", text: "Branch <strong>master</strong> was not found in this project's repository.",
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Create branch', actionText: 'Create branch',
actionPayload: 'master', actionPayload: 'master',
}, },
...@@ -122,10 +120,12 @@ describe('IDE store project actions', () => { ...@@ -122,10 +120,12 @@ describe('IDE store project actions', () => {
}); });
describe('createNewBranchFromDefault', () => { describe('createNewBranchFromDefault', () => {
it('calls API', done => { beforeEach(() => {
spyOn(api, 'createBranch').and.returnValue(Promise.resolve()); jest.spyOn(api, 'createBranch').mockResolvedValue();
spyOn(router, 'push'); jest.spyOn(router, 'push').mockImplementation();
});
it('calls API', done => {
createNewBranchFromDefault( createNewBranchFromDefault(
{ {
state: { state: {
...@@ -151,9 +151,7 @@ describe('IDE store project actions', () => { ...@@ -151,9 +151,7 @@ describe('IDE store project actions', () => {
}); });
it('clears error message', done => { it('clears error message', done => {
const dispatchSpy = jasmine.createSpy('dispatch'); const dispatchSpy = jest.fn().mockName('dispatch');
spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
spyOn(router, 'push');
createNewBranchFromDefault( createNewBranchFromDefault(
{ {
...@@ -177,9 +175,6 @@ describe('IDE store project actions', () => { ...@@ -177,9 +175,6 @@ describe('IDE store project actions', () => {
}); });
it('reloads window', done => { it('reloads window', done => {
spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
spyOn(router, 'push');
createNewBranchFromDefault( createNewBranchFromDefault(
{ {
state: { state: {
...@@ -215,7 +210,7 @@ describe('IDE store project actions', () => { ...@@ -215,7 +210,7 @@ describe('IDE store project actions', () => {
payload: { entry: store.state.trees[`${TEST_PROJECT_ID}/master`], forceValue: false }, payload: { entry: store.state.trees[`${TEST_PROJECT_ID}/master`], forceValue: false },
}, },
], ],
jasmine.any(Object), expect.any(Object),
done, done,
); );
}); });
...@@ -243,7 +238,7 @@ describe('IDE store project actions', () => { ...@@ -243,7 +238,7 @@ describe('IDE store project actions', () => {
'foo/bar': { pending: false }, 'foo/bar': { pending: false },
}, },
}); });
spyOn(store, 'dispatch'); jest.spyOn(store, 'dispatch').mockImplementation();
}); });
it('does nothing, if basePath is not given', () => { it('does nothing, if basePath is not given', () => {
...@@ -264,15 +259,15 @@ describe('IDE store project actions', () => { ...@@ -264,15 +259,15 @@ describe('IDE store project actions', () => {
it('does not handle tree entry action, if entry is pending', () => { it('does not handle tree entry action, if entry is pending', () => {
loadFile(store, { basePath: 'foo/bar-pending/' }); loadFile(store, { basePath: 'foo/bar-pending/' });
expect(store.dispatch).not.toHaveBeenCalledWith('handleTreeEntryAction', jasmine.anything()); expect(store.dispatch).not.toHaveBeenCalledWith('handleTreeEntryAction', expect.anything());
}); });
it('creates a new temp file supplied via URL if the file does not exist yet', () => { it('creates a new temp file supplied via URL if the file does not exist yet', () => {
loadFile(store, { basePath: 'not-existent.md' }); loadFile(store, { basePath: 'not-existent.md' });
expect(store.dispatch.calls.count()).toBe(1); expect(store.dispatch.mock.calls).toHaveLength(1);
expect(store.dispatch).not.toHaveBeenCalledWith('handleTreeEntryAction', jasmine.anything()); expect(store.dispatch).not.toHaveBeenCalledWith('handleTreeEntryAction', expect.anything());
expect(store.dispatch).toHaveBeenCalledWith('createTempEntry', { expect(store.dispatch).toHaveBeenCalledWith('createTempEntry', {
name: 'not-existent.md', name: 'not-existent.md',
...@@ -307,14 +302,14 @@ describe('IDE store project actions', () => { ...@@ -307,14 +302,14 @@ describe('IDE store project actions', () => {
it('fetches branch data', done => { it('fetches branch data', done => {
const mockGetters = { findBranch: () => ({ commit: { id: ref } }) }; const mockGetters = { findBranch: () => ({ commit: { id: ref } }) };
spyOn(store, 'dispatch').and.returnValue(Promise.resolve()); jest.spyOn(store, 'dispatch').mockResolvedValue();
loadBranch( loadBranch(
{ getters: mockGetters, state: store.state, dispatch: store.dispatch }, { getters: mockGetters, state: store.state, dispatch: store.dispatch },
{ projectId, branchId }, { projectId, branchId },
) )
.then(() => { .then(() => {
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }], ['getBranchData', { projectId, branchId }],
['getMergeRequestsForBranch', { projectId, branchId }], ['getMergeRequestsForBranch', { projectId, branchId }],
['getFiles', { projectId, branchId, ref }], ['getFiles', { projectId, branchId, ref }],
...@@ -325,12 +320,12 @@ describe('IDE store project actions', () => { ...@@ -325,12 +320,12 @@ describe('IDE store project actions', () => {
}); });
it('shows an error if branch can not be fetched', done => { it('shows an error if branch can not be fetched', done => {
spyOn(store, 'dispatch').and.returnValue(Promise.reject()); jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject());
loadBranch(store, { projectId, branchId }) loadBranch(store, { projectId, branchId })
.then(done.fail) .then(done.fail)
.catch(() => { .catch(() => {
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['getBranchData', { projectId, branchId }], ['getBranchData', { projectId, branchId }],
['showBranchNotFoundError', branchId], ['showBranchNotFoundError', branchId],
]); ]);
...@@ -360,13 +355,13 @@ describe('IDE store project actions', () => { ...@@ -360,13 +355,13 @@ describe('IDE store project actions', () => {
describe('existing branch', () => { describe('existing branch', () => {
beforeEach(() => { beforeEach(() => {
spyOn(store, 'dispatch').and.returnValue(Promise.resolve()); jest.spyOn(store, 'dispatch').mockResolvedValue();
}); });
it('dispatches branch actions', done => { it('dispatches branch actions', done => {
openBranch(store, branch) openBranch(store, branch)
.then(() => { .then(() => {
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId], ['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }], ['loadBranch', { projectId, branchId }],
['loadFile', { basePath: undefined }], ['loadFile', { basePath: undefined }],
...@@ -379,13 +374,13 @@ describe('IDE store project actions', () => { ...@@ -379,13 +374,13 @@ describe('IDE store project actions', () => {
describe('non-existent branch', () => { describe('non-existent branch', () => {
beforeEach(() => { beforeEach(() => {
spyOn(store, 'dispatch').and.returnValue(Promise.reject()); jest.spyOn(store, 'dispatch').mockReturnValue(Promise.reject());
}); });
it('dispatches correct branch actions', done => { it('dispatches correct branch actions', done => {
openBranch(store, branch) openBranch(store, branch)
.then(val => { .then(val => {
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['setCurrentBranchId', branchId], ['setCurrentBranchId', branchId],
['loadBranch', { projectId, branchId }], ['loadBranch', { projectId, branchId }],
]); ]);
......
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 { showTreeEntry, getFiles, setDirectoryData } from '~/ide/stores/actions/tree'; import { showTreeEntry, getFiles, setDirectoryData } from '~/ide/stores/actions/tree';
import * as types from '~/ide/stores/mutation_types'; import * as types from '~/ide/stores/mutation_types';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
...@@ -21,8 +21,7 @@ describe('Multi-file store tree actions', () => { ...@@ -21,8 +21,7 @@ describe('Multi-file store tree actions', () => {
}; };
beforeEach(() => { beforeEach(() => {
jasmine.clock().install(); jest.spyOn(router, 'push').mockImplementation();
spyOn(router, 'push');
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
...@@ -35,7 +34,6 @@ describe('Multi-file store tree actions', () => { ...@@ -35,7 +34,6 @@ describe('Multi-file store tree actions', () => {
}); });
afterEach(() => { afterEach(() => {
jasmine.clock().uninstall();
mock.restore(); mock.restore();
resetStore(store); resetStore(store);
}); });
...@@ -43,7 +41,7 @@ describe('Multi-file store tree actions', () => { ...@@ -43,7 +41,7 @@ describe('Multi-file store tree actions', () => {
describe('getFiles', () => { describe('getFiles', () => {
describe('success', () => { describe('success', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'getFiles').and.callThrough(); jest.spyOn(service, 'getFiles');
mock mock
.onGet(/(.*)/) .onGet(/(.*)/)
...@@ -54,15 +52,16 @@ describe('Multi-file store tree actions', () => { ...@@ -54,15 +52,16 @@ describe('Multi-file store tree actions', () => {
]); ]);
}); });
it('calls service getFiles', done => { it('calls service getFiles', () => {
return (
store store
.dispatch('getFiles', basicCallParameters) .dispatch('getFiles', basicCallParameters)
// getFiles actions calls lodash.defer
.then(() => jest.runOnlyPendingTimers())
.then(() => { .then(() => {
expect(service.getFiles).toHaveBeenCalledWith('foo/abcproject', '12345678'); expect(service.getFiles).toHaveBeenCalledWith('foo/abcproject', '12345678');
done();
}) })
.catch(done.fail); );
}); });
it('adds data into tree', done => { it('adds data into tree', done => {
...@@ -71,7 +70,7 @@ describe('Multi-file store tree actions', () => { ...@@ -71,7 +70,7 @@ describe('Multi-file store tree actions', () => {
.then(() => { .then(() => {
// The populating of the tree is deferred for performance reasons. // The populating of the tree is deferred for performance reasons.
// See this merge request for details: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/25700 // See this merge request for details: https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/25700
jasmine.clock().tick(1); jest.advanceTimersByTime(1);
}) })
.then(() => { .then(() => {
projectTree = store.state.trees['abcproject/master']; projectTree = store.state.trees['abcproject/master'];
...@@ -91,7 +90,7 @@ describe('Multi-file store tree actions', () => { ...@@ -91,7 +90,7 @@ describe('Multi-file store tree actions', () => {
describe('error', () => { describe('error', () => {
it('dispatches error action', done => { it('dispatches error action', done => {
const dispatch = jasmine.createSpy('dispatchSpy'); const dispatch = jest.fn();
store.state.projects = { store.state.projects = {
'abc/def': { 'abc/def': {
...@@ -127,7 +126,7 @@ describe('Multi-file store tree actions', () => { ...@@ -127,7 +126,7 @@ describe('Multi-file store tree actions', () => {
.catch(() => { .catch(() => {
expect(dispatch).toHaveBeenCalledWith('setErrorMessage', { expect(dispatch).toHaveBeenCalledWith('setErrorMessage', {
text: 'An error occurred while loading all the files.', text: 'An error occurred while loading all the files.',
action: jasmine.any(Function), action: expect.any(Function),
actionText: 'Please try again', actionText: 'Please try again',
actionPayload: { projectId: 'abc/def', branchId: 'master-testing' }, actionPayload: { projectId: 'abc/def', branchId: 'master-testing' },
}); });
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import actions, { import { visitUrl } from '~/lib/utils/url_utility';
import { createStore } from '~/ide/stores';
import router from '~/ide/ide_router';
import {
stageAllChanges, stageAllChanges,
unstageAllChanges, unstageAllChanges,
toggleFileFinder, toggleFileFinder,
...@@ -15,28 +18,29 @@ import actions, { ...@@ -15,28 +18,29 @@ import actions, {
discardAllChanges, discardAllChanges,
} from '~/ide/stores/actions'; } from '~/ide/stores/actions';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { createStore } from '~/ide/stores';
import * as types from '~/ide/stores/mutation_types'; import * as types from '~/ide/stores/mutation_types';
import router from '~/ide/ide_router';
import { file } from '../helpers'; import { file } from '../helpers';
import testAction from '../../helpers/vuex_action_helper'; import testAction from '../../helpers/vuex_action_helper';
import eventHub from '~/ide/eventhub'; import eventHub from '~/ide/eventhub';
jest.mock('~/lib/utils/url_utility', () => ({
visitUrl: jest.fn(),
joinPaths: jest.requireActual('~/lib/utils/url_utility').joinPaths,
}));
describe('Multi-file store actions', () => { describe('Multi-file store actions', () => {
let store; let store;
beforeEach(() => { beforeEach(() => {
store = createStore(); store = createStore();
spyOn(store, 'commit').and.callThrough(); jest.spyOn(store, 'commit');
spyOn(store, 'dispatch').and.callThrough(); jest.spyOn(store, 'dispatch');
spyOn(router, 'push'); jest.spyOn(router, 'push').mockImplementation();
}); });
describe('redirectToUrl', () => { describe('redirectToUrl', () => {
it('calls visitUrl', done => { it('calls visitUrl', done => {
const visitUrl = spyOnDependency(actions, 'visitUrl');
store store
.dispatch('redirectToUrl', 'test') .dispatch('redirectToUrl', 'test')
.then(() => { .then(() => {
...@@ -79,7 +83,7 @@ describe('Multi-file store actions', () => { ...@@ -79,7 +83,7 @@ describe('Multi-file store actions', () => {
discardAllChanges(store); discardAllChanges(store);
expect(store.dispatch.calls.allArgs()).toEqual(jasmine.arrayContaining(expectedCalls)); expect(store.dispatch.mock.calls).toEqual(expect.arrayContaining(expectedCalls));
}); });
it('removes all files from changedFiles state', done => { it('removes all files from changedFiles state', done => {
...@@ -255,7 +259,7 @@ describe('Multi-file store actions', () => { ...@@ -255,7 +259,7 @@ describe('Multi-file store actions', () => {
type: 'blob', type: 'blob',
}) })
.then(() => { .then(() => {
expect(store.state.stagedFiles).toEqual([jasmine.objectContaining({ name })]); expect(store.state.stagedFiles).toEqual([expect.objectContaining({ name })]);
done(); done();
}) })
...@@ -311,12 +315,12 @@ describe('Multi-file store actions', () => { ...@@ -311,12 +315,12 @@ describe('Multi-file store actions', () => {
document.body.innerHTML += document.body.innerHTML +=
'<div id="tabs"><div class="active"><div class="repo-tab"></div></div></div>'; '<div id="tabs"><div class="active"><div class="repo-tab"></div></div></div>';
const el = document.querySelector('.repo-tab'); const el = document.querySelector('.repo-tab');
spyOn(el, 'focus'); jest.spyOn(el, 'focus').mockImplementation();
store store
.dispatch('scrollToTab') .dispatch('scrollToTab')
.then(() => { .then(() => {
setTimeout(() => { setImmediate(() => {
expect(el.focus).toHaveBeenCalled(); expect(el.focus).toHaveBeenCalled();
document.getElementById('tabs').remove(); document.getElementById('tabs').remove();
...@@ -350,16 +354,16 @@ describe('Multi-file store actions', () => { ...@@ -350,16 +354,16 @@ describe('Multi-file store actions', () => {
it('adds all files from changedFiles to stagedFiles', () => { it('adds all files from changedFiles to stagedFiles', () => {
stageAllChanges(store); stageAllChanges(store);
expect(store.commit.calls.allArgs()).toEqual([ expect(store.commit.mock.calls).toEqual([
[types.SET_LAST_COMMIT_MSG, ''], [types.SET_LAST_COMMIT_MSG, ''],
[types.STAGE_CHANGE, jasmine.objectContaining({ path: file1.path })], [types.STAGE_CHANGE, expect.objectContaining({ path: file1.path })],
]); ]);
}); });
it('opens pending tab if a change exists in that file', () => { it('opens pending tab if a change exists in that file', () => {
stageAllChanges(store); stageAllChanges(store);
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
[ [
'openPendingTab', 'openPendingTab',
{ file: { ...file1, staged: true, changed: true }, keyPrefix: 'staged' }, { file: { ...file1, staged: true, changed: true }, keyPrefix: 'staged' },
...@@ -382,15 +386,15 @@ describe('Multi-file store actions', () => { ...@@ -382,15 +386,15 @@ describe('Multi-file store actions', () => {
it('removes all files from stagedFiles after unstaging', () => { it('removes all files from stagedFiles after unstaging', () => {
unstageAllChanges(store); unstageAllChanges(store);
expect(store.commit.calls.allArgs()).toEqual([ expect(store.commit.mock.calls).toEqual([
[types.UNSTAGE_CHANGE, jasmine.objectContaining({ path: file2.path })], [types.UNSTAGE_CHANGE, expect.objectContaining({ path: file2.path })],
]); ]);
}); });
it('opens pending tab if a change exists in that file', () => { it('opens pending tab if a change exists in that file', () => {
unstageAllChanges(store); unstageAllChanges(store);
expect(store.dispatch.calls.allArgs()).toEqual([ expect(store.dispatch.mock.calls).toEqual([
['openPendingTab', { file: file1, keyPrefix: 'unstaged' }], ['openPendingTab', { file: file1, keyPrefix: 'unstaged' }],
]); ]);
}); });
...@@ -696,7 +700,7 @@ describe('Multi-file store actions', () => { ...@@ -696,7 +700,7 @@ describe('Multi-file store actions', () => {
describe('renameEntry', () => { describe('renameEntry', () => {
describe('purging of file model cache', () => { describe('purging of file model cache', () => {
beforeEach(() => { beforeEach(() => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit').mockImplementation();
}); });
it('does not purge model cache for temporary entries that got renamed', done => { it('does not purge model cache for temporary entries that got renamed', done => {
...@@ -715,9 +719,7 @@ describe('Multi-file store actions', () => { ...@@ -715,9 +719,7 @@ describe('Multi-file store actions', () => {
name: 'new', name: 'new',
}) })
.then(() => { .then(() => {
expect(eventHub.$emit.calls.allArgs()).not.toContain( expect(eventHub.$emit.mock.calls).not.toContain('editor.update.model.dispose.foo-bar');
'editor.update.model.dispose.foo-bar',
);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -768,17 +770,17 @@ describe('Multi-file store actions', () => { ...@@ -768,17 +770,17 @@ describe('Multi-file store actions', () => {
}); });
it('by default renames an entry and stages it', () => { it('by default renames an entry and stages it', () => {
const dispatch = jasmine.createSpy(); const dispatch = jest.fn();
const commit = jasmine.createSpy(); const commit = jest.fn();
renameEntry( renameEntry(
{ dispatch, commit, state: store.state, getters: store.getters }, { dispatch, commit, state: store.state, getters: store.getters },
{ path: 'orig', name: 'renamed' }, { path: 'orig', name: 'renamed' },
); );
expect(commit.calls.allArgs()).toEqual([ expect(commit.mock.calls).toEqual([
[types.RENAME_ENTRY, { path: 'orig', name: 'renamed', parentPath: undefined }], [types.RENAME_ENTRY, { path: 'orig', name: 'renamed', parentPath: undefined }],
[types.STAGE_CHANGE, jasmine.objectContaining({ path: 'renamed' })], [types.STAGE_CHANGE, expect.objectContaining({ path: 'renamed' })],
]); ]);
}); });
...@@ -813,7 +815,7 @@ describe('Multi-file store actions', () => { ...@@ -813,7 +815,7 @@ describe('Multi-file store actions', () => {
renameEntry, renameEntry,
{ path: 'orig', name: 'renamed' }, { path: 'orig', name: 'renamed' },
store.state, store.state,
[jasmine.objectContaining({ type: types.RENAME_ENTRY })], [expect.objectContaining({ type: types.RENAME_ENTRY })],
[{ type: 'triggerFilesChange' }], [{ type: 'triggerFilesChange' }],
done, done,
); );
...@@ -831,7 +833,7 @@ describe('Multi-file store actions', () => { ...@@ -831,7 +833,7 @@ describe('Multi-file store actions', () => {
name: 'renamed', name: 'renamed',
}) })
.then(() => { .then(() => {
expect(router.push.calls.count()).toBe(1); expect(router.push.mock.calls).toHaveLength(1);
expect(router.push).toHaveBeenCalledWith(`/project/foo-bar.md`); expect(router.push).toHaveBeenCalledWith(`/project/foo-bar.md`);
}) })
.then(done) .then(done)
...@@ -918,7 +920,7 @@ describe('Multi-file store actions', () => { ...@@ -918,7 +920,7 @@ describe('Multi-file store actions', () => {
expect(entries['new-folder']).toBeDefined(); expect(entries['new-folder']).toBeDefined();
expect(entries['new-folder/test']).toEqual( expect(entries['new-folder/test']).toEqual(
jasmine.objectContaining({ expect.objectContaining({
path: 'new-folder/test', path: 'new-folder/test',
name: 'test', name: 'test',
prevPath: 'old-folder/test', prevPath: 'old-folder/test',
...@@ -941,7 +943,7 @@ describe('Multi-file store actions', () => { ...@@ -941,7 +943,7 @@ describe('Multi-file store actions', () => {
expect(entries['old-folder']).toBeDefined(); expect(entries['old-folder']).toBeDefined();
expect(entries['old-folder/test']).toEqual( expect(entries['old-folder/test']).toEqual(
jasmine.objectContaining({ expect.objectContaining({
path: 'old-folder/test', path: 'old-folder/test',
name: 'test', name: 'test',
prevPath: undefined, prevPath: undefined,
...@@ -989,10 +991,10 @@ describe('Multi-file store actions', () => { ...@@ -989,10 +991,10 @@ describe('Multi-file store actions', () => {
.dispatch('renameEntry', { path: filePath, name: fileName, parentPath: newParentPath }) .dispatch('renameEntry', { path: filePath, name: fileName, parentPath: newParentPath })
.then(() => { .then(() => {
expect(store.state.entries[newParentPath]).toEqual( expect(store.state.entries[newParentPath]).toEqual(
jasmine.objectContaining({ expect.objectContaining({
path: newParentPath, path: newParentPath,
type: 'tree', type: 'tree',
tree: jasmine.arrayContaining([ tree: expect.arrayContaining([
store.state.entries[`${newParentPath}/${fileName}`], store.state.entries[`${newParentPath}/${fileName}`],
]), ]),
}), }),
...@@ -1078,7 +1080,7 @@ describe('Multi-file store actions', () => { ...@@ -1078,7 +1080,7 @@ describe('Multi-file store actions', () => {
branchId: 'master-testing', branchId: 'master-testing',
}, },
]; ];
dispatch = jasmine.createSpy('dispatchSpy'); dispatch = jest.fn();
document.body.innerHTML += '<div class="flash-container"></div>'; document.body.innerHTML += '<div class="flash-container"></div>';
}); });
...@@ -1092,7 +1094,7 @@ describe('Multi-file store actions', () => { ...@@ -1092,7 +1094,7 @@ describe('Multi-file store actions', () => {
getBranchData(...callParams) getBranchData(...callParams)
.then(done.fail) .then(done.fail)
.catch(e => { .catch(e => {
expect(dispatch.calls.count()).toEqual(0); expect(dispatch.mock.calls).toHaveLength(0);
expect(e.response.status).toEqual(404); expect(e.response.status).toEqual(404);
expect(document.querySelector('.flash-alert')).toBeNull(); expect(document.querySelector('.flash-alert')).toBeNull();
done(); done();
...@@ -1105,7 +1107,7 @@ describe('Multi-file store actions', () => { ...@@ -1105,7 +1107,7 @@ describe('Multi-file store actions', () => {
getBranchData(...callParams) getBranchData(...callParams)
.then(done.fail) .then(done.fail)
.catch(e => { .catch(e => {
expect(dispatch.calls.count()).toEqual(0); expect(dispatch.mock.calls).toHaveLength(0);
expect(e.response).toBeUndefined(); expect(e.response).toBeUndefined();
expect(document.querySelector('.flash-alert')).not.toBeNull(); expect(document.querySelector('.flash-alert')).not.toBeNull();
done(); done();
......
import { resetStore, file } from 'spec/ide/helpers'; import { resetStore, file } from 'jest/ide/helpers';
import rootActions from '~/ide/stores/actions'; import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import { visitUrl } from '~/lib/utils/url_utility';
import { createStore } from '~/ide/stores'; import { createStore } from '~/ide/stores';
import service from '~/ide/services'; import service from '~/ide/services';
import router from '~/ide/ide_router'; import router from '~/ide/ide_router';
...@@ -10,15 +12,28 @@ import * as actions from '~/ide/stores/modules/commit/actions'; ...@@ -10,15 +12,28 @@ import * as actions from '~/ide/stores/modules/commit/actions';
import { commitActionTypes, PERMISSION_CREATE_MR } from '~/ide/constants'; import { commitActionTypes, PERMISSION_CREATE_MR } from '~/ide/constants';
import testAction from '../../../../helpers/vuex_action_helper'; import testAction from '../../../../helpers/vuex_action_helper';
jest.mock('~/lib/utils/url_utility', () => ({
visitUrl: jest.fn(),
joinPaths: jest.requireActual('~/lib/utils/url_utility').joinPaths,
}));
const TEST_COMMIT_SHA = '123456789'; const TEST_COMMIT_SHA = '123456789';
const store = createStore(); const store = createStore();
describe('IDE commit module actions', () => { describe('IDE commit module actions', () => {
let mock;
beforeEach(() => { beforeEach(() => {
spyOn(router, 'push'); gon.api_version = 'v1';
mock = new MockAdapter(axios);
jest.spyOn(router, 'push').mockImplementation();
mock.onGet('/api/v1/projects/abcproject/repository/branches/master').reply(200);
}); });
afterEach(() => { afterEach(() => {
delete gon.api_version;
mock.restore();
resetStore(store); resetStore(store);
}); });
...@@ -71,7 +86,7 @@ describe('IDE commit module actions', () => { ...@@ -71,7 +86,7 @@ describe('IDE commit module actions', () => {
[ [
{ {
type: mutationTypes.UPDATE_COMMIT_ACTION, type: mutationTypes.UPDATE_COMMIT_ACTION,
payload: { commitAction: jasmine.anything() }, payload: { commitAction: expect.anything() },
}, },
{ type: mutationTypes.TOGGLE_SHOULD_CREATE_MR, payload: true }, { type: mutationTypes.TOGGLE_SHOULD_CREATE_MR, payload: true },
], ],
...@@ -92,7 +107,7 @@ describe('IDE commit module actions', () => { ...@@ -92,7 +107,7 @@ describe('IDE commit module actions', () => {
[ [
{ {
type: mutationTypes.UPDATE_COMMIT_ACTION, type: mutationTypes.UPDATE_COMMIT_ACTION,
payload: { commitAction: jasmine.anything() }, payload: { commitAction: expect.anything() },
}, },
{ type: mutationTypes.TOGGLE_SHOULD_CREATE_MR, payload: false }, { type: mutationTypes.TOGGLE_SHOULD_CREATE_MR, payload: false },
], ],
...@@ -168,7 +183,7 @@ describe('IDE commit module actions', () => { ...@@ -168,7 +183,7 @@ describe('IDE commit module actions', () => {
let f; let f;
beforeEach(() => { beforeEach(() => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit').mockImplementation();
f = file('changedFile'); f = file('changedFile');
Object.assign(f, { Object.assign(f, {
...@@ -200,9 +215,9 @@ describe('IDE commit module actions', () => { ...@@ -200,9 +215,9 @@ describe('IDE commit module actions', () => {
changed: true, changed: true,
}, },
], ],
openFiles: store.state.stagedFiles,
}); });
store.state.openFiles = store.state.stagedFiles;
store.state.stagedFiles.forEach(stagedFile => { store.state.stagedFiles.forEach(stagedFile => {
store.state.entries[stagedFile.path] = stagedFile; store.state.entries[stagedFile.path] = stagedFile;
}); });
...@@ -280,11 +295,7 @@ describe('IDE commit module actions', () => { ...@@ -280,11 +295,7 @@ describe('IDE commit module actions', () => {
}); });
describe('commitChanges', () => { describe('commitChanges', () => {
let visitUrl;
beforeEach(() => { beforeEach(() => {
visitUrl = spyOnDependency(rootActions, 'visitUrl');
document.body.innerHTML += '<div class="flash-container"></div>'; document.body.innerHTML += '<div class="flash-container"></div>';
const f = { const f = {
...@@ -346,11 +357,7 @@ describe('IDE commit module actions', () => { ...@@ -346,11 +357,7 @@ describe('IDE commit module actions', () => {
}; };
beforeEach(() => { beforeEach(() => {
spyOn(service, 'commit').and.returnValue( jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
Promise.resolve({
data: COMMIT_RESPONSE,
}),
);
}); });
it('calls service', done => { it('calls service', done => {
...@@ -358,14 +365,14 @@ describe('IDE commit module actions', () => { ...@@ -358,14 +365,14 @@ describe('IDE commit module actions', () => {
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
.then(() => { .then(() => {
expect(service.commit).toHaveBeenCalledWith('abcproject', { expect(service.commit).toHaveBeenCalledWith('abcproject', {
branch: jasmine.anything(), branch: expect.anything(),
commit_message: 'testing 123', commit_message: 'testing 123',
actions: [ actions: [
{ {
action: commitActionTypes.update, action: commitActionTypes.update,
file_path: jasmine.anything(), file_path: expect.anything(),
content: '\n', content: '\n',
encoding: jasmine.anything(), encoding: expect.anything(),
last_commit_id: undefined, last_commit_id: undefined,
previous_path: undefined, previous_path: undefined,
}, },
...@@ -385,14 +392,14 @@ describe('IDE commit module actions', () => { ...@@ -385,14 +392,14 @@ describe('IDE commit module actions', () => {
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
.then(() => { .then(() => {
expect(service.commit).toHaveBeenCalledWith('abcproject', { expect(service.commit).toHaveBeenCalledWith('abcproject', {
branch: jasmine.anything(), branch: expect.anything(),
commit_message: 'testing 123', commit_message: 'testing 123',
actions: [ actions: [
{ {
action: commitActionTypes.update, action: commitActionTypes.update,
file_path: jasmine.anything(), file_path: expect.anything(),
content: '\n', content: '\n',
encoding: jasmine.anything(), encoding: expect.anything(),
last_commit_id: TEST_COMMIT_SHA, last_commit_id: TEST_COMMIT_SHA,
previous_path: undefined, previous_path: undefined,
}, },
...@@ -455,7 +462,7 @@ describe('IDE commit module actions', () => { ...@@ -455,7 +462,7 @@ describe('IDE commit module actions', () => {
describe('merge request', () => { describe('merge request', () => {
it('redirects to new merge request page', done => { it('redirects to new merge request page', done => {
spyOn(eventHub, '$on'); jest.spyOn(eventHub, '$on').mockImplementation();
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store.state.commit.shouldCreateMR = true; store.state.commit.shouldCreateMR = true;
...@@ -475,7 +482,7 @@ describe('IDE commit module actions', () => { ...@@ -475,7 +482,7 @@ describe('IDE commit module actions', () => {
}); });
it('does not redirect to new merge request page when shouldCreateMR is not checked', done => { it('does not redirect to new merge request page when shouldCreateMR is not checked', done => {
spyOn(eventHub, '$on'); jest.spyOn(eventHub, '$on').mockImplementation();
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store.state.commit.shouldCreateMR = false; store.state.commit.shouldCreateMR = false;
...@@ -489,30 +496,25 @@ describe('IDE commit module actions', () => { ...@@ -489,30 +496,25 @@ describe('IDE commit module actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('resets changed files before redirecting', done => { it('resets changed files before redirecting', () => {
visitUrl = visitUrl.and.callFake(() => { jest.spyOn(eventHub, '$on').mockImplementation();
expect(store.state.stagedFiles.length).toBe(0);
done();
});
spyOn(eventHub, '$on');
store.state.commit.commitAction = '3'; store.state.commit.commitAction = '3';
store.dispatch('commit/commitChanges').catch(done.fail); return store.dispatch('commit/commitChanges').then(() => {
expect(store.state.stagedFiles.length).toBe(0);
});
}); });
}); });
}); });
describe('failed', () => { describe('failed', () => {
beforeEach(() => { beforeEach(() => {
spyOn(service, 'commit').and.returnValue( jest.spyOn(service, 'commit').mockResolvedValue({
Promise.resolve({
data: { data: {
message: 'failed message', message: 'failed message',
}, },
}), });
);
}); });
it('shows failed message', done => { it('shows failed message', done => {
...@@ -543,20 +545,15 @@ describe('IDE commit module actions', () => { ...@@ -543,20 +545,15 @@ describe('IDE commit module actions', () => {
}; };
it('commits TOGGLE_EMPTY_STATE mutation on empty repo', done => { it('commits TOGGLE_EMPTY_STATE mutation on empty repo', done => {
spyOn(service, 'commit').and.returnValue( jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
Promise.resolve({ jest.spyOn(store, 'commit');
data: COMMIT_RESPONSE,
}),
);
spyOn(store, 'commit').and.callThrough();
store store
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
.then(() => { .then(() => {
expect(store.commit.calls.allArgs()).toEqual( expect(store.commit.mock.calls).toEqual(
jasmine.arrayContaining([ expect.arrayContaining([
['TOGGLE_EMPTY_STATE', jasmine.any(Object), jasmine.any(Object)], ['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)],
]), ]),
); );
done(); done();
...@@ -566,19 +563,15 @@ describe('IDE commit module actions', () => { ...@@ -566,19 +563,15 @@ describe('IDE commit module actions', () => {
it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', done => { it('does not commmit TOGGLE_EMPTY_STATE mutation on existing project', done => {
COMMIT_RESPONSE.parent_ids.push('1234'); COMMIT_RESPONSE.parent_ids.push('1234');
spyOn(service, 'commit').and.returnValue( jest.spyOn(service, 'commit').mockResolvedValue({ data: COMMIT_RESPONSE });
Promise.resolve({ jest.spyOn(store, 'commit');
data: COMMIT_RESPONSE,
}),
);
spyOn(store, 'commit').and.callThrough();
store store
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
.then(() => { .then(() => {
expect(store.commit.calls.allArgs()).not.toEqual( expect(store.commit.mock.calls).not.toEqual(
jasmine.arrayContaining([ expect.arrayContaining([
['TOGGLE_EMPTY_STATE', jasmine.any(Object), jasmine.any(Object)], ['TOGGLE_EMPTY_STATE', expect.any(Object), expect.any(Object)],
]), ]),
); );
done(); done();
......
export * from '../../frontend/ide/helpers';
export * from '../../frontend/ide/mock_data';
import Vue from 'vue'; import Vue from 'vue';
import Mousetrap from 'mousetrap'; import Mousetrap from 'mousetrap';
import { file } from 'spec/ide/helpers'; import { file } from 'jest/ide/helpers';
import timeoutPromise from 'spec/helpers/set_timeout_promise_helper'; import timeoutPromise from 'spec/helpers/set_timeout_promise_helper';
import FindFileComponent from '~/vue_shared/components/file_finder/index.vue'; import FindFileComponent from '~/vue_shared/components/file_finder/index.vue';
import { UP_KEY_CODE, DOWN_KEY_CODE, ENTER_KEY_CODE, ESC_KEY_CODE } from '~/lib/utils/keycodes'; import { UP_KEY_CODE, DOWN_KEY_CODE, ENTER_KEY_CODE, ESC_KEY_CODE } from '~/lib/utils/keycodes';
......
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