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,30 +50,7 @@ ...@@ -50,30 +50,7 @@
this.service.rebase() this.service.rebase()
.then(() => { .then(() => {
simplePoll((continuePolling, stopPolling) => { simplePoll(this.checkRebaseStatus);
this.service.poll()
.then(res => res.json())
.then((res) => {
if (res.rebase_in_progress) {
continuePolling();
} else {
this.isMakingRequest = false;
if (res.merge_error.length) {
this.rebasingError = res.merge_error;
Flash('Something went wrong. Please try again.');
}
eventHub.$emit('MRWidgetUpdateRequested');
stopPolling();
}
})
.catch(() => {
this.isMakingRequest = false;
Flash('Something went wrong. Please try again.');
stopPolling();
});
});
}) })
.catch((error) => { .catch((error) => {
this.rebasingError = error.merge_error; this.rebasingError = error.merge_error;
...@@ -81,6 +58,30 @@ ...@@ -81,6 +58,30 @@
Flash('Something went wrong. Please try again.'); Flash('Something went wrong. Please try again.');
}); });
}, },
checkRebaseStatus(continuePolling, stopPolling) {
this.service.poll()
.then(res => res.json())
.then((res) => {
if (res.rebase_in_progress) {
continuePolling();
} else {
this.isMakingRequest = false;
if (res.merge_error && res.merge_error.length) {
this.rebasingError = res.merge_error;
Flash('Something went wrong. Please try again.');
}
eventHub.$emit('MRWidgetUpdateRequested');
stopPolling();
}
})
.catch(() => {
this.isMakingRequest = false;
Flash('Something went wrong. Please try again.');
stopPolling();
});
},
}, },
}; };
</script> </script>
......
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