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
This commit is contained in:
Kasper Nilsson
2017-07-11 14:50:51 -07:00
parent 4691942270
commit de211a56a2
4 changed files with 19 additions and 9 deletions

View File

@@ -14,6 +14,9 @@
(function() {
'use strict';
const ERR_BRANCH_EMPTY = 'The destination branch cant be empty.';
const ERR_COMMIT_EMPTY = 'The commit message cant be empty.';
const ERR_REVISION_ACTIONS = 'Couldnt load revision actions.';
/**
* @enum {number}
*/
@@ -293,8 +296,7 @@
this.revisionActions = revisionActions;
this._loading = false;
}).catch(err => {
alert('Couldnt 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 cant be empty.');
this.fire('show-alert', {message: ERR_BRANCH_EMPTY});
return;
}
if (!el.message) {
alert('The commit message cant be empty.');
this.fire('show-alert', {message: ERR_COMMIT_EMPTY});
return;
}
this.$.overlay.close();

View File

@@ -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}.`;

View File

@@ -34,17 +34,21 @@ limitations under the License.
<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', () => {

View File

@@ -17,6 +17,8 @@
const COMMIT_MESSAGE_PATH = '/COMMIT_MSG';
const MERGE_LIST_PATH = '/MERGE_LIST';
const ERR_REVIEW_STATUS = 'Couldnt 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('Couldnt change file review status. Check the console ' +
'and contact the PolyGerrit team for assistance.');
this.fire('show-alert', {message: ERR_REVIEW_STATUS});
throw err;
});
},