Commit a4676855 authored by Phil Hughes's avatar Phil Hughes

Merge branch '4304-fix-successful-rebase' into 'master'

Fix successful rebase throwing flash error message

Closes #4304

See merge request gitlab-org/gitlab-ee!3727
parents 8218713e 8498f4fa
---
title: Fix successful rebase throwing flash error message
merge_request: 3727
author:
type: fixed
...@@ -50,7 +50,15 @@ ...@@ -50,7 +50,15 @@
this.service.rebase() this.service.rebase()
.then(() => { .then(() => {
simplePoll((continuePolling, stopPolling) => { simplePoll(this.checkRebaseStatus);
})
.catch((error) => {
this.rebasingError = error.merge_error;
this.isMakingRequest = false;
Flash('Something went wrong. Please try again.');
});
},
checkRebaseStatus(continuePolling, stopPolling) {
this.service.poll() this.service.poll()
.then(res => res.json()) .then(res => res.json())
.then((res) => { .then((res) => {
...@@ -59,7 +67,7 @@ ...@@ -59,7 +67,7 @@
} else { } else {
this.isMakingRequest = false; this.isMakingRequest = false;
if (res.merge_error.length) { if (res.merge_error && res.merge_error.length) {
this.rebasingError = res.merge_error; this.rebasingError = res.merge_error;
Flash('Something went wrong. Please try again.'); Flash('Something went wrong. Please try again.');
} }
...@@ -73,13 +81,6 @@ ...@@ -73,13 +81,6 @@
Flash('Something went wrong. Please try again.'); Flash('Something went wrong. Please try again.');
stopPolling(); stopPolling();
}); });
});
})
.catch((error) => {
this.rebasingError = error.merge_error;
this.isMakingRequest = false;
Flash('Something went wrong. Please try again.');
});
}, },
}, },
}; };
......
import Vue from 'vue'; import Vue from 'vue';
import eventHub from '~/vue_merge_request_widget/event_hub';
import component from 'ee/vue_merge_request_widget/components/states/mr_widget_rebase.vue'; import component from 'ee/vue_merge_request_widget/components/states/mr_widget_rebase.vue';
import mountComponent from '../../helpers/vue_mount_component_helper'; import mountComponent from '../../helpers/vue_mount_component_helper';
...@@ -75,4 +76,42 @@ describe('Merge request widget rebase component', () => { ...@@ -75,4 +76,42 @@ describe('Merge request widget rebase component', () => {
expect(text).toContain('to allow this merge request to be merged.'); expect(text).toContain('to allow this merge request to be merged.');
}); });
}); });
describe('methods', () => {
it('checkRebaseStatus', (done) => {
spyOn(eventHub, '$emit');
vm = mountComponent(Component, {
mr: {},
service: {
rebase() {
return Promise.resolve();
},
poll() {
return Promise.resolve({
json() {
return {
rebase_in_progress: false,
merge_error: null,
};
},
});
},
},
});
vm.rebase();
// Wait for the rebase request
vm.$nextTick()
// Wait for the polling request
.then(vm.$nextTick())
// Wait for the eventHub to be called
.then(vm.$nextTick())
.then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith('MRWidgetUpdateRequested');
})
.then(done)
.catch(done.fail);
});
});
}); });
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