Commit 84e550fa authored by Nathan Friend's avatar Nathan Friend Committed by Shinya Maeda

Fix frontend tests related to autoMergeStrategy

A few minor frontend changes to complete the refactoring
from MWPS to the more generic autoMergeStrategy.
parent d4b46936
...@@ -31,7 +31,7 @@ export default { ...@@ -31,7 +31,7 @@ export default {
return { return {
removeSourceBranch: this.mr.shouldRemoveSourceBranch, removeSourceBranch: this.mr.shouldRemoveSourceBranch,
mergeWhenBuildSucceeds: false, mergeWhenBuildSucceeds: false,
autoMergeStrategy: null, autoMergeStrategy: undefined,
isMakingRequest: false, isMakingRequest: false,
isMergingImmediately: false, isMergingImmediately: false,
commitMessage: this.mr.commitMessage, commitMessage: this.mr.commitMessage,
...@@ -126,11 +126,7 @@ export default { ...@@ -126,11 +126,7 @@ export default {
this.isMergingImmediately = true; this.isMergingImmediately = true;
} }
if (mergeWhenBuildSucceeds === true) { this.autoMergeStrategy = mergeWhenBuildSucceeds ? 'merge_when_pipeline_succeeds' : undefined;
this.autoMergeStrategy = 'merge_when_pipeline_succeeds'
} else {
this.autoMergeStrategy = null
}
const options = { const options = {
sha: this.mr.sha, sha: this.mr.sha,
......
...@@ -24,7 +24,7 @@ export default function deviseState(data) { ...@@ -24,7 +24,7 @@ export default function deviseState(data) {
} else if (this.isSHAMismatch) { } else if (this.isSHAMismatch) {
return stateKey.shaMismatch; return stateKey.shaMismatch;
} else if (this.autoMergeEnabled) { } else if (this.autoMergeEnabled) {
return this.mergeError ? stateKey.autoMergeFailed : stateKey.mergeWhenPipelineSucceeds; return this.mergeError ? stateKey.autoMergeFailed : stateKey.autoMergeEnabled;
} else if (!this.canMerge) { } else if (!this.canMerge) {
return stateKey.notAllowedToMerge; return stateKey.notAllowedToMerge;
} else if (this.canBeMerged) { } else if (this.canBeMerged) {
......
...@@ -75,7 +75,7 @@ export default class MergeRequestStore { ...@@ -75,7 +75,7 @@ export default class MergeRequestStore {
this.sourceBranchRemoved = !data.source_branch_exists; this.sourceBranchRemoved = !data.source_branch_exists;
this.shouldRemoveSourceBranch = data.remove_source_branch || false; this.shouldRemoveSourceBranch = data.remove_source_branch || false;
this.onlyAllowMergeIfPipelineSucceeds = data.only_allow_merge_if_pipeline_succeeds || false; this.onlyAllowMergeIfPipelineSucceeds = data.only_allow_merge_if_pipeline_succeeds || false;
this.autoMergeEnabled = data.auto_merge_enabled || false; this.autoMergeEnabled = Boolean(data.auto_merge_enabled);
this.autoMergeStrategy = data.auto_merge_strategy; this.autoMergeStrategy = data.auto_merge_strategy;
this.mergePath = data.merge_path; this.mergePath = data.merge_path;
this.ffOnlyEnabled = data.ff_only_enabled; this.ffOnlyEnabled = data.ff_only_enabled;
......
...@@ -13,7 +13,7 @@ const stateToComponentMap = { ...@@ -13,7 +13,7 @@ const stateToComponentMap = {
unresolvedDiscussions: 'mr-widget-unresolved-discussions', unresolvedDiscussions: 'mr-widget-unresolved-discussions',
pipelineBlocked: 'mr-widget-pipeline-blocked', pipelineBlocked: 'mr-widget-pipeline-blocked',
pipelineFailed: 'mr-widget-pipeline-failed', pipelineFailed: 'mr-widget-pipeline-failed',
mergeWhenPipelineSucceeds: 'mr-widget-merge-when-pipeline-succeeds', autoMergeEnabled: 'mr-widget-merge-when-pipeline-succeeds',
failedToMerge: 'mr-widget-failed-to-merge', failedToMerge: 'mr-widget-failed-to-merge',
autoMergeFailed: 'mr-widget-auto-merge-failed', autoMergeFailed: 'mr-widget-auto-merge-failed',
shaMismatch: 'sha-mismatch', shaMismatch: 'sha-mismatch',
...@@ -45,7 +45,7 @@ export const stateKey = { ...@@ -45,7 +45,7 @@ export const stateKey = {
pipelineBlocked: 'pipelineBlocked', pipelineBlocked: 'pipelineBlocked',
shaMismatch: 'shaMismatch', shaMismatch: 'shaMismatch',
autoMergeFailed: 'autoMergeFailed', autoMergeFailed: 'autoMergeFailed',
mergeWhenPipelineSucceeds: 'mergeWhenPipelineSucceeds', autoMergeEnabled: 'autoMergeEnabled',
notAllowedToMerge: 'notAllowedToMerge', notAllowedToMerge: 'notAllowedToMerge',
readyToMerge: 'readyToMerge', readyToMerge: 'readyToMerge',
rebase: 'rebase', rebase: 'rebase',
......
...@@ -4,7 +4,7 @@ describe('getStateKey', () => { ...@@ -4,7 +4,7 @@ describe('getStateKey', () => {
it('should return proper state name', () => { it('should return proper state name', () => {
const context = { const context = {
mergeStatus: 'checked', mergeStatus: 'checked',
mergeWhenPipelineSucceeds: false, autoMergeEnabled: false,
canMerge: true, canMerge: true,
onlyAllowMergeIfPipelineSucceeds: false, onlyAllowMergeIfPipelineSucceeds: false,
isPipelineFailed: false, isPipelineFailed: false,
...@@ -33,7 +33,7 @@ describe('getStateKey', () => { ...@@ -33,7 +33,7 @@ describe('getStateKey', () => {
context.autoMergeEnabled = true; context.autoMergeEnabled = true;
expect(bound()).toEqual('mergeWhenPipelineSucceeds'); expect(bound()).toEqual('autoMergeEnabled');
context.isSHAMismatch = true; context.isSHAMismatch = true;
...@@ -80,7 +80,7 @@ describe('getStateKey', () => { ...@@ -80,7 +80,7 @@ describe('getStateKey', () => {
it('returns rebased state key', () => { it('returns rebased state key', () => {
const context = { const context = {
mergeStatus: 'checked', mergeStatus: 'checked',
mergeWhenPipelineSucceeds: false, autoMergeEnabled: false,
canMerge: true, canMerge: true,
onlyAllowMergeIfPipelineSucceeds: true, onlyAllowMergeIfPipelineSucceeds: true,
isPipelineFailed: true, isPipelineFailed: true,
......
...@@ -21,7 +21,7 @@ describe('MRWidgetMergeWhenPipelineSucceeds', () => { ...@@ -21,7 +21,7 @@ describe('MRWidgetMergeWhenPipelineSucceeds', () => {
canCancelAutomaticMerge: true, canCancelAutomaticMerge: true,
mergeUserId: 1, mergeUserId: 1,
currentUserId: 1, currentUserId: 1,
setToMWPSBy: {}, setToAutoMergeBy: {},
sha, sha,
targetBranchPath, targetBranchPath,
targetBranch, targetBranch,
...@@ -106,7 +106,7 @@ describe('MRWidgetMergeWhenPipelineSucceeds', () => { ...@@ -106,7 +106,7 @@ describe('MRWidgetMergeWhenPipelineSucceeds', () => {
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested'); expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
expect(vm.service.merge).toHaveBeenCalledWith({ expect(vm.service.merge).toHaveBeenCalledWith({
sha, sha,
merge_when_pipeline_succeeds: true, auto_merge_strategy: 'merge_when_pipeline_succeeds',
should_remove_source_branch: true, should_remove_source_branch: true,
}); });
done(); done();
......
...@@ -80,7 +80,7 @@ describe('ReadyToMerge', () => { ...@@ -80,7 +80,7 @@ describe('ReadyToMerge', () => {
it('should have default data', () => { it('should have default data', () => {
expect(vm.mergeWhenBuildSucceeds).toBeFalsy(); expect(vm.mergeWhenBuildSucceeds).toBeFalsy();
expect(vm.useCommitMessageWithDescription).toBeFalsy(); expect(vm.useCommitMessageWithDescription).toBeFalsy();
expect(vm.setToAutoMerge).toBeFalsy(); expect(vm.autoMergeStrategy).toBeUndefined();
expect(vm.showCommitMessageEditor).toBeFalsy(); expect(vm.showCommitMessageEditor).toBeFalsy();
expect(vm.isMakingRequest).toBeFalsy(); expect(vm.isMakingRequest).toBeFalsy();
expect(vm.isMergingImmediately).toBeFalsy(); expect(vm.isMergingImmediately).toBeFalsy();
...@@ -325,16 +325,20 @@ describe('ReadyToMerge', () => { ...@@ -325,16 +325,20 @@ describe('ReadyToMerge', () => {
vm.handleMergeButtonClick(true); vm.handleMergeButtonClick(true);
setTimeout(() => { setTimeout(() => {
expect(vm.setToAutoMerge).toBeTruthy(); expect(vm.autoMergeStrategy).toBe('merge_when_pipeline_succeeds');
expect(vm.isMakingRequest).toBeTruthy(); expect(vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested'); expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
const params = vm.service.merge.calls.argsFor(0)[0]; const params = vm.service.merge.calls.argsFor(0)[0];
expect(params.sha).toEqual(vm.mr.sha); expect(params).toEqual(
expect(params.commit_message).toEqual(vm.mr.commitMessage); jasmine.objectContaining({
expect(params.should_remove_source_branch).toBeFalsy(); sha: vm.mr.sha,
expect(params.merge_when_pipeline_succeeds).toBeTruthy(); commit_message: vm.mr.commitMessage,
should_remove_source_branch: false,
auto_merge_strategy: 'merge_when_pipeline_succeeds',
}),
);
done(); done();
}, 333); }, 333);
}); });
...@@ -345,7 +349,7 @@ describe('ReadyToMerge', () => { ...@@ -345,7 +349,7 @@ describe('ReadyToMerge', () => {
vm.handleMergeButtonClick(false, true); vm.handleMergeButtonClick(false, true);
setTimeout(() => { setTimeout(() => {
expect(vm.setToAutoMerge).toBeFalsy(); expect(vm.autoMergeStrategy).toBeUndefined();
expect(vm.isMakingRequest).toBeTruthy(); expect(vm.isMakingRequest).toBeTruthy();
expect(eventHub.$emit).toHaveBeenCalledWith('FailedToMerge', undefined); expect(eventHub.$emit).toHaveBeenCalledWith('FailedToMerge', undefined);
...@@ -363,7 +367,7 @@ describe('ReadyToMerge', () => { ...@@ -363,7 +367,7 @@ describe('ReadyToMerge', () => {
vm.handleMergeButtonClick(); vm.handleMergeButtonClick();
setTimeout(() => { setTimeout(() => {
expect(vm.setToAutoMerge).toBeFalsy(); expect(vm.autoMergeStrategy).toBeUndefined();
expect(vm.isMakingRequest).toBeTruthy(); expect(vm.isMakingRequest).toBeTruthy();
expect(vm.initiateMergePolling).toHaveBeenCalled(); expect(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