Confirm change delete with a dialog Bug: Issue 4895 Change-Id: Ie0ef166811d8dfefc3bf60a8b48d8cb478d867dc
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 96c6193..30e9e86 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 @@ on-confirm="_handleAbandonDialogConfirm" on-cancel="_handleConfirmDialogCancel" hidden></gr-confirm-abandon-dialog> + <gr-confirm-dialog + id="confirmDeleteDialog" + class="confirmDialog" + confirm-label="Delete" + on-cancel="_handleConfirmDialogCancel" + on-confirm="_handleDeleteConfirm"> + <div class="header"> + Delete Change + </div> + <div class="main"> + Do you really want to delete the change? + </div> + </gr-confirm-dialog> </gr-overlay> <gr-js-api-interface id="jsAPI"></gr-js-api-interface> <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
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 9fdc2a9..ef2a3b4 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 c180f46..00e61d9 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 @@ 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); + }); + }); }); </script>