diff options
Diffstat (limited to 'spec/javascripts/ide/stores/modules/commit/actions_spec.js')
-rw-r--r-- | spec/javascripts/ide/stores/modules/commit/actions_spec.js | 157 |
1 files changed, 155 insertions, 2 deletions
diff --git a/spec/javascripts/ide/stores/modules/commit/actions_spec.js b/spec/javascripts/ide/stores/modules/commit/actions_spec.js index 4413a12fac4..5f7272311c8 100644 --- a/spec/javascripts/ide/stores/modules/commit/actions_spec.js +++ b/spec/javascripts/ide/stores/modules/commit/actions_spec.js @@ -1,9 +1,12 @@ -import actions from '~/ide/stores/actions'; +import rootActions from '~/ide/stores/actions'; import store from '~/ide/stores'; import service from '~/ide/services'; import router from '~/ide/ide_router'; import eventHub from '~/ide/eventhub'; import consts from '~/ide/stores/modules/commit/constants'; +import * as mutationTypes from '~/ide/stores/modules/commit/mutation_types'; +import * as actions from '~/ide/stores/modules/commit/actions'; +import testAction from '../../../../helpers/vuex_action_helper'; import { commitActionTypes } from '~/ide/constants'; import { resetStore, file } from 'spec/ide/helpers'; @@ -225,7 +228,7 @@ describe('IDE commit module actions', () => { let visitUrl; beforeEach(() => { - visitUrl = spyOnDependency(actions, 'visitUrl'); + visitUrl = spyOnDependency(rootActions, 'visitUrl'); document.body.innerHTML += '<div class="flash-container"></div>'; @@ -523,4 +526,154 @@ describe('IDE commit module actions', () => { }); }); }); + + describe('toggleShouldCreateMR', () => { + it('commits both toggle and interacting with MR checkbox actions', done => { + testAction( + actions.toggleShouldCreateMR, + {}, + store.state, + [ + { type: mutationTypes.TOGGLE_SHOULD_CREATE_MR }, + { type: mutationTypes.INTERACT_WITH_NEW_MR }, + ], + [], + done, + ); + }); + }); + + describe('setShouldCreateMR', () => { + beforeEach(() => { + store.state.projects = { + project: { + default_branch: 'master', + branches: { + master: { + name: 'master', + }, + feature: { + name: 'feature', + }, + }, + }, + }; + + store.state.currentProjectId = 'project'; + }); + + it('sets to false when the current branch already has an MR', done => { + store.state.commit.currentMergeRequestId = 1; + store.state.commit.commitAction = consts.COMMIT_TO_CURRENT_BRANCH; + store.state.currentMergeRequestId = '1'; + store.state.currentBranchId = 'feature'; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit.calls.allArgs()[0]).toEqual( + jasmine.arrayContaining([`commit/${mutationTypes.TOGGLE_SHOULD_CREATE_MR}`, false]), + ); + done(); + }) + .catch(done.fail); + }); + + it('changes to false when current branch is the default branch and user has not interacted', done => { + store.state.commit.interactedWithNewMR = false; + store.state.currentBranchId = 'master'; + store.state.commit.commitAction = consts.COMMIT_TO_CURRENT_BRANCH; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit.calls.allArgs()[0]).toEqual( + jasmine.arrayContaining([`commit/${mutationTypes.TOGGLE_SHOULD_CREATE_MR}`, false]), + ); + done(); + }) + .catch(done.fail); + }); + + it('changes to true when "create new branch" is selected and user has not interacted', done => { + store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; + store.state.commit.interactedWithNewMR = false; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit.calls.allArgs()[0]).toEqual( + jasmine.arrayContaining([`commit/${mutationTypes.TOGGLE_SHOULD_CREATE_MR}`, true]), + ); + done(); + }) + .catch(done.fail); + }); + + it('does not change anything if user has interacted and comitting to new branch', done => { + store.state.commit.commitAction = consts.COMMIT_TO_NEW_BRANCH; + store.state.commit.interactedWithNewMR = true; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit).not.toHaveBeenCalled(); + done(); + }) + .catch(done.fail); + }); + + it('does not change anything if user has interacted and comitting to branch without MR', done => { + store.state.commit.commitAction = consts.COMMIT_TO_CURRENT_BRANCH; + store.state.commit.currentMergeRequestId = null; + store.state.commit.interactedWithNewMR = true; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit).not.toHaveBeenCalled(); + done(); + }) + .catch(done.fail); + }); + + it('still changes to false if hiding the checkbox', done => { + store.state.currentBranchId = 'feature'; + store.state.commit.commitAction = consts.COMMIT_TO_CURRENT_BRANCH; + store.state.currentMergeRequestId = '1'; + store.state.commit.interactedWithNewMR = true; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit.calls.allArgs()[0]).toEqual( + jasmine.arrayContaining([`commit/${mutationTypes.TOGGLE_SHOULD_CREATE_MR}`, false]), + ); + done(); + }) + .catch(done.fail); + }); + + it('does not change to false when on master and user has interacted even if MR exists', done => { + store.state.currentBranchId = 'master'; + store.state.commit.commitAction = consts.COMMIT_TO_CURRENT_BRANCH; + store.state.currentMergeRequestId = '1'; + store.state.commit.interactedWithNewMR = true; + spyOn(store, 'commit').and.callThrough(); + + store + .dispatch('commit/setShouldCreateMR') + .then(() => { + expect(store.commit).not.toHaveBeenCalled(); + done(); + }) + .catch(done.fail); + }); + }); }); |