Commit 61d6439d authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'ph/fixAutoMergeStateTransition' into 'master'

Fixed MWPS button showing merging state

See merge request gitlab-org/gitlab!71804
parents 6ee8e278 d64a2d87
...@@ -49,7 +49,7 @@ const MERGE_SUCCESS_STATUS = 'success'; ...@@ -49,7 +49,7 @@ const MERGE_SUCCESS_STATUS = 'success';
const MERGE_HOOK_VALIDATION_ERROR_STATUS = 'hook_validation_error'; const MERGE_HOOK_VALIDATION_ERROR_STATUS = 'hook_validation_error';
const { transitions } = STATE_MACHINE; const { transitions } = STATE_MACHINE;
const { MERGE, MERGED, MERGE_FAILURE } = transitions; const { MERGE, MERGED, MERGE_FAILURE, AUTO_MERGE } = transitions;
export default { export default {
name: 'ReadyToMerge', name: 'ReadyToMerge',
...@@ -365,7 +365,11 @@ export default { ...@@ -365,7 +365,11 @@ export default {
} }
this.isMakingRequest = true; this.isMakingRequest = true;
this.mr.transitionStateMachine({ transition: MERGE });
if (!useAutoMerge) {
this.mr.transitionStateMachine({ transition: MERGE });
}
this.service this.service
.merge(options) .merge(options)
.then((res) => res.data) .then((res) => res.data)
...@@ -376,6 +380,7 @@ export default { ...@@ -376,6 +380,7 @@ export default {
if (AUTO_MERGE_STRATEGIES.includes(data.status)) { if (AUTO_MERGE_STRATEGIES.includes(data.status)) {
eventHub.$emit('MRWidgetUpdateRequested'); eventHub.$emit('MRWidgetUpdateRequested');
this.mr.transitionStateMachine({ transition: AUTO_MERGE });
} else if (data.status === MERGE_SUCCESS_STATUS) { } else if (data.status === MERGE_SUCCESS_STATUS) {
this.initiateMergePolling(); this.initiateMergePolling();
} else if (hasError) { } else if (hasError) {
......
...@@ -58,9 +58,11 @@ const STATE_MACHINE = { ...@@ -58,9 +58,11 @@ const STATE_MACHINE = {
states: { states: {
IDLE: 'IDLE', IDLE: 'IDLE',
MERGING: 'MERGING', MERGING: 'MERGING',
AUTO_MERGE: 'AUTO_MERGE',
}, },
transitions: { transitions: {
MERGE: 'start-merge', MERGE: 'start-merge',
AUTO_MERGE: 'start-auto-merge',
MERGE_FAILURE: 'merge-failed', MERGE_FAILURE: 'merge-failed',
MERGED: 'merge-done', MERGED: 'merge-done',
}, },
...@@ -73,6 +75,7 @@ STATE_MACHINE.definition = { ...@@ -73,6 +75,7 @@ STATE_MACHINE.definition = {
[states.IDLE]: { [states.IDLE]: {
on: { on: {
[transitions.MERGE]: states.MERGING, [transitions.MERGE]: states.MERGING,
[transitions.AUTO_MERGE]: states.AUTO_MERGE,
}, },
}, },
[states.MERGING]: { [states.MERGING]: {
...@@ -81,15 +84,23 @@ STATE_MACHINE.definition = { ...@@ -81,15 +84,23 @@ STATE_MACHINE.definition = {
[transitions.MERGE_FAILURE]: states.IDLE, [transitions.MERGE_FAILURE]: states.IDLE,
}, },
}, },
[states.AUTO_MERGE]: {
on: {
[transitions.MERGED]: states.IDLE,
[transitions.MERGE_FAILURE]: states.IDLE,
},
},
}, },
}; };
export const stateToTransitionMap = { export const stateToTransitionMap = {
[stateKey.merging]: transitions.MERGE, [stateKey.merging]: transitions.MERGE,
[stateKey.merged]: transitions.MERGED, [stateKey.merged]: transitions.MERGED,
[stateKey.autoMergeEnabled]: transitions.AUTO_MERGE,
}; };
export const stateToComponentMap = { export const stateToComponentMap = {
[states.MERGING]: classStateMap[stateKey.merging], [states.MERGING]: classStateMap[stateKey.merging],
[states.AUTO_MERGE]: classStateMap[stateKey.autoMergeEnabled],
}; };
export const EXTENSION_ICONS = { export const EXTENSION_ICONS = {
......
...@@ -79,6 +79,7 @@ RSpec.describe 'User adds to merge train when pipeline succeeds', :js do ...@@ -79,6 +79,7 @@ RSpec.describe 'User adds to merge train when pipeline succeeds', :js do
context "when user clicks 'Delete source branch" do context "when user clicks 'Delete source branch" do
before do before do
wait_for_requests
click_button 'Delete source branch' click_button 'Delete source branch'
end end
......
...@@ -45,7 +45,7 @@ const createTestMr = (customConfig) => { ...@@ -45,7 +45,7 @@ const createTestMr = (customConfig) => {
preferredAutoMergeStrategy: MWPS_MERGE_STRATEGY, preferredAutoMergeStrategy: MWPS_MERGE_STRATEGY,
availableAutoMergeStrategies: [MWPS_MERGE_STRATEGY], availableAutoMergeStrategies: [MWPS_MERGE_STRATEGY],
mergeImmediatelyDocsPath: 'path/to/merge/immediately/docs', mergeImmediatelyDocsPath: 'path/to/merge/immediately/docs',
transitionStateMachine: () => eventHub.$emit('StateMachineValueChanged', { value: 'value' }), transitionStateMachine: (transition) => eventHub.$emit('StateMachineValueChanged', transition),
translateStateToMachine: () => this.transitionStateMachine(), translateStateToMachine: () => this.transitionStateMachine(),
}; };
...@@ -306,6 +306,9 @@ describe('ReadyToMerge', () => { ...@@ -306,6 +306,9 @@ describe('ReadyToMerge', () => {
setImmediate(() => { setImmediate(() => {
expect(wrapper.vm.isMakingRequest).toBeTruthy(); expect(wrapper.vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested'); expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
expect(eventHub.$emit).toHaveBeenCalledWith('StateMachineValueChanged', {
transition: 'start-auto-merge',
});
const params = wrapper.vm.service.merge.mock.calls[0][0]; const params = wrapper.vm.service.merge.mock.calls[0][0];
...@@ -343,10 +346,15 @@ describe('ReadyToMerge', () => { ...@@ -343,10 +346,15 @@ describe('ReadyToMerge', () => {
it('should handle merge action accepted case', (done) => { it('should handle merge action accepted case', (done) => {
createComponent(); createComponent();
jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
jest.spyOn(wrapper.vm.service, 'merge').mockReturnValue(returnPromise('success')); jest.spyOn(wrapper.vm.service, 'merge').mockReturnValue(returnPromise('success'));
jest.spyOn(wrapper.vm, 'initiateMergePolling').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'initiateMergePolling').mockImplementation(() => {});
wrapper.vm.handleMergeButtonClick(); wrapper.vm.handleMergeButtonClick();
expect(eventHub.$emit).toHaveBeenCalledWith('StateMachineValueChanged', {
transition: 'start-merge',
});
setImmediate(() => { setImmediate(() => {
expect(wrapper.vm.isMakingRequest).toBeTruthy(); expect(wrapper.vm.isMakingRequest).toBeTruthy();
expect(wrapper.vm.initiateMergePolling).toHaveBeenCalled(); expect(wrapper.vm.initiateMergePolling).toHaveBeenCalled();
......
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