Confirm change delete with a dialog

Bug: Issue 4895
Change-Id: Ie0ef166811d8dfefc3bf60a8b48d8cb478d867dc
This commit is contained in:
Viktar Donich
2016-11-07 15:50:11 -08:00
parent aedb7fbce0
commit bcd44b1ba4
3 changed files with 73 additions and 0 deletions

View File

@@ -112,6 +112,19 @@ limitations under the License.
on-confirm="_handleAbandonDialogConfirm" on-confirm="_handleAbandonDialogConfirm"
on-cancel="_handleConfirmDialogCancel" on-cancel="_handleConfirmDialogCancel"
hidden></gr-confirm-abandon-dialog> 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-overlay>
<gr-js-api-interface id="jsAPI"></gr-js-api-interface> <gr-js-api-interface id="jsAPI"></gr-js-api-interface>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface> <gr-rest-api-interface id="restAPI"></gr-rest-api-interface>

View File

@@ -336,6 +336,8 @@
var type = el.getAttribute('data-action-type'); var type = el.getAttribute('data-action-type');
if (type === ActionType.REVISION) { if (type === ActionType.REVISION) {
this._handleRevisionAction(key); this._handleRevisionAction(key);
} else if (key === ChangeActions.DELETE) {
this._showActionDialog(this.$.confirmDeleteDialog);
} else if (key === ChangeActions.REVERT) { } else if (key === ChangeActions.REVERT) {
this.showRevertDialog(); this.showRevertDialog();
} else if (key === ChangeActions.ABANDON) { } else if (key === ChangeActions.ABANDON) {
@@ -441,6 +443,10 @@
{message: el.message}); {message: el.message});
}, },
_handleDeleteConfirm: function() {
this._fireAction('/', this.actions[ChangeActions.DELETE], false);
},
_setLoadingOnButtonWithKey: function(key) { _setLoadingOnButtonWithKey: function(key) {
var buttonEl = this.$$('[data-action-key="' + key + '"]'); var buttonEl = this.$$('[data-action-key="' + key + '"]');
buttonEl.setAttribute('loading', true); buttonEl.setAttribute('loading', true);

View File

@@ -434,5 +434,59 @@ limitations under the License.
populateRevertMsgStub.restore(); 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> </script>