diff options
author | Phil Hughes <me@iamphill.com> | 2018-06-26 16:51:57 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-06-27 10:44:15 +0100 |
commit | 093e43a01157854f0ef1ce435e7935feba041e27 (patch) | |
tree | 9add61cd927b323257ae36bc17729cd55d9d9bb6 | |
parent | 93e5d8c7520b21561b96cbbe8134283d3aa728f9 (diff) | |
download | gitlab-ce-093e43a01157854f0ef1ce435e7935feba041e27.tar.gz |
:white_check_mark: store specs
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/project.js | 3 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions/project_spec.js | 86 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/actions_spec.js | 14 | ||||
-rw-r--r-- | spec/javascripts/ide/stores/mutations_spec.js | 8 |
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'); + }); + }); }); |