Remove alert-based error reporting
Migrates all alert calls to toasts. Also corrects one test that checked
for an alert on the window.
Bug: Issue 6701
Change-Id: I4d41790f63edc15873014df4f98013ac2bb2af7c
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 c5660ac..32e14d2 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
@@ -14,6 +14,9 @@
(function() {
'use strict';
+ const ERR_BRANCH_EMPTY = 'The destination branch can’t be empty.';
+ const ERR_COMMIT_EMPTY = 'The commit message can’t be empty.';
+ const ERR_REVISION_ACTIONS = 'Couldn’t load revision actions.';
/**
* @enum {number}
*/
@@ -293,8 +296,7 @@
this.revisionActions = revisionActions;
this._loading = false;
}).catch(err => {
- alert('Couldn’t load revision actions. Check the console ' +
- 'and contact the PolyGerrit team for assistance.');
+ this.fire('show-alert', {message: ERR_REVISION_ACTIONS});
this._loading = false;
throw err;
});
@@ -696,11 +698,11 @@
const el = this.$.confirmCherrypick;
if (!el.branch) {
// TODO(davido): Fix error handling
- alert('The destination branch can’t be empty.');
+ this.fire('show-alert', {message: ERR_BRANCH_EMPTY});
return;
}
if (!el.message) {
- alert('The commit message can’t be empty.');
+ this.fire('show-alert', {message: ERR_COMMIT_EMPTY});
return;
}
this.$.overlay.close();
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js
index 4a1bbb8..5b11652 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js
@@ -14,6 +14,9 @@
(function() {
'use strict';
+ const ERR_COMMIT_NOT_FOUND =
+ 'Unable to find the commit hash of this change.';
+
Polymer({
is: 'gr-confirm-revert-dialog',
@@ -38,7 +41,7 @@
const originalTitle = message.split('\n')[0];
const revertTitle = `Revert "${originalTitle}"`;
if (!commitHash) {
- alert('Unable to find the commit hash of this change.');
+ this.fire('show-alert', {message: ERR_COMMIT_NOT_FOUND});
return;
}
const revertCommitText = `This reverts commit ${commitHash}.`;
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html
index 09ba6bb..c1220cb 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html
+++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html
@@ -34,17 +34,21 @@
<script>
suite('gr-confirm-revert-dialog tests', () => {
let element;
+ let sandbox;
setup(() => {
element = fixture('basic');
+ sandbox =sinon.sandbox.create();
});
+ teardown(() => sandbox.restore());
+
test('no match', () => {
assert.isNotOk(element.message);
- const alertStub = sinon.stub(window, 'alert');
+ const alertStub = sandbox.stub();
+ element.addEventListener('show-alert', alertStub);
element.populateRevertMessage('not a commitHash in sight', undefined);
assert.isTrue(alertStub.calledOnce);
- alertStub.restore();
});
test('single line', () => {
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index 4d66fe1..8093aa2 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -17,6 +17,8 @@
const COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
const MERGE_LIST_PATH = '/MERGE_LIST';
+ const ERR_REVIEW_STATUS = 'Couldn’t change file review status.';
+
const COMMENT_SAVE = 'Try again when all comments have saved.';
const DiffSides = {
@@ -191,8 +193,7 @@
_setReviewed(reviewed) {
this.$.reviewed.checked = reviewed;
this._saveReviewedState(reviewed).catch(err => {
- alert('Couldn’t change file review status. Check the console ' +
- 'and contact the PolyGerrit team for assistance.');
+ this.fire('show-alert', {message: ERR_REVIEW_STATUS});
throw err;
});
},