summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-06-26 16:51:57 +0100
committerPhil Hughes <me@iamphill.com>2018-06-26 16:51:57 +0100
commit055737b9a3f5159437fb2ef2b22d4022fccb70e3 (patch)
treedb8b3d82ee366344a9d75dab1898d940ff96a664
parentf2eaaf76c9e23eebae1fef31abaf755c19e1391c (diff)
downloadgitlab-ce-ide-improve-error-messages.tar.gz
:white_check_mark: store specside-improve-error-messages
-rw-r--r--app/assets/javascripts/ide/stores/actions/project.js3
-rw-r--r--spec/javascripts/ide/stores/actions/project_spec.js86
-rw-r--r--spec/javascripts/ide/stores/actions_spec.js14
-rw-r--r--spec/javascripts/ide/stores/mutations_spec.js8
4 files changed, 109 insertions, 2 deletions
diff --git a/app/assets/javascripts/ide/stores/actions/project.js b/app/assets/javascripts/ide/stores/actions/project.js
index 20fd12596f9..54785770e7f 100644
--- a/app/assets/javascripts/ide/stores/actions/project.js
+++ b/app/assets/javascripts/ide/stores/actions/project.js
@@ -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(() => {});
diff --git a/spec/javascripts/ide/stores/actions/project_spec.js b/spec/javascripts/ide/stores/actions/project_spec.js
index d71fc0e035e..5529fe44ce5 100644
--- a/spec/javascripts/ide/stores/actions/project_spec.js
+++ b/spec/javascripts/ide/stores/actions/project_spec.js
@@ -1,6 +1,12 @@
-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();
+ });
+ });
+ });
});
diff --git a/spec/javascripts/ide/stores/actions_spec.js b/spec/javascripts/ide/stores/actions_spec.js
index 062c3497623..8b665a6d79e 100644
--- a/spec/javascripts/ide/stores/actions_spec.js
+++ b/spec/javascripts/ide/stores/actions_spec.js
@@ -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,
+ );
+ });
+ });
});
diff --git a/spec/javascripts/ide/stores/mutations_spec.js b/spec/javascripts/ide/stores/mutations_spec.js
index 972713c5ad2..98016f593aa 100644
--- a/spec/javascripts/ide/stores/mutations_spec.js
+++ b/spec/javascripts/ide/stores/mutations_spec.js
@@ -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');
+ });
+ });
});