Commit d53aea6b authored by Phil Hughes's avatar Phil Hughes

Fixed merge request status badge not updating after merging

parent 5c51cbca
...@@ -110,7 +110,7 @@ MergeRequest.prototype.initCommitMessageListeners = function() { ...@@ -110,7 +110,7 @@ MergeRequest.prototype.initCommitMessageListeners = function() {
}); });
}; };
MergeRequest.prototype.updateStatusText = function(classToRemove, classToAdd, newStatusText) { MergeRequest.updateStatusText = function(classToRemove, classToAdd, newStatusText) {
$('.detail-page-header .status-box') $('.detail-page-header .status-box')
.removeClass(classToRemove) .removeClass(classToRemove)
.addClass(classToAdd) .addClass(classToAdd)
...@@ -118,14 +118,14 @@ MergeRequest.prototype.updateStatusText = function(classToRemove, classToAdd, ne ...@@ -118,14 +118,14 @@ MergeRequest.prototype.updateStatusText = function(classToRemove, classToAdd, ne
.text(newStatusText); .text(newStatusText);
}; };
MergeRequest.prototype.decreaseCounter = function(by = 1) { MergeRequest.decreaseCounter = function(by = 1) {
const $el = $('.nav-links .js-merge-counter'); const $el = $('.js-merge-counter');
const count = Math.max((parseInt($el.text().replace(/[^\d]/, ''), 10) - by), 0); const count = Math.max((parseInt($el.text().replace(/[^\d]/, ''), 10) - by), 0);
$el.text(addDelimiter(count)); $el.text(addDelimiter(count));
}; };
MergeRequest.prototype.hideCloseButton = function() { MergeRequest.hideCloseButton = function() {
const el = document.querySelector('.merge-request .js-issuable-actions'); const el = document.querySelector('.merge-request .js-issuable-actions');
const closeDropdownItem = el.querySelector('li.close-item'); const closeDropdownItem = el.querySelector('li.close-item');
if (closeDropdownItem) { if (closeDropdownItem) {
......
import successSvg from 'icons/_icon_status_success.svg'; import successSvg from 'icons/_icon_status_success.svg';
import warningSvg from 'icons/_icon_status_warning.svg'; import warningSvg from 'icons/_icon_status_warning.svg';
import simplePoll from '~/lib/utils/simple_poll'; import simplePoll from '~/lib/utils/simple_poll';
import MergeRequest from '../../../merge_request';
import Flash from '../../../flash'; import Flash from '../../../flash';
import statusIcon from '../mr_widget_status_icon'; import statusIcon from '../mr_widget_status_icon';
import eventHub from '../../event_hub'; import eventHub from '../../event_hub';
...@@ -165,11 +166,9 @@ export default { ...@@ -165,11 +166,9 @@ export default {
// If state is merged we should update the widget and stop the polling // If state is merged we should update the widget and stop the polling
eventHub.$emit('MRWidgetUpdateRequested'); eventHub.$emit('MRWidgetUpdateRequested');
eventHub.$emit('FetchActionsContent'); eventHub.$emit('FetchActionsContent');
if (window.mergeRequest) { MergeRequest.updateStatusText('status-box-open', 'status-box-merged', 'Merged');
window.mergeRequest.updateStatusText('status-box-open', 'status-box-merged', 'Merged'); MergeRequest.hideCloseButton();
window.mergeRequest.hideCloseButton(); MergeRequest.decreaseCounter();
window.mergeRequest.decreaseCounter();
}
stopPolling(); stopPolling();
// If user checked remove source branch and we didn't remove the branch yet // If user checked remove source branch and we didn't remove the branch yet
......
---
title: Fixed merge request status badge not updating after merging
merge_request:
author:
type: fixed
...@@ -70,8 +70,7 @@ import IssuablesHelper from '~/helpers/issuables_helper'; ...@@ -70,8 +70,7 @@ import IssuablesHelper from '~/helpers/issuables_helper';
beforeEach(() => { beforeEach(() => {
loadFixtures('merge_requests/merge_request_with_task_list.html.raw'); loadFixtures('merge_requests/merge_request_with_task_list.html.raw');
this.el = document.querySelector('.js-issuable-actions'); this.el = document.querySelector('.js-issuable-actions');
const merge = new MergeRequest(); MergeRequest.hideCloseButton();
merge.hideCloseButton();
}); });
it('hides the dropdown close item and selects the next item', () => { it('hides the dropdown close item and selects the next item', () => {
......
...@@ -371,6 +371,10 @@ describe('MRWidgetReadyToMerge', () => { ...@@ -371,6 +371,10 @@ describe('MRWidgetReadyToMerge', () => {
}); });
}); });
beforeEach(() => {
loadFixtures('merge_requests/merge_request_of_current_user.html.raw');
});
it('should call start and stop polling when MR merged', (done) => { it('should call start and stop polling when MR merged', (done) => {
spyOn(eventHub, '$emit'); spyOn(eventHub, '$emit');
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged')); spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
...@@ -392,6 +396,47 @@ describe('MRWidgetReadyToMerge', () => { ...@@ -392,6 +396,47 @@ describe('MRWidgetReadyToMerge', () => {
}, 333); }, 333);
}); });
it('updates status box', (done) => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
vm.handleMergePolling(() => {}, () => {});
setTimeout(() => {
const statusBox = document.querySelector('.status-box');
expect(statusBox.classList.contains('status-box-merged')).toBeTruthy();
expect(statusBox.textContent).toContain('Merged');
done();
});
});
it('hides close button', (done) => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
vm.handleMergePolling(() => {}, () => {});
setTimeout(() => {
expect(document.querySelector('.btn-close').classList.contains('hidden')).toBeTruthy();
done();
});
});
it('updates merge request count badge', (done) => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('merged'));
spyOn(vm, 'initiateRemoveSourceBranchPolling');
vm.handleMergePolling(() => {}, () => {});
setTimeout(() => {
expect(document.querySelector('.js-merge-counter').textContent).toBe('0');
done();
});
});
it('should continue polling until MR is merged', (done) => { it('should continue polling until MR is merged', (done) => {
spyOn(vm.service, 'poll').and.returnValue(returnPromise('some_other_state')); spyOn(vm.service, 'poll').and.returnValue(returnPromise('some_other_state'));
spyOn(vm, 'initiateRemoveSourceBranchPolling'); spyOn(vm, 'initiateRemoveSourceBranchPolling');
......
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