update issue count when closing/reopening an issue

This commit is contained in:
Simon Knox 2017-02-14 17:27:29 +11:00
parent 865e3fcc13
commit 142432ce5a
2 changed files with 7 additions and 0 deletions

View File

@ -54,16 +54,19 @@ require('vendor/task_list');
success: function(data, textStatus, jqXHR) { success: function(data, textStatus, jqXHR) {
if ('id' in data) { if ('id' in data) {
$(document).trigger('issuable:change'); $(document).trigger('issuable:change');
const currentTotal = Number($('.issue_counter').text());
if (isClose) { if (isClose) {
$('a.btn-close').addClass('hidden'); $('a.btn-close').addClass('hidden');
$('a.btn-reopen').removeClass('hidden'); $('a.btn-reopen').removeClass('hidden');
$('div.status-box-closed').removeClass('hidden'); $('div.status-box-closed').removeClass('hidden');
$('div.status-box-open').addClass('hidden'); $('div.status-box-open').addClass('hidden');
$('.issue_counter').text(currentTotal - 1);
} else { } else {
$('a.btn-reopen').addClass('hidden'); $('a.btn-reopen').addClass('hidden');
$('a.btn-close').removeClass('hidden'); $('a.btn-close').removeClass('hidden');
$('div.status-box-closed').addClass('hidden'); $('div.status-box-closed').addClass('hidden');
$('div.status-box-open').removeClass('hidden'); $('div.status-box-open').removeClass('hidden');
$('.issue_counter').text(currentTotal + 1);
} }
} else { } else {
new Flash(issueFailMessage, 'alert'); new Flash(issueFailMessage, 'alert');

View File

@ -105,6 +105,7 @@ require('~/issue');
expectIssueState(false); expectIssueState(false);
expect($btnClose).toHaveProp('disabled', false); expect($btnClose).toHaveProp('disabled', false);
expect($('.issue_counter')).toHaveText(0);
}); });
it('fails to close an issue with success:false', function() { it('fails to close an issue with success:false', function() {
@ -121,6 +122,7 @@ require('~/issue');
expectIssueState(true); expectIssueState(true);
expect($btnClose).toHaveProp('disabled', false); expect($btnClose).toHaveProp('disabled', false);
expectErrorMessage(); expectErrorMessage();
expect($('.issue_counter')).toHaveText(1);
}); });
it('fails to closes an issue with HTTP error', function() { it('fails to closes an issue with HTTP error', function() {
@ -135,6 +137,7 @@ require('~/issue');
expectIssueState(true); expectIssueState(true);
expect($btnClose).toHaveProp('disabled', true); expect($btnClose).toHaveProp('disabled', true);
expectErrorMessage(); expectErrorMessage();
expect($('.issue_counter')).toHaveText(1);
}); });
}); });
@ -159,6 +162,7 @@ require('~/issue');
expectIssueState(true); expectIssueState(true);
expect($btnReopen).toHaveProp('disabled', false); expect($btnReopen).toHaveProp('disabled', false);
expect($('.issue_counter')).toHaveText(1);
}); });
}); });
}).call(this); }).call(this);