Commit 66699030 authored by Phil Hughes's avatar Phil Hughes

Merge branch '57482-shortcut-to-create-merge-request-from-web-ide' into 'master'

Resolve "Shortcut to create merge request from Web IDE"

Closes #57482

See merge request gitlab-org/gitlab-ce!26792
parents 8e04450c 2571856f
<script> <script>
import _ from 'underscore'; import _ from 'underscore';
import { mapActions, mapState, mapGetters } from 'vuex'; import { mapActions, mapState, mapGetters, createNamespacedHelpers } from 'vuex';
import { sprintf, __ } from '~/locale'; import { sprintf, __ } from '~/locale';
import * as consts from '../../stores/modules/commit/constants'; import consts from '../../stores/modules/commit/constants';
import RadioGroup from './radio_group.vue'; import RadioGroup from './radio_group.vue';
const { mapState: mapCommitState, mapGetters: mapCommitGetters } = createNamespacedHelpers(
'commit',
);
export default { export default {
components: { components: {
RadioGroup, RadioGroup,
}, },
computed: { computed: {
...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']), ...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
...mapGetters(['currentProject', 'currentBranch']), ...mapCommitState(['commitAction', 'shouldCreateMR', 'shouldDisableNewMrOption']),
...mapGetters(['currentProject', 'currentBranch', 'currentMergeRequest']),
...mapCommitGetters(['shouldDisableNewMrOption']),
commitToCurrentBranchText() { commitToCurrentBranchText() {
return sprintf( return sprintf(
__('Commit to %{branchName} branch'), __('Commit to %{branchName} branch'),
...@@ -32,7 +38,7 @@ export default { ...@@ -32,7 +38,7 @@ export default {
this.updateSelectedCommitAction(); this.updateSelectedCommitAction();
}, },
methods: { methods: {
...mapActions('commit', ['updateCommitAction']), ...mapActions('commit', ['updateCommitAction', 'toggleShouldCreateMR']),
updateSelectedCommitAction() { updateSelectedCommitAction() {
if (this.currentBranch && !this.currentBranch.can_push) { if (this.currentBranch && !this.currentBranch.can_push) {
this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH); this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH);
...@@ -43,7 +49,6 @@ export default { ...@@ -43,7 +49,6 @@ export default {
}, },
commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH, commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH,
commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH, commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH,
commitToNewBranchMR: consts.COMMIT_TO_NEW_BRANCH_MR,
currentBranchPermissionsTooltip: __( currentBranchPermissionsTooltip: __(
"This option is disabled as you don't have write permissions for the current branch", "This option is disabled as you don't have write permissions for the current branch",
), ),
...@@ -64,13 +69,17 @@ export default { ...@@ -64,13 +69,17 @@ export default {
:label="__('Create a new branch')" :label="__('Create a new branch')"
:show-input="true" :show-input="true"
/> />
<radio-group <hr class="my-2" />
v-if="currentProject.merge_requests_enabled" <label class="mb-0">
:value="$options.commitToNewBranchMR" <input
:label="__('Create a new branch and merge request')" :checked="shouldCreateMR"
:title="__('This option is disabled while you still have unstaged changes')" :disabled="shouldDisableNewMrOption"
:show-input="true" type="checkbox"
:disabled="disableMergeRequestRadio" @change="toggleShouldCreateMR"
/> />
<span class="prepend-left-10" :class="{ 'text-secondary': shouldDisableNewMrOption }">
{{ __('Start a new merge request') }}
</span>
</label>
</div> </div>
</template> </template>
...@@ -5,7 +5,7 @@ import Icon from '~/vue_shared/components/icon.vue'; ...@@ -5,7 +5,7 @@ import Icon from '~/vue_shared/components/icon.vue';
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue'; import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue';
import CommitFilesList from './commit_sidebar/list.vue'; import CommitFilesList from './commit_sidebar/list.vue';
import EmptyState from './commit_sidebar/empty_state.vue'; import EmptyState from './commit_sidebar/empty_state.vue';
import * as consts from '../stores/modules/commit/constants'; import consts from '../stores/modules/commit/constants';
import { activityBarViews, stageKeys } from '../constants'; import { activityBarViews, stageKeys } from '../constants';
export default { export default {
......
...@@ -25,7 +25,10 @@ export const projectsWithTrees = state => ...@@ -25,7 +25,10 @@ export const projectsWithTrees = state =>
}); });
export const currentMergeRequest = state => { export const currentMergeRequest = state => {
if (state.projects[state.currentProjectId]) { if (
state.projects[state.currentProjectId] &&
state.projects[state.currentProjectId].mergeRequests
) {
return state.projects[state.currentProjectId].mergeRequests[state.currentMergeRequestId]; return state.projects[state.currentProjectId].mergeRequests[state.currentMergeRequestId];
} }
return null; return null;
......
...@@ -6,7 +6,7 @@ import { createCommitPayload, createNewMergeRequestUrl } from '../../utils'; ...@@ -6,7 +6,7 @@ import { createCommitPayload, createNewMergeRequestUrl } from '../../utils';
import router from '../../../ide_router'; import router from '../../../ide_router';
import service from '../../../services'; import service from '../../../services';
import * as types from './mutation_types'; import * as types from './mutation_types';
import * as consts from './constants'; import consts from './constants';
import { activityBarViews } from '../../../constants'; import { activityBarViews } from '../../../constants';
import eventHub from '../../../eventhub'; import eventHub from '../../../eventhub';
...@@ -18,16 +18,23 @@ export const discardDraft = ({ commit }) => { ...@@ -18,16 +18,23 @@ export const discardDraft = ({ commit }) => {
commit(types.UPDATE_COMMIT_MESSAGE, ''); commit(types.UPDATE_COMMIT_MESSAGE, '');
}; };
export const updateCommitAction = ({ commit }, commitAction) => { export const updateCommitAction = ({ commit, rootGetters }, commitAction) => {
commit(types.UPDATE_COMMIT_ACTION, commitAction); commit(types.UPDATE_COMMIT_ACTION, {
commitAction,
currentMergeRequest: rootGetters.currentMergeRequest,
});
};
export const toggleShouldCreateMR = ({ commit }) => {
commit(types.TOGGLE_SHOULD_CREATE_MR);
}; };
export const updateBranchName = ({ commit }, branchName) => { export const updateBranchName = ({ commit }, branchName) => {
commit(types.UPDATE_NEW_BRANCH_NAME, branchName); commit(types.UPDATE_NEW_BRANCH_NAME, branchName);
}; };
export const setLastCommitMessage = ({ rootState, commit }, data) => { export const setLastCommitMessage = ({ commit, rootGetters }, data) => {
const currentProject = rootState.projects[rootState.currentProjectId]; const { currentProject } = rootGetters;
const commitStats = data.stats const commitStats = data.stats
? sprintf(__('with %{additions} additions, %{deletions} deletions.'), { ? sprintf(__('with %{additions} additions, %{deletions} deletions.'), {
additions: data.stats.additions, additions: data.stats.additions,
...@@ -48,8 +55,8 @@ export const setLastCommitMessage = ({ rootState, commit }, data) => { ...@@ -48,8 +55,8 @@ export const setLastCommitMessage = ({ rootState, commit }, data) => {
commit(rootTypes.SET_LAST_COMMIT_MSG, commitMsg, { root: true }); commit(rootTypes.SET_LAST_COMMIT_MSG, commitMsg, { root: true });
}; };
export const updateFilesAfterCommit = ({ commit, dispatch, rootState }, { data }) => { export const updateFilesAfterCommit = ({ commit, dispatch, rootState, rootGetters }, { data }) => {
const selectedProject = rootState.projects[rootState.currentProjectId]; const selectedProject = rootGetters.currentProject;
const lastCommit = { const lastCommit = {
commit_path: `${selectedProject.web_url}/commit/${data.id}`, commit_path: `${selectedProject.web_url}/commit/${data.id}`,
commit: { commit: {
...@@ -135,14 +142,15 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo ...@@ -135,14 +142,15 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
branch: getters.branchName, branch: getters.branchName,
}) })
.then(() => { .then(() => {
if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR) { if (state.shouldCreateMR) {
const { currentProject } = rootGetters;
const targetBranch = getters.isCreatingNewBranch
? rootState.currentBranchId
: currentProject.default_branch;
dispatch( dispatch(
'redirectToUrl', 'redirectToUrl',
createNewMergeRequestUrl( createNewMergeRequestUrl(currentProject.web_url, getters.branchName, targetBranch),
rootState.projects[rootState.currentProjectId].web_url,
getters.branchName,
rootState.currentBranchId,
),
{ root: true }, { root: true },
); );
} }
......
export const COMMIT_TO_CURRENT_BRANCH = '1'; const COMMIT_TO_CURRENT_BRANCH = '1';
export const COMMIT_TO_NEW_BRANCH = '2'; const COMMIT_TO_NEW_BRANCH = '2';
export const COMMIT_TO_NEW_BRANCH_MR = '3';
export default {
COMMIT_TO_CURRENT_BRANCH,
COMMIT_TO_NEW_BRANCH,
};
import { sprintf, n__, __ } from '../../../../locale'; import { sprintf, n__, __ } from '../../../../locale';
import * as consts from './constants'; import consts from './constants';
const BRANCH_SUFFIX_COUNT = 5; const BRANCH_SUFFIX_COUNT = 5;
const createTranslatedTextForFiles = (files, text) => { const createTranslatedTextForFiles = (files, text) => {
...@@ -20,10 +20,7 @@ export const placeholderBranchName = (state, _, rootState) => ...@@ -20,10 +20,7 @@ export const placeholderBranchName = (state, _, rootState) =>
)}`; )}`;
export const branchName = (state, getters, rootState) => { export const branchName = (state, getters, rootState) => {
if ( if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH) {
state.commitAction === consts.COMMIT_TO_NEW_BRANCH ||
state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR
) {
if (state.newBranchName === '') { if (state.newBranchName === '') {
return getters.placeholderBranchName; return getters.placeholderBranchName;
} }
...@@ -49,5 +46,10 @@ export const preBuiltCommitMessage = (state, _, rootState) => { ...@@ -49,5 +46,10 @@ export const preBuiltCommitMessage = (state, _, rootState) => {
.join('\n'); .join('\n');
}; };
export const isCreatingNewBranch = state => state.commitAction === consts.COMMIT_TO_NEW_BRANCH;
export const shouldDisableNewMrOption = (state, _getters, _rootState, rootGetters) =>
rootGetters.currentMergeRequest && state.commitAction === consts.COMMIT_TO_CURRENT_BRANCH;
// prevent babel-plugin-rewire from generating an invalid default during karma tests // prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {}; export default () => {};
...@@ -2,3 +2,4 @@ export const UPDATE_COMMIT_MESSAGE = 'UPDATE_COMMIT_MESSAGE'; ...@@ -2,3 +2,4 @@ export const UPDATE_COMMIT_MESSAGE = 'UPDATE_COMMIT_MESSAGE';
export const UPDATE_COMMIT_ACTION = 'UPDATE_COMMIT_ACTION'; export const UPDATE_COMMIT_ACTION = 'UPDATE_COMMIT_ACTION';
export const UPDATE_NEW_BRANCH_NAME = 'UPDATE_NEW_BRANCH_NAME'; export const UPDATE_NEW_BRANCH_NAME = 'UPDATE_NEW_BRANCH_NAME';
export const UPDATE_LOADING = 'UPDATE_LOADING'; export const UPDATE_LOADING = 'UPDATE_LOADING';
export const TOGGLE_SHOULD_CREATE_MR = 'TOGGLE_SHOULD_CREATE_MR';
import * as types from './mutation_types'; import * as types from './mutation_types';
import consts from './constants';
export default { export default {
[types.UPDATE_COMMIT_MESSAGE](state, commitMessage) { [types.UPDATE_COMMIT_MESSAGE](state, commitMessage) {
...@@ -6,9 +7,13 @@ export default { ...@@ -6,9 +7,13 @@ export default {
commitMessage, commitMessage,
}); });
}, },
[types.UPDATE_COMMIT_ACTION](state, commitAction) { [types.UPDATE_COMMIT_ACTION](state, { commitAction, currentMergeRequest }) {
Object.assign(state, { Object.assign(state, {
commitAction, commitAction,
shouldCreateMR:
commitAction === consts.COMMIT_TO_CURRENT_BRANCH && currentMergeRequest
? false
: state.shouldCreateMR,
}); });
}, },
[types.UPDATE_NEW_BRANCH_NAME](state, newBranchName) { [types.UPDATE_NEW_BRANCH_NAME](state, newBranchName) {
...@@ -21,4 +26,9 @@ export default { ...@@ -21,4 +26,9 @@ export default {
submitCommitLoading, submitCommitLoading,
}); });
}, },
[types.TOGGLE_SHOULD_CREATE_MR](state) {
Object.assign(state, {
shouldCreateMR: !state.shouldCreateMR,
});
},
}; };
...@@ -3,4 +3,5 @@ export default () => ({ ...@@ -3,4 +3,5 @@ export default () => ({
commitAction: '1', commitAction: '1',
newBranchName: '', newBranchName: '',
submitCommitLoading: false, submitCommitLoading: false,
shouldCreateMR: false,
}); });
---
title: Create a shortcut for a new MR in the Web IDE
merge_request: 26792
author:
type: added
...@@ -2537,9 +2537,6 @@ msgstr "" ...@@ -2537,9 +2537,6 @@ msgstr ""
msgid "Create a new branch" msgid "Create a new branch"
msgstr "" msgstr ""
msgid "Create a new branch and merge request"
msgstr ""
msgid "Create a new issue" msgid "Create a new issue"
msgstr "" msgstr ""
...@@ -7717,6 +7714,9 @@ msgstr "" ...@@ -7717,6 +7714,9 @@ msgstr ""
msgid "Start a %{new_merge_request} with these changes" msgid "Start a %{new_merge_request} with these changes"
msgstr "" msgstr ""
msgid "Start a new merge request"
msgstr ""
msgid "Start and due date" msgid "Start and due date"
msgstr "" msgstr ""
...@@ -8391,9 +8391,6 @@ msgstr "" ...@@ -8391,9 +8391,6 @@ msgstr ""
msgid "This option is disabled as you don't have write permissions for the current branch" msgid "This option is disabled as you don't have write permissions for the current branch"
msgstr "" msgstr ""
msgid "This option is disabled while you still have unstaged changes"
msgstr ""
msgid "This page is unavailable because you are not allowed to read information across multiple projects." msgid "This page is unavailable because you are not allowed to read information across multiple projects."
msgstr "" msgstr ""
......
...@@ -18,7 +18,7 @@ describe('IDE commit module mutations', () => { ...@@ -18,7 +18,7 @@ describe('IDE commit module mutations', () => {
describe('UPDATE_COMMIT_ACTION', () => { describe('UPDATE_COMMIT_ACTION', () => {
it('updates commitAction', () => { it('updates commitAction', () => {
mutations.UPDATE_COMMIT_ACTION(state, 'testing'); mutations.UPDATE_COMMIT_ACTION(state, { commitAction: 'testing' });
expect(state.commitAction).toBe('testing'); expect(state.commitAction).toBe('testing');
}); });
...@@ -39,4 +39,20 @@ describe('IDE commit module mutations', () => { ...@@ -39,4 +39,20 @@ describe('IDE commit module mutations', () => {
expect(state.submitCommitLoading).toBeTruthy(); expect(state.submitCommitLoading).toBeTruthy();
}); });
}); });
describe('TOGGLE_SHOULD_CREATE_MR', () => {
it('changes shouldCreateMR to true when initial state is false', () => {
state.shouldCreateMR = false;
mutations.TOGGLE_SHOULD_CREATE_MR(state);
expect(state.shouldCreateMR).toBe(true);
});
it('changes shouldCreateMR to false when initial state is true', () => {
state.shouldCreateMR = true;
mutations.TOGGLE_SHOULD_CREATE_MR(state);
expect(state.shouldCreateMR).toBe(false);
});
});
}); });
import Vue from 'vue'; import Vue from 'vue';
import store from '~/ide/stores'; import store from '~/ide/stores';
import consts from '~/ide/stores/modules/commit/constants';
import commitActions from '~/ide/components/commit_sidebar/actions.vue'; import commitActions from '~/ide/components/commit_sidebar/actions.vue';
import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper'; import { createComponentWithStore } from 'spec/helpers/vue_mount_component_helper';
import { resetStore } from 'spec/ide/helpers'; import { resetStore } from 'spec/ide/helpers';
...@@ -7,20 +8,33 @@ import { projectData } from 'spec/ide/mock_data'; ...@@ -7,20 +8,33 @@ import { projectData } from 'spec/ide/mock_data';
describe('IDE commit sidebar actions', () => { describe('IDE commit sidebar actions', () => {
let vm; let vm;
const createComponent = ({
beforeEach(done => { hasMR = false,
commitAction = consts.COMMIT_TO_NEW_BRANCH,
mergeRequestsEnabled = true,
currentBranchId = 'master',
shouldCreateMR = false,
} = {}) => {
const Component = Vue.extend(commitActions); const Component = Vue.extend(commitActions);
vm = createComponentWithStore(Component, store); vm = createComponentWithStore(Component, store);
vm.$store.state.currentBranchId = 'master'; vm.$store.state.currentBranchId = currentBranchId;
vm.$store.state.currentProjectId = 'abcproject'; vm.$store.state.currentProjectId = 'abcproject';
vm.$store.state.commit.commitAction = commitAction;
Vue.set(vm.$store.state.projects, 'abcproject', { ...projectData }); Vue.set(vm.$store.state.projects, 'abcproject', { ...projectData });
vm.$store.state.projects.abcproject.merge_requests_enabled = mergeRequestsEnabled;
vm.$store.state.commit.shouldCreateMR = shouldCreateMR;
vm.$mount(); if (hasMR) {
vm.$store.state.currentMergeRequestId = '1';
vm.$store.state.projects[store.state.currentProjectId].mergeRequests[
store.state.currentMergeRequestId
] = { foo: 'bar' };
}
Vue.nextTick(done); return vm.$mount();
}); };
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.$destroy();
...@@ -28,16 +42,20 @@ describe('IDE commit sidebar actions', () => { ...@@ -28,16 +42,20 @@ describe('IDE commit sidebar actions', () => {
resetStore(vm.$store); resetStore(vm.$store);
}); });
it('renders 3 groups', () => { it('renders 2 groups', () => {
expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(3); createComponent();
expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2);
}); });
it('renders current branch text', () => { it('renders current branch text', () => {
createComponent();
expect(vm.$el.textContent).toContain('Commit to master branch'); expect(vm.$el.textContent).toContain('Commit to master branch');
}); });
it('hides merge request option when project merge requests are disabled', done => { it('hides merge request option when project merge requests are disabled', done => {
vm.$store.state.projects.abcproject.merge_requests_enabled = false; createComponent({ mergeRequestsEnabled: false });
vm.$nextTick(() => { vm.$nextTick(() => {
expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2); expect(vm.$el.querySelectorAll('input[type="radio"]').length).toBe(2);
...@@ -49,9 +67,53 @@ describe('IDE commit sidebar actions', () => { ...@@ -49,9 +67,53 @@ describe('IDE commit sidebar actions', () => {
describe('commitToCurrentBranchText', () => { describe('commitToCurrentBranchText', () => {
it('escapes current branch', () => { it('escapes current branch', () => {
vm.$store.state.currentBranchId = '<img src="x" />'; const injectedSrc = '<img src="x" />';
createComponent({ currentBranchId: injectedSrc });
expect(vm.commitToCurrentBranchText).not.toContain(injectedSrc);
});
});
describe('create new MR checkbox', () => {
it('disables `createMR` button when an MR already exists and committing to current branch', () => {
createComponent({ hasMR: true, commitAction: consts.COMMIT_TO_CURRENT_BRANCH });
expect(vm.$el.querySelector('input[type="checkbox"]').disabled).toBe(true);
});
it('does not disable checkbox if MR does not exist', () => {
createComponent({ hasMR: false });
expect(vm.$el.querySelector('input[type="checkbox"]').disabled).toBe(false);
});
it('does not disable checkbox when creating a new branch', () => {
createComponent({ commitAction: consts.COMMIT_TO_NEW_BRANCH });
expect(vm.$el.querySelector('input[type="checkbox"]').disabled).toBe(false);
});
it('toggles off new MR when switching back to commit to current branch and MR exists', () => {
createComponent({
commitAction: consts.COMMIT_TO_NEW_BRANCH,
shouldCreateMR: true,
});
const currentBranchRadio = vm.$el.querySelector(
`input[value="${consts.COMMIT_TO_CURRENT_BRANCH}"`,
);
currentBranchRadio.click();
vm.$nextTick(() => {
expect(vm.$store.state.commit.shouldCreateMR).toBe(false);
});
});
it('toggles `shouldCreateMR` when clicking checkbox', () => {
createComponent();
const el = vm.$el.querySelector('input[type="checkbox"]');
el.dispatchEvent(new Event('change'));
expect(vm.commitToCurrentBranchText).not.toContain('<img src="x" />'); expect(vm.$store.state.commit.shouldCreateMR).toBe(true);
}); });
}); });
}); });
...@@ -3,7 +3,7 @@ import store from '~/ide/stores'; ...@@ -3,7 +3,7 @@ import store 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';
import eventHub from '~/ide/eventhub'; import eventHub from '~/ide/eventhub';
import * as consts from '~/ide/stores/modules/commit/constants'; import consts from '~/ide/stores/modules/commit/constants';
import { resetStore, file } from 'spec/ide/helpers'; import { resetStore, file } from 'spec/ide/helpers';
describe('IDE commit module actions', () => { describe('IDE commit module actions', () => {
...@@ -389,7 +389,8 @@ describe('IDE commit module actions', () => { ...@@ -389,7 +389,8 @@ describe('IDE commit module actions', () => {
it('redirects to new merge request page', done => { it('redirects to new merge request page', done => {
spyOn(eventHub, '$on'); spyOn(eventHub, '$on');
store.state.commit.commitAction = '3'; store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store.state.commit.shouldCreateMR = true;
store store
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
...@@ -405,6 +406,21 @@ describe('IDE commit module actions', () => { ...@@ -405,6 +406,21 @@ describe('IDE commit module actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('does not redirect to new merge request page when shouldCreateMR is not checked', done => {
spyOn(eventHub, '$on');
store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH;
store.state.commit.shouldCreateMR = false;
store
.dispatch('commit/commitChanges')
.then(() => {
expect(visitUrl).not.toHaveBeenCalled();
done();
})
.catch(done.fail);
});
it('resets changed files before redirecting', done => { it('resets changed files before redirecting', done => {
spyOn(eventHub, '$on'); spyOn(eventHub, '$on');
......
import commitState from '~/ide/stores/modules/commit/state'; import commitState from '~/ide/stores/modules/commit/state';
import * as consts from '~/ide/stores/modules/commit/constants'; import consts from '~/ide/stores/modules/commit/constants';
import * as getters from '~/ide/stores/modules/commit/getters'; import * as getters from '~/ide/stores/modules/commit/getters';
describe('IDE commit module getters', () => { describe('IDE commit module getters', () => {
...@@ -46,7 +46,7 @@ describe('IDE commit module getters', () => { ...@@ -46,7 +46,7 @@ describe('IDE commit module getters', () => {
currentBranchId: 'master', currentBranchId: 'master',
}; };
const localGetters = { const localGetters = {
placeholderBranchName: 'newBranchName', placeholderBranchName: 'placeholder-branch-name',
}; };
beforeEach(() => { beforeEach(() => {
...@@ -59,25 +59,28 @@ describe('IDE commit module getters', () => { ...@@ -59,25 +59,28 @@ describe('IDE commit module getters', () => {
expect(getters.branchName(state, null, rootState)).toBe('master'); expect(getters.branchName(state, null, rootState)).toBe('master');
}); });
['COMMIT_TO_NEW_BRANCH', 'COMMIT_TO_NEW_BRANCH_MR'].forEach(type => { describe('COMMIT_TO_NEW_BRANCH', () => {
describe(type, () => { beforeEach(() => {
beforeEach(() => { Object.assign(state, {
Object.assign(state, { commitAction: consts.COMMIT_TO_NEW_BRANCH,
commitAction: consts[type],
});
}); });
});
it('uses newBranchName when not empty', () => { it('uses newBranchName when not empty', () => {
expect(getters.branchName(state, localGetters, rootState)).toBe('state-newBranchName'); const newBranchName = 'nonempty-branch-name';
Object.assign(state, {
newBranchName,
}); });
it('uses placeholderBranchName when state newBranchName is empty', () => { expect(getters.branchName(state, localGetters, rootState)).toBe(newBranchName);
Object.assign(state, { });
newBranchName: '',
});
expect(getters.branchName(state, localGetters, rootState)).toBe('newBranchName'); it('uses placeholderBranchName when state newBranchName is empty', () => {
Object.assign(state, {
newBranchName: '',
}); });
expect(getters.branchName(state, localGetters, rootState)).toBe('placeholder-branch-name');
}); });
}); });
}); });
...@@ -141,4 +144,33 @@ describe('IDE commit module getters', () => { ...@@ -141,4 +144,33 @@ describe('IDE commit module getters', () => {
}); });
}); });
}); });
describe('shouldDisableNewMrOption', () => {
it('returns false if commitAction `COMMIT_TO_NEW_BRANCH`', () => {
state.commitAction = consts.COMMIT_TO_NEW_BRANCH;
const rootState = {
currentMergeRequest: { foo: 'bar' },
};
expect(getters.shouldDisableNewMrOption(state, null, null, rootState)).toBeFalsy();
});
it('returns false if there is no current merge request', () => {
state.commitAction = consts.COMMIT_TO_CURRENT_BRANCH;
const rootState = {
currentMergeRequest: null,
};
expect(getters.shouldDisableNewMrOption(state, null, null, rootState)).toBeFalsy();
});
it('returns true an MR exists and commit action is `COMMIT_TO_CURRENT_BRANCH`', () => {
state.commitAction = consts.COMMIT_TO_CURRENT_BRANCH;
const rootState = {
currentMergeRequest: { foo: 'bar' },
};
expect(getters.shouldDisableNewMrOption(state, null, null, rootState)).toBeTruthy();
});
});
}); });
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