Merge "Confirm change delete with a dialog"
This commit is contained in:
@@ -112,6 +112,19 @@ limitations under the License.
|
||||
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>
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user