Merge "ES6ify /gr-diff-preferences/*"
diff --git a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java
index 5117328..3ab4a88 100644
--- a/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java
+++ b/gerrit-acceptance-framework/src/test/java/com/google/gerrit/acceptance/TestAccount.java
@@ -16,12 +16,15 @@
import static java.util.stream.Collectors.toList;
+import com.google.common.net.InetAddresses;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.mail.Address;
import com.jcraft.jsch.KeyPair;
import java.io.ByteArrayOutputStream;
+import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.List;
+import org.apache.http.client.utils.URIBuilder;
import org.eclipse.jgit.lib.PersonIdent;
public class TestAccount {
@@ -77,12 +80,13 @@
}
public String getHttpUrl(GerritServer server) {
- return String.format(
- "http://%s:%s@%s:%d",
- username,
- httpPassword,
- server.getHttpAddress().getAddress().getHostAddress(),
- server.getHttpAddress().getPort());
+ InetSocketAddress addr = server.getHttpAddress();
+ return new URIBuilder()
+ .setScheme("http")
+ .setUserInfo(username, httpPassword)
+ .setHost(InetAddresses.toUriString(addr.getAddress()))
+ .setPort(addr.getPort())
+ .toString();
}
public Account.Id getId() {
diff --git a/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js
index e47f14f..074e39e 100644
--- a/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-confirm-abandon-dialog/gr-confirm-abandon-dialog.js
@@ -33,16 +33,16 @@
message: String,
},
- resetFocus: function() {
+ resetFocus() {
this.$.messageInput.textarea.focus();
},
- _handleConfirmTap: function(e) {
+ _handleConfirmTap(e) {
e.preventDefault();
this.fire('confirm', {reason: this.message}, {bubbles: false});
},
- _handleCancelTap: function(e) {
+ _handleCancelTap(e) {
e.preventDefault();
this.fire('cancel', null, {bubbles: false});
},
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
index 0791193..ea6347f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js
@@ -173,6 +173,9 @@
},
_eraseDraftComment: function() {
+ // Prevents a race condition in which removing the draft comment occurs
+ // prior to it being saved.
+ this.cancelDebouncer('store');
this.$.storage.eraseDraftComment({
changeNum: this.changeNum,
patchNum: this._getPatchNum(),
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html
index 919a64f..bcac6b3 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html
@@ -476,6 +476,7 @@
test('draft saving/editing', function(done) {
var fireStub = sinon.stub(element, 'fire');
+ let cancelDebounce = sandbox.stub(element, 'cancelDebouncer');
element.draft = true;
MockInteractions.tap(element.$$('.edit'));
@@ -507,6 +508,7 @@
element._xhrPromise.then(function(draft) {
assert(fireStub.calledWith('comment-save'),
'comment-save should be sent');
+ assert(cancelDebounce.calledWith('store'));
assert.deepEqual(fireStub.lastCall.args[1], {
comment: {
__commentSide: 'right',
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
index 58d29bd..e9437bd 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.js
@@ -15,7 +15,7 @@
'use strict';
// Maximum length for patch set descriptions.
- var PATCH_DESC_MAX_LENGTH = 500;
+ const PATCH_DESC_MAX_LENGTH = 500;
Polymer({
is: 'gr-patch-range-select',
@@ -36,15 +36,15 @@
behaviors: [Gerrit.PatchSetBehavior],
- _updateSelected: function() {
+ _updateSelected() {
this._rightSelected = this.patchRange.patchNum;
this._leftSelected = this.patchRange.basePatchNum;
},
- _handlePatchChange: function(e) {
- var leftPatch = this._leftSelected;
- var rightPatch = this._rightSelected;
- var rangeStr = rightPatch;
+ _handlePatchChange(e) {
+ const leftPatch = this._leftSelected;
+ const rightPatch = this._rightSelected;
+ let rangeStr = rightPatch;
if (leftPatch != 'PARENT') {
rangeStr = leftPatch + '..' + rangeStr;
}
@@ -52,11 +52,11 @@
e.target.blur();
},
- _computeLeftDisabled: function(patchNum, patchRange) {
+ _computeLeftDisabled(patchNum, patchRange) {
return parseInt(patchNum, 10) >= parseInt(patchRange.patchNum, 10);
},
- _computeRightDisabled: function(patchNum, patchRange) {
+ _computeRightDisabled(patchNum, patchRange) {
if (patchRange.basePatchNum == 'PARENT') { return false; }
return parseInt(patchNum, 10) <= parseInt(patchRange.basePatchNum, 10);
},
@@ -66,16 +66,16 @@
// are loaded, the correct value will get selected. I attempted to
// debounce these, but because they are detecting two different
// events, sometimes the timing was off and one ended up missing.
- _synchronizeSelectionRight: function() {
+ _synchronizeSelectionRight() {
this.$.rightPatchSelect.value = this._rightSelected;
},
- _synchronizeSelectionLeft: function() {
+ _synchronizeSelectionLeft() {
this.$.leftPatchSelect.value = this._leftSelected;
},
- _computePatchSetDescription: function(revisions, patchNum) {
- var rev = this.getRevisionByPatchNum(revisions, patchNum);
+ _computePatchSetDescription(revisions, patchNum) {
+ const rev = this.getRevisionByPatchNum(revisions, patchNum);
return (rev && rev.description) ?
rev.description.substring(0, PATCH_DESC_MAX_LENGTH) : '';
},
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html
index 00d73bf..0195eac 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.html
@@ -34,24 +34,24 @@
</test-fixture>
<script>
- suite('gr-patch-range-select tests', function() {
- var element;
+ suite('gr-patch-range-select tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
element = fixture('basic');
});
- test('enabled/disabled options', function() {
- var patchRange = {
+ test('enabled/disabled options', () => {
+ const patchRange = {
basePatchNum: 'PARENT',
patchNum: '3',
};
- ['1', '2', '3'].forEach(function(patchNum) {
+ for (const patchNum of ['1', '2', '3']) {
assert.isFalse(element._computeRightDisabled(patchNum, patchRange));
- });
- ['PARENT', '1', '2'].forEach(function(patchNum) {
+ }
+ for (const patchNum of ['PARENT', '1', '2']) {
assert.isFalse(element._computeLeftDisabled(patchNum, patchRange));
- });
+ }
assert.isTrue(element._computeLeftDisabled('3', patchRange));
patchRange.basePatchNum = '2';
@@ -61,11 +61,11 @@
assert.isFalse(element._computeRightDisabled('3', patchRange));
});
- test('navigation', function(done) {
- var showStub = sinon.stub(page, 'show');
- var leftSelectEl = element.$.leftPatchSelect;
- var rightSelectEl = element.$.rightPatchSelect;
- var blurSpy = sinon.spy(leftSelectEl, 'blur');
+ test('navigation', done => {
+ const showStub = sinon.stub(page, 'show');
+ const leftSelectEl = element.$.leftPatchSelect;
+ const rightSelectEl = element.$.rightPatchSelect;
+ const blurSpy = sinon.spy(leftSelectEl, 'blur');
element.changeNum = '42';
element.path = 'path/to/file.txt';
element.availablePatches = ['1', '2', '3'];
@@ -75,8 +75,8 @@
};
flushAsynchronousOperations();
- var numEvents = 0;
- leftSelectEl.addEventListener('change', function(e) {
+ let numEvents = 0;
+ leftSelectEl.addEventListener('change', e => {
numEvents++;
if (numEvents == 1) {
assert(showStub.lastCall.calledWithExactly(
@@ -98,23 +98,23 @@
element.fire('change', {}, {node: leftSelectEl});
});
- test('filesWeblinks', function() {
+ test('filesWeblinks', () => {
element.filesWeblinks = {
meta_a: [
{
name: 'foo',
url: 'f.oo',
- }
+ },
],
meta_b: [
{
name: 'bar',
url: 'ba.r',
- }
+ },
],
};
flushAsynchronousOperations();
- var domApi = Polymer.dom(element.root);
+ const domApi = Polymer.dom(element.root);
assert.equal(
domApi.querySelector('a[href="f.oo"]').textContent, 'foo');
assert.equal(
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js
index 9bcde07..99c4fed 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api.js
@@ -22,13 +22,13 @@
}
GrChangeActionsInterface.prototype.addPrimaryActionKey = function(key) {
- if (this._el.primaryActionKeys.indexOf(key) !== -1) { return; }
+ if (this._el.primaryActionKeys.includes(key)) { return; }
this._el.push('primaryActionKeys', key);
};
GrChangeActionsInterface.prototype.removePrimaryActionKey = function(key) {
- this._el.primaryActionKeys = this._el.primaryActionKeys.filter(function(k) {
+ this._el.primaryActionKeys = this._el.primaryActionKeys.filter(k => {
return k !== key;
});
};
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
index d964cde..24fee39 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-actions-js-api_test.html
@@ -37,43 +37,44 @@
</test-fixture>
<script>
- suite('gr-js-api-interface tests', function() {
- var element;
- var changeActions;
+ suite('gr-js-api-interface tests', () => {
+ let element;
+ let changeActions;
// Because deepEqual doesn’t behave in Safari.
function assertArraysEqual(actual, expected) {
assert.equal(actual.length, expected.length);
- for (var i = 0; i < actual.length; i++) {
+ for (let i = 0; i < actual.length; i++) {
assert.equal(actual[i], expected[i]);
}
}
- setup(function() {
+ setup(() => {
element = fixture('basic');
element.change = {};
element._hasKnownChainState = false;
- var plugin;
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ let plugin;
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeActions = plugin.changeActions();
});
- teardown(function() {
+ teardown(() => {
changeActions = null;
});
- test('property existence', function() {
- [
+ test('property existence', () => {
+ const properties = [
'ActionType',
'ChangeActions',
'RevisionActions',
- ].forEach(function(p) {
+ ];
+ for (const p of properties) {
assertArraysEqual(changeActions[p], element[p]);
- });
+ }
});
- test('add/remove primary action keys', function() {
+ test('add/remove primary action keys', () => {
element.primaryActionKeys = [];
changeActions.addPrimaryActionKey('foo');
assertArraysEqual(element.primaryActionKeys, ['foo']);
@@ -89,34 +90,34 @@
assertArraysEqual(element.primaryActionKeys, []);
});
- test('action buttons', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- var handler = sinon.spy();
+ test('action buttons', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ const handler = sinon.spy();
changeActions.addTapListener(key, handler);
- flush(function() {
+ flush(() => {
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.removeTapListener(key, handler);
MockInteractions.tap(element.$$('[data-action-key="' + key + '"]'));
assert(handler.calledOnce);
changeActions.remove(key);
- flush(function() {
+ flush(() => {
assert.isNull(element.$$('[data-action-key="' + key + '"]'));
done();
});
});
});
- test('action button properties', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- flush(function() {
- var button = element.$$('[data-action-key="' + key + '"]');
+ test('action button properties', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ flush(() => {
+ const button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.equal(button.getAttribute('data-label'), 'Bork!');
assert.isNotOk(button.disabled);
changeActions.setLabel(key, 'Yo');
changeActions.setEnabled(key, false);
- flush(function() {
+ flush(() => {
assert.equal(button.getAttribute('data-label'), 'Yo');
assert.isTrue(button.disabled);
done();
@@ -124,30 +125,30 @@
});
});
- test('hide action buttons', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- flush(function() {
- var button = element.$$('[data-action-key="' + key + '"]');
+ test('hide action buttons', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ flush(() => {
+ const button = element.$$('[data-action-key="' + key + '"]');
assert.isOk(button);
assert.isFalse(button.hasAttribute('hidden'));
changeActions.setActionHidden(
changeActions.ActionType.REVISION, key, true);
- flush(function() {
- var button = element.$$('[data-action-key="' + key + '"]');
+ flush(() => {
+ const button = element.$$('[data-action-key="' + key + '"]');
assert.isNotOk(button);
done();
});
});
});
- test('move action button to overflow', function(done) {
- var key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- flush(function() {
+ test('move action button to overflow', done => {
+ const key = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ flush(() => {
assert.isTrue(element.$.moreActions.hidden);
assert.isOk(element.$$('[data-action-key="' + key + '"]'));
changeActions.setActionOverflow(
changeActions.ActionType.REVISION, key, true);
- flush(function() {
+ flush(() => {
assert.isNotOk(element.$$('[data-action-key="' + key + '"]'));
assert.isFalse(element.$.moreActions.hidden);
assert.strictEqual(element.$.moreActions.items[0].name, 'Bork!');
@@ -156,17 +157,19 @@
});
});
- test('change actions priority', function(done) {
- var key1 = changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
- var key2 = changeActions.add(changeActions.ActionType.CHANGE, 'Squanch?');
- flush(function() {
- var buttons =
+ test('change actions priority', done => {
+ const key1 =
+ changeActions.add(changeActions.ActionType.REVISION, 'Bork!');
+ const key2 =
+ changeActions.add(changeActions.ActionType.CHANGE, 'Squanch?');
+ flush(() => {
+ let buttons =
Polymer.dom(element.root).querySelectorAll('[data-action-key]');
assert.equal(buttons[0].getAttribute('data-action-key'), key1);
assert.equal(buttons[1].getAttribute('data-action-key'), key2);
changeActions.setActionPriority(
changeActions.ActionType.REVISION, key1, 10);
- flush(function() {
+ flush(() => {
buttons =
Polymer.dom(element.root).querySelectorAll('[data-action-key]');
assert.equal(buttons[0].getAttribute('data-action-key'), key2);
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html
index c2357cc..73f3479 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-change-reply-js-api_test.html
@@ -37,35 +37,35 @@
</test-fixture>
<script>
- suite('gr-change-reply-js-api tests', function() {
- var element;
- var sandbox;
- var changeReply;
+ suite('gr-change-reply-js-api tests', () => {
+ let element;
+ let sandbox;
+ let changeReply;
- setup(function() {
+ setup(() => {
stub('gr-rest-api-interface', {
- getConfig: function() { return Promise.resolve({}); },
- getAccount: function() { return Promise.resolve(null); },
+ getConfig() { return Promise.resolve({}); },
+ getAccount() { return Promise.resolve(null); },
});
element = fixture('basic');
sandbox = sinon.sandbox.create();
- var plugin;
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ let plugin;
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
changeReply = plugin.changeReply();
});
- teardown(function() {
+ teardown(() => {
changeReply = null;
sandbox.restore();
});
- test('calls', function() {
- var setLabelValueStub = sinon.stub(element, 'setLabelValue');
+ test('calls', () => {
+ const setLabelValueStub = sinon.stub(element, 'setLabelValue');
changeReply.setLabelValue('My-Label', '+1337');
assert(setLabelValueStub.calledWithExactly('My-Label', '+1337'));
- var sendStub = sinon.stub(element, 'send');
+ const sendStub = sinon.stub(element, 'send');
changeReply.send(false);
assert(sendStub.calledWithExactly(false));
});
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
index 34ca728..70a9bf5 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
@@ -14,7 +14,7 @@
(function() {
'use strict';
- var EventType = {
+ const EventType = {
HISTORY: 'history',
LABEL_CHANGE: 'labelchange',
SHOW_CHANGE: 'showchange',
@@ -25,7 +25,7 @@
POST_REVERT: 'postrevert',
};
- var Element = {
+ const Element = {
CHANGE_ACTIONS: 'changeactions',
REPLY_DIALOG: 'replydialog',
};
@@ -44,11 +44,11 @@
},
},
- Element: Element,
- EventType: EventType,
+ Element,
+ EventType,
- handleEvent: function(type, detail) {
- Gerrit.awaitPluginsLoaded().then(function() {
+ handleEvent(type, detail) {
+ Gerrit.awaitPluginsLoaded().then(() => {
switch (type) {
case EventType.HISTORY:
this._handleHistory(detail);
@@ -67,27 +67,27 @@
type);
break;
}
- }.bind(this));
+ });
},
- addElement: function(key, el) {
+ addElement(key, el) {
this._elements[key] = el;
},
- getElement: function(key) {
+ getElement(key) {
return this._elements[key];
},
- addEventCallback: function(eventName, callback) {
+ addEventCallback(eventName, callback) {
if (!this._eventCallbacks[eventName]) {
this._eventCallbacks[eventName] = [];
}
this._eventCallbacks[eventName].push(callback);
},
- canSubmitChange: function(change, revision) {
- var submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
- var cancelSubmit = submitCallbacks.some(function(callback) {
+ canSubmitChange(change, revision) {
+ const submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
+ const cancelSubmit = submitCallbacks.some(callback => {
try {
return callback(change, revision) === false;
} catch (err) {
@@ -99,28 +99,29 @@
return !cancelSubmit;
},
- _removeEventCallbacks: function() {
- for (var k in EventType) {
+ _removeEventCallbacks() {
+ for (const k in EventType) {
+ if (!EventType.hasOwnProperty(k)) { continue; }
this._eventCallbacks[EventType[k]] = [];
}
},
- _handleHistory: function(detail) {
- this._getEventCallbacks(EventType.HISTORY).forEach(function(cb) {
+ _handleHistory(detail) {
+ for (const cb of this._getEventCallbacks(EventType.HISTORY)) {
try {
cb(detail.path);
} catch (err) {
console.error(err);
}
- });
+ }
},
- _handleShowChange: function(detail) {
- this._getEventCallbacks(EventType.SHOW_CHANGE).forEach(function(cb) {
- var change = detail.change;
- var patchNum = detail.patchNum;
- var revision;
- for (var rev in change.revisions) {
+ _handleShowChange(detail) {
+ for (const cb of this._getEventCallbacks(EventType.SHOW_CHANGE)) {
+ const change = detail.change;
+ const patchNum = detail.patchNum;
+ let revision;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
revision = change.revisions[rev];
break;
@@ -131,67 +132,63 @@
} catch (err) {
console.error(err);
}
- });
+ }
},
- handleCommitMessage: function(change, msg) {
- this._getEventCallbacks(EventType.COMMIT_MSG_EDIT).forEach(
- function(cb) {
- try {
- cb(change, msg);
- } catch (err) {
- console.error(err);
- }
- }
- );
+ handleCommitMessage(change, msg) {
+ for (const cb of this._getEventCallbacks(EventType.COMMIT_MSG_EDIT)) {
+ try {
+ cb(change, msg);
+ } catch (err) {
+ console.error(err);
+ }
+ }
},
- _handleComment: function(detail) {
- this._getEventCallbacks(EventType.COMMENT).forEach(function(cb) {
+ _handleComment(detail) {
+ for (const cb of this._getEventCallbacks(EventType.COMMENT)) {
try {
cb(detail.node);
} catch (err) {
console.error(err);
}
- });
+ }
},
- _handleLabelChange: function(detail) {
- this._getEventCallbacks(EventType.LABEL_CHANGE).forEach(function(cb) {
+ _handleLabelChange(detail) {
+ for (const cb of this._getEventCallbacks(EventType.LABEL_CHANGE)) {
try {
cb(detail.change);
} catch (err) {
console.error(err);
}
- });
+ }
},
- modifyRevertMsg: function(change, revertMsg, origMsg) {
- this._getEventCallbacks(EventType.REVERT).forEach(function(callback) {
+ modifyRevertMsg(change, revertMsg, origMsg) {
+ for (const cb of this._getEventCallbacks(EventType.REVERT)) {
try {
- revertMsg = callback(change, revertMsg, origMsg);
+ revertMsg = cb(change, revertMsg, origMsg);
} catch (err) {
console.error(err);
}
- });
+ }
return revertMsg;
},
- getLabelValuesPostRevert: function(change) {
- var labels = {};
- this._getEventCallbacks(EventType.POST_REVERT).forEach(
- function(callback) {
- try {
- labels = callback(change);
- } catch (err) {
- console.error(err);
- }
- }
- );
+ getLabelValuesPostRevert(change) {
+ let labels = {};
+ for (const cb of this._getEventCallbacks(EventType.POST_REVERT)) {
+ try {
+ labels = cb(change);
+ } catch (err) {
+ console.error(err);
+ }
+ }
return labels;
},
- _getEventCallbacks: function(type) {
+ _getEventCallbacks(type) {
return this._eventCallbacks[type] || [];
},
});
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
index d62bdd8..c3013bd 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface_test.html
@@ -31,45 +31,45 @@
</test-fixture>
<script>
- suite('gr-js-api-interface tests', function() {
- var element;
- var plugin;
- var errorStub;
- var sandbox;
+ suite('gr-js-api-interface tests', () => {
+ let element;
+ let plugin;
+ let errorStub;
+ let sandbox;
- var throwErrFn = function() {
+ const throwErrFn = function() {
throw Error('Unfortunately, this handler has stopped');
};
- setup(function() {
+ setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-rest-api-interface', {
- getAccount: function() {
+ getAccount() {
return Promise.resolve({name: 'Judy Hopps'});
},
});
element = fixture('basic');
errorStub = sandbox.stub(console, 'error');
Gerrit._setPluginsCount(1);
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
element._removeEventCallbacks();
plugin = null;
});
- test('url', function() {
+ test('url', () => {
assert.equal(plugin.url(), 'http://test.com/plugins/testplugin/');
assert.equal(plugin.url('/static/test.js'),
'http://test.com/plugins/testplugin/static/test.js');
});
- test('history event', function(done) {
+ test('history event', done => {
plugin.on(element.EventType.HISTORY, throwErrFn);
- plugin.on(element.EventType.HISTORY, function(path) {
+ plugin.on(element.EventType.HISTORY, path => {
assert.equal(path, '/path/to/awesomesauce');
assert.isTrue(errorStub.calledOnce);
done();
@@ -78,13 +78,13 @@
{path: '/path/to/awesomesauce'});
});
- test('showchange event', function(done) {
- var testChange = {
+ test('showchange event', done => {
+ const testChange = {
_number: 42,
revisions: {def: {_number: 2}, abc: {_number: 1}},
};
plugin.on(element.EventType.SHOW_CHANGE, throwErrFn);
- plugin.on(element.EventType.SHOW_CHANGE, function(change, revision) {
+ plugin.on(element.EventType.SHOW_CHANGE, (change, revision) => {
assert.deepEqual(change, testChange);
assert.deepEqual(revision, testChange.revisions.abc);
assert.isTrue(errorStub.calledOnce);
@@ -94,28 +94,28 @@
{change: testChange, patchNum: 1});
});
- test('handleEvent awaits plugins load', function(done) {
- var testChange = {
+ test('handleEvent awaits plugins load', done => {
+ const testChange = {
_number: 42,
revisions: {def: {_number: 2}, abc: {_number: 1}},
};
- var spy = sandbox.spy();
+ const spy = sandbox.spy();
Gerrit._setPluginsCount(1);
plugin.on(element.EventType.SHOW_CHANGE, spy);
element.handleEvent(element.EventType.SHOW_CHANGE,
{change: testChange, patchNum: 1});
assert.isFalse(spy.called);
Gerrit._setPluginsCount(0);
- flush(function() {
+ flush(() => {
assert.isTrue(spy.called);
done();
});
});
- test('comment event', function(done) {
- var testCommentNode = {foo: 'bar'};
+ test('comment event', done => {
+ const testCommentNode = {foo: 'bar'};
plugin.on(element.EventType.COMMENT, throwErrFn);
- plugin.on(element.EventType.COMMENT, function(commentNode) {
+ plugin.on(element.EventType.COMMENT, commentNode => {
assert.deepEqual(commentNode, testCommentNode);
assert.isTrue(errorStub.calledOnce);
done();
@@ -123,7 +123,7 @@
element.handleEvent(element.EventType.COMMENT, {node: testCommentNode});
});
- test('revert event', function() {
+ test('revert event', () => {
function appendToRevertMsg(c, revertMsg, originalMsg) {
return revertMsg + '\n' + originalMsg.replace(/^/gm, '> ') + '\ninfo';
}
@@ -134,16 +134,16 @@
plugin.on(element.EventType.REVERT, throwErrFn);
plugin.on(element.EventType.REVERT, appendToRevertMsg);
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
- 'test\n> origTest\ninfo');
+ 'test\n> origTest\ninfo');
assert.isTrue(errorStub.calledOnce);
plugin.on(element.EventType.REVERT, appendToRevertMsg);
assert.equal(element.modifyRevertMsg(null, 'test', 'origTest'),
- 'test\n> origTest\ninfo\n> origTest\ninfo');
+ 'test\n> origTest\ninfo\n> origTest\ninfo');
assert.isTrue(errorStub.calledTwice);
});
- test('postrevert event', function() {
+ test('postrevert event', () => {
function getLabels(c) {
return {'Code-Review': 1};
}
@@ -158,10 +158,10 @@
assert.isTrue(errorStub.calledOnce);
});
- test('commitmsgedit event', function(done) {
- var testMsg = 'Test CL commit message';
+ test('commitmsgedit event', done => {
+ const testMsg = 'Test CL commit message';
plugin.on(element.EventType.COMMIT_MSG_EDIT, throwErrFn);
- plugin.on(element.EventType.COMMIT_MSG_EDIT, function(change, msg) {
+ plugin.on(element.EventType.COMMIT_MSG_EDIT, (change, msg) => {
assert.deepEqual(msg, testMsg);
assert.isTrue(errorStub.calledOnce);
done();
@@ -169,10 +169,10 @@
element.handleCommitMessage(null, testMsg);
});
- test('labelchange event', function(done) {
- var testChange = {_number: 42};
+ test('labelchange event', done => {
+ const testChange = {_number: 42};
plugin.on(element.EventType.LABEL_CHANGE, throwErrFn);
- plugin.on(element.EventType.LABEL_CHANGE, function(change) {
+ plugin.on(element.EventType.LABEL_CHANGE, change => {
assert.deepEqual(change, testChange);
assert.isTrue(errorStub.calledOnce);
done();
@@ -180,41 +180,41 @@
element.handleEvent(element.EventType.LABEL_CHANGE, {change: testChange});
});
- test('submitchange', function() {
+ test('submitchange', () => {
plugin.on(element.EventType.SUBMIT_CHANGE, throwErrFn);
- plugin.on(element.EventType.SUBMIT_CHANGE, function() { return true; });
+ plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
assert.isTrue(element.canSubmitChange());
assert.isTrue(errorStub.calledOnce);
- plugin.on(element.EventType.SUBMIT_CHANGE, function() { return false; });
- plugin.on(element.EventType.SUBMIT_CHANGE, function() { return true; });
+ plugin.on(element.EventType.SUBMIT_CHANGE, () => { return false; });
+ plugin.on(element.EventType.SUBMIT_CHANGE, () => { return true; });
assert.isFalse(element.canSubmitChange());
assert.isTrue(errorStub.calledTwice);
});
- test('versioning', function() {
- var callback = sandbox.spy();
+ test('versioning', () => {
+ const callback = sandbox.spy();
Gerrit.install(callback, '0.0pre-alpha');
assert(callback.notCalled);
});
- test('getAccount', function(done) {
- Gerrit.getLoggedIn().then(function(loggedIn) {
+ test('getAccount', done => {
+ Gerrit.getLoggedIn().then(loggedIn => {
assert.isTrue(loggedIn);
done();
});
});
- test('_setPluginsCount', function(done) {
+ test('_setPluginsCount', done => {
stub('gr-reporting', {
- pluginsLoaded: function() {
+ pluginsLoaded() {
assert.equal(Gerrit._pluginsPending, 0);
done();
- }
+ },
});
Gerrit._setPluginsCount(0);
});
- test('_arePluginsLoaded', function() {
+ test('_arePluginsLoaded', () => {
assert.isTrue(Gerrit._arePluginsLoaded());
Gerrit._setPluginsCount(1);
assert.isFalse(Gerrit._arePluginsLoaded());
@@ -222,12 +222,12 @@
assert.isTrue(Gerrit._arePluginsLoaded());
});
- test('_pluginInstalled', function(done) {
+ test('_pluginInstalled', done => {
stub('gr-reporting', {
- pluginsLoaded: function() {
+ pluginsLoaded() {
assert.equal(Gerrit._pluginsPending, 0);
done();
- }
+ },
});
Gerrit._setPluginsCount(2);
Gerrit._pluginInstalled();
@@ -235,34 +235,34 @@
Gerrit._pluginInstalled();
});
- test('install calls _pluginInstalled', function() {
+ test('install calls _pluginInstalled', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
- Gerrit.install(function(p) { plugin = p; }, '0.1',
+ Gerrit.install(p => { plugin = p; }, '0.1',
'http://test.com/plugins/testplugin/static/test.js');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
- test('install calls _pluginInstalled on error', function() {
+ test('install calls _pluginInstalled on error', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
- Gerrit.install(function() {}, '0.0pre-alpha');
+ Gerrit.install(() => {}, '0.0pre-alpha');
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
- test('installGwt calls _pluginInstalled', function() {
+ test('installGwt calls _pluginInstalled', () => {
sandbox.stub(Gerrit, '_pluginInstalled');
Gerrit.installGwt();
assert.isTrue(Gerrit._pluginInstalled.calledOnce);
});
- test('installGwt returns a stub object', function() {
- var plugin = Gerrit.installGwt();
+ test('installGwt returns a stub object', () => {
+ const plugin = Gerrit.installGwt();
sandbox.stub(console, 'warn');
assert.isAbove(Object.keys(plugin).length, 0);
- Object.keys(plugin).forEach(function(name) {
+ for (const name of Object.keys(plugin)) {
console.warn.reset();
plugin[name]();
assert.isTrue(console.warn.calledOnce);
- });
+ }
});
});
</script>
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js
index 402b371..a84eedd 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-public-js-api.js
@@ -14,17 +14,17 @@
(function(window) {
'use strict';
- var warnNotSupported = function(opt_name) {
+ const warnNotSupported = function(opt_name) {
console.warn('Plugin API method ' + (opt_name || '') + ' is not supported');
};
- var stubbedMethods = ['_loadedGwt', 'screen', 'settingsScreen', 'panel'];
- var GWT_PLUGIN_STUB = {};
- stubbedMethods.forEach(function(name) {
+ const stubbedMethods = ['_loadedGwt', 'screen', 'settingsScreen', 'panel'];
+ const GWT_PLUGIN_STUB = {};
+ for (const name of stubbedMethods) {
GWT_PLUGIN_STUB[name] = warnNotSupported.bind(null, name);
- });
+ }
- var API_VERSION = '0.1';
+ const API_VERSION = '0.1';
// GWT JSNI uses $wnd to refer to window.
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
@@ -38,7 +38,7 @@
}
this._url = new URL(opt_url);
- if (this._url.pathname.indexOf('/plugins') !== 0) {
+ if (!this._url.pathname.startsWith('/plugins')) {
console.warn('Plugin not being loaded from /plugins base path:',
this._url.href, '— Unable to determine name.');
return;
@@ -54,14 +54,14 @@
return this._name;
};
- Plugin.prototype.registerStyleModule =
- function(stylingEndpointName, moduleName) {
+ Plugin.prototype.registerStyleModule = function(stylingEndpointName,
+ moduleName) {
if (!Gerrit._styleModules[stylingEndpointName]) {
Gerrit._styleModules[stylingEndpointName] = [];
}
Gerrit._styleModules[stylingEndpointName].push({
pluginUrl: this._url,
- moduleName: moduleName,
+ moduleName,
});
};
@@ -87,7 +87,7 @@
Plugin._sharedAPIElement.Element.REPLY_DIALOG));
};
- var Gerrit = window.Gerrit || {};
+ const Gerrit = window.Gerrit || {};
// Number of plugins to initialize, -1 means 'not yet known'.
Gerrit._pluginsPending = -1;
@@ -102,12 +102,13 @@
Gerrit.css = function(rulesStr) {
if (!Gerrit._customStyleSheet) {
- var styleEl = document.createElement('style');
+ const styleEl = document.createElement('style');
document.head.appendChild(styleEl);
Gerrit._customStyleSheet = styleEl.sheet;
}
- var name = '__pg_js_api_class_' + Gerrit._customStyleSheet.cssRules.length;
+ const name = '__pg_js_api_class_' +
+ Gerrit._customStyleSheet.cssRules.length;
Gerrit._customStyleSheet.insertRule('.' + name + '{' + rulesStr + '}', 0);
return name;
};
@@ -121,9 +122,9 @@
}
// TODO(andybons): Polyfill currentScript for IE10/11 (edge supports it).
- var src = opt_src || (document.currentScript &&
+ const src = opt_src || (document.currentScript &&
document.currentScript.src || document.currentScript.baseURI);
- var plugin = new Plugin(src);
+ const plugin = new Plugin(src);
try {
callback(plugin);
} catch (e) {
@@ -155,7 +156,7 @@
if (Gerrit._arePluginsLoaded()) {
Gerrit._allPluginsPromise = Promise.resolve();
} else {
- Gerrit._allPluginsPromise = new Promise(function(resolve) {
+ Gerrit._allPluginsPromise = new Promise(resolve => {
Gerrit._resolveAllPluginsLoaded = resolve;
});
}