diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html index 96c6193b71..30e9e86676 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.html @@ -112,6 +112,19 @@ limitations under the License. on-confirm="_handleAbandonDialogConfirm" on-cancel="_handleConfirmDialogCancel" hidden> + + + Delete Change + + + Do you really want to delete the change? + + diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js index 9fdc2a93ad..ef2a3b4456 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js @@ -336,6 +336,8 @@ var type = el.getAttribute('data-action-type'); if (type === ActionType.REVISION) { this._handleRevisionAction(key); + } else if (key === ChangeActions.DELETE) { + this._showActionDialog(this.$.confirmDeleteDialog); } else if (key === ChangeActions.REVERT) { this.showRevertDialog(); } else if (key === ChangeActions.ABANDON) { @@ -441,6 +443,10 @@ {message: el.message}); }, + _handleDeleteConfirm: function() { + this._fireAction('/', this.actions[ChangeActions.DELETE], false); + }, + _setLoadingOnButtonWithKey: function(key) { var buttonEl = this.$$('[data-action-key="' + key + '"]'); buttonEl.setAttribute('loading', true); diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html index c180f46649..00e61d9a8a 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html @@ -434,5 +434,59 @@ limitations under the License. populateRevertMsgStub.restore(); }); }); + + suite('delete change', function() { + var fireActionStub; + var deleteAction; + + var tapDeleteAction = function() { + var deleteButton = element.$$('gr-button[data-action-key=\'/\']'); + MockInteractions.tap(deleteButton); + flushAsynchronousOperations(); + }; + + setup(function() { + fireActionStub = sinon.stub(element, '_fireAction'); + element.change = { + current_revision: 'abc1234', + }; + deleteAction = { + method: 'DELETE', + label: 'Delete Change', + title: 'Delete change X_X', + enabled: true, + }; + element.actions = { + '/': deleteAction, + }; + }); + + teardown(function() { + fireActionStub.restore(); + }); + + test('does not delete on action', function() { + tapDeleteAction(); + assert.isFalse(fireActionStub.called); + }); + + test('shows confirm dialog', function() { + tapDeleteAction(); + assert.isFalse(element.$$('#confirmDeleteDialog').hidden); + MockInteractions.tap( + element.$$('#confirmDeleteDialog').$$('gr-button[primary]')); + flushAsynchronousOperations(); + assert.isTrue(fireActionStub.calledWith('/', deleteAction, false)); + }); + + test('hides delete confirm on cancel', function() { + tapDeleteAction(); + MockInteractions.tap( + element.$$('#confirmDeleteDialog').$$('gr-button:not([primary])')); + flushAsynchronousOperations(); + assert.isTrue(element.$$('#confirmDeleteDialog').hidden); + assert.isFalse(fireActionStub.called); + }); + }); });