Commit 093e43a0 authored by Phil Hughes's avatar Phil Hughes

store specs

parent 93e5d8c7
......@@ -4,6 +4,7 @@ import { __, sprintf } from '~/locale';
import service from '../../services';
import api from '../../../api';
import * as types from '../mutation_types';
import { refreshCurrentPage } from '../../../lib/utils/url_utility';
export const getProjectData = ({ commit, state }, { namespace, projectId, force = false } = {}) =>
new Promise((resolve, reject) => {
......@@ -97,7 +98,7 @@ export const createNewBranchFromDefault = ({ state, getters }, branch) =>
branch,
})
.then(() => {
window.location.reload();
refreshCurrentPage();
// this forces the loading icon to spin whilst the page is reloading
return new Promise(() => {});
......
import { refreshLastCommitData } from '~/ide/stores/actions';
import {
refreshLastCommitData,
showBranchNotFoundError,
createNewBranchFromDefault,
} from '~/ide/stores/actions';
import store from '~/ide/stores';
import projectActions from '~/ide/stores/actions/project';
import service from '~/ide/services';
import api from '~/api';
import { resetStore } from '../../helpers';
import testAction from '../../../helpers/vuex_action_helper';
......@@ -80,4 +86,82 @@ describe('IDE store project actions', () => {
);
});
});
describe('showBranchNotFoundError', () => {
it('dispatches setErrorMessage', done => {
testAction(
showBranchNotFoundError,
'master',
null,
[],
[
{
type: 'setErrorMessage',
payload: {
text: "Branch <strong>master</strong> was not found in this project's repository.",
action: 'createNewBranchFromDefault',
actionText: 'Create branch',
actionPayload: 'master',
},
},
],
done,
);
});
});
describe('createNewBranchFromDefault', () => {
it('calls API', done => {
spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
spyOnDependency(projectActions, 'refreshCurrentPage');
createNewBranchFromDefault(
{
state: {
currentProjectId: 'project-path',
},
getters: {
currentProject: {
default_branch: 'master',
},
},
},
'new-branch-name',
);
setTimeout(() => {
expect(api.createBranch).toHaveBeenCalledWith('project-path', {
ref: 'master',
branch: 'new-branch-name',
});
done();
});
});
it('reloads window', done => {
spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
const refreshSpy = spyOnDependency(projectActions, 'refreshCurrentPage');
createNewBranchFromDefault(
{
state: {
currentProjectId: 'project-path',
},
getters: {
currentProject: {
default_branch: 'master',
},
},
},
'new-branch-name',
);
setTimeout(() => {
expect(refreshSpy).toHaveBeenCalled();
done();
});
});
});
});
......@@ -6,6 +6,7 @@ import actions, {
setEmptyStateSvgs,
updateActivityBarView,
updateTempFlagForEntry,
setErrorMessage,
} from '~/ide/stores/actions';
import store from '~/ide/stores';
import * as types from '~/ide/stores/mutation_types';
......@@ -443,4 +444,17 @@ describe('Multi-file store actions', () => {
);
});
});
describe('setErrorMessage', () => {
it('commis error messsage', done => {
testAction(
setErrorMessage,
'error',
null,
[{ type: types.SET_ERROR_MESSAGE, payload: 'error' }],
[],
done,
);
});
});
});
......@@ -148,4 +148,12 @@ describe('Multi-file store mutations', () => {
expect(localState.unusedSeal).toBe(false);
});
});
describe('SET_ERROR_MESSAGE', () => {
it('updates error message', () => {
mutations.SET_ERROR_MESSAGE(localState, 'error');
expect(localState.errorMessage).toBe('error');
});
});
});
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