ES6ify gr-app
Bug: Issue 6179
Change-Id: I51601a12071f83ac042957510c3ba871344f3a98
diff --git a/polygerrit-ui/app/elements/gr-app-it_test.html b/polygerrit-ui/app/elements/gr-app-it_test.html
index 66b0f8f..67c5139 100644
--- a/polygerrit-ui/app/elements/gr-app-it_test.html
+++ b/polygerrit-ui/app/elements/gr-app-it_test.html
@@ -33,11 +33,11 @@
</test-fixture>
<script>
- suite('gr-app integration tests', function() {
- var sandbox;
- var element;
+ suite('gr-app integration tests', () => {
+ let sandbox;
+ let element;
- setup(function(done) {
+ setup(done => {
sandbox = sinon.sandbox.create();
stub('gr-reporting', {
appStarted: sandbox.stub(),
@@ -46,46 +46,46 @@
_getTopContent: sinon.stub(),
});
stub('gr-rest-api-interface', {
- getAccount: function() { return Promise.resolve(null); },
- getAccountCapabilities: function() { return Promise.resolve({}); },
- getConfig: function() {
+ getAccount() { return Promise.resolve(null); },
+ getAccountCapabilities() { return Promise.resolve({}); },
+ getConfig() {
return Promise.resolve({
gerrit: {web_uis: ['GWT', 'POLYGERRIT']},
plugin: {
js_resource_paths: [],
html_resource_paths: [
- new URL('test/plugin.html', window.location.href).toString()
- ]
+ new URL('test/plugin.html', window.location.href).toString(),
+ ],
},
});
},
- getVersion: function() { return Promise.resolve(42); },
- getLoggedIn: function() { return Promise.resolve(false); },
+ getVersion() { return Promise.resolve(42); },
+ getLoggedIn() { return Promise.resolve(false); },
});
element = fixture('element');
- var importSpy = sandbox.spy(element.$.externalStyle, '_import');
- Gerrit.awaitPluginsLoaded().then(function() {
- Promise.all(importSpy.returnValues).then(function() {
+ const importSpy = sandbox.spy(element.$.externalStyle, '_import');
+ Gerrit.awaitPluginsLoaded().then(() => {
+ Promise.all(importSpy.returnValues).then(() => {
flush(done);
});
});
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
});
- test('applies --primary-text-color', function() {
+ test('applies --primary-text-color', () => {
assert.equal(
element.getComputedStyleValue('--primary-text-color'), '#F00BAA');
});
- test('applies --header-background-color', function() {
+ test('applies --header-background-color', () => {
assert.equal(element.getComputedStyleValue('--header-background-color'),
'#F01BAA');
});
- test('applies --footer-background-color', function() {
+ test('applies --footer-background-color', () => {
assert.equal(element.getComputedStyleValue('--footer-background-color'),
'#F02BAA');
});
diff --git a/polygerrit-ui/app/elements/gr-app.js b/polygerrit-ui/app/elements/gr-app.js
index 90f641d..70ad03d 100644
--- a/polygerrit-ui/app/elements/gr-app.js
+++ b/polygerrit-ui/app/elements/gr-app.js
@@ -34,7 +34,7 @@
params: Object,
keyEventTarget: {
type: Object,
- value: function() { return document.body; },
+ value() { return document.body; },
},
_account: {
@@ -73,18 +73,18 @@
'?': '_showKeyboardShortcuts',
},
- ready: function() {
+ ready() {
this.$.router.start();
- this.$.restAPI.getAccount().then(function(account) {
+ this.$.restAPI.getAccount().then(account => {
this._account = account;
- }.bind(this));
- this.$.restAPI.getConfig().then(function(config) {
+ });
+ this.$.restAPI.getConfig().then(config => {
this._serverConfig = config;
- }.bind(this));
- this.$.restAPI.getVersion().then(function(version) {
+ });
+ this.$.restAPI.getVersion().then(version => {
this._version = version;
- }.bind(this));
+ });
this.$.reporting.appStarted();
this._viewState = {
@@ -107,7 +107,7 @@
};
},
- _accountChanged: function(account) {
+ _accountChanged(account) {
if (!account) { return; }
// Preferences are cached when a user is logged in; warm them.
@@ -117,7 +117,7 @@
this._account && this._account._account_id || null;
},
- _viewChanged: function(view) {
+ _viewChanged(view) {
this.$.errorView.hidden = true;
this.set('_showChangeListView', view === 'gr-change-list-view');
this.set('_showDashboardView', view === 'gr-dashboard-view');
@@ -131,69 +131,69 @@
}
},
- _loginTapHandler: function(e) {
+ _loginTapHandler(e) {
e.preventDefault();
page.show('/login/' + encodeURIComponent(
window.location.pathname + window.location.hash));
},
// Argument used for binding update only.
- _computeLoggedIn: function(account) {
+ _computeLoggedIn(account) {
return !!(account && Object.keys(account).length > 0);
},
- _computeShowGwtUiLink: function(config) {
- return config.gerrit.web_uis &&
- config.gerrit.web_uis.indexOf('GWT') !== -1;
+ _computeShowGwtUiLink(config) {
+ return config.gerrit.web_uis && config.gerrit.web_uis.includes('GWT');
},
- _handlePageError: function(e) {
- [
+ _handlePageError(e) {
+ const props = [
'_showChangeListView',
'_showDashboardView',
'_showChangeView',
'_showDiffView',
'_showSettingsView',
- ].forEach(function(showProp) {
+ ];
+ for (const showProp of props) {
this.set(showProp, false);
- }.bind(this));
+ }
this.$.errorView.hidden = false;
- var response = e.detail.response;
- var err = {text: [response.status, response.statusText].join(' ')};
+ const response = e.detail.response;
+ const err = {text: [response.status, response.statusText].join(' ')};
if (response.status === 404) {
err.emoji = '¯\\_(ツ)_/¯';
this._lastError = err;
} else {
err.emoji = 'o_O';
- response.text().then(function(text) {
+ response.text().then(text => {
err.moreInfo = text;
this._lastError = err;
- }.bind(this));
+ });
}
},
- _handleLocationChange: function(e) {
- var hash = e.detail.hash.substring(1);
- var pathname = e.detail.pathname;
- if (pathname.indexOf('/c/') === 0 && parseInt(hash, 10) > 0) {
+ _handleLocationChange(e) {
+ const hash = e.detail.hash.substring(1);
+ let pathname = e.detail.pathname;
+ if (pathname.startsWith('/c/') && parseInt(hash, 10) > 0) {
pathname += '@' + hash;
}
this.set('_path', pathname);
this._handleSearchPageChange();
},
- _handleSearchPageChange: function() {
+ _handleSearchPageChange() {
if (!this.params) {
return;
}
- var viewsToCheck = ['gr-change-list-view', 'gr-dashboard-view'];
- if (viewsToCheck.indexOf(this.params.view) !== -1) {
+ const viewsToCheck = ['gr-change-list-view', 'gr-dashboard-view'];
+ if (viewsToCheck.includes(this.params.view)) {
this.set('_lastSearchPage', location.pathname);
}
},
- _handleTitleChange: function(e) {
+ _handleTitleChange(e) {
if (e.detail.title) {
document.title = e.detail.title + ' · Gerrit Code Review';
} else {
@@ -201,23 +201,23 @@
}
},
- _showKeyboardShortcuts: function(e) {
+ _showKeyboardShortcuts(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
this.$.keyboardShortcuts.open();
},
- _handleKeyboardShortcutDialogClose: function() {
+ _handleKeyboardShortcutDialogClose() {
this.$.keyboardShortcuts.close();
},
- _handleAccountDetailUpdate: function(e) {
+ _handleAccountDetailUpdate(e) {
this.$.mainHeader.reload();
if (this.params.view === 'gr-settings-view') {
this.$$('gr-settings-view').reloadAccountDetail();
}
},
- _handleRegistrationDialogClose: function(e) {
+ _handleRegistrationDialogClose(e) {
this.params.justRegistered = false;
this.$.registration.close();
},
diff --git a/polygerrit-ui/app/elements/gr-app_test.html b/polygerrit-ui/app/elements/gr-app_test.html
index dbe3423..e25869b 100644
--- a/polygerrit-ui/app/elements/gr-app_test.html
+++ b/polygerrit-ui/app/elements/gr-app_test.html
@@ -32,11 +32,11 @@
</test-fixture>
<script>
- suite('gr-app tests', function() {
- var sandbox;
- var element;
+ suite('gr-app tests', () => {
+ let sandbox;
+ let element;
- setup(function(done) {
+ setup(done => {
sandbox = sinon.sandbox.create();
stub('gr-reporting', {
appStarted: sandbox.stub(),
@@ -45,43 +45,43 @@
_getTopContent: sinon.stub(),
});
stub('gr-rest-api-interface', {
- getAccount: function() { return Promise.resolve({}); },
- getAccountCapabilities: function() { return Promise.resolve({}); },
- getConfig: function() {
+ getAccount() { return Promise.resolve({}); },
+ getAccountCapabilities() { return Promise.resolve({}); },
+ getConfig() {
return Promise.resolve({
gerrit: {web_uis: ['GWT', 'POLYGERRIT']},
plugin: {js_resource_paths: []},
});
},
- getPreferences: function() { return Promise.resolve({my: []}); },
- getVersion: function() { return Promise.resolve(42); },
- probePath: function() { return Promise.resolve(42); },
+ getPreferences() { return Promise.resolve({my: []}); },
+ getVersion() { return Promise.resolve(42); },
+ probePath() { return Promise.resolve(42); },
});
element = fixture('basic');
flush(done);
});
- teardown(function() {
+ teardown(() => {
sandbox.restore();
});
- test('reporting', function() {
+ test('reporting', () => {
assert.isTrue(element.$.reporting.appStarted.calledOnce);
});
- test('location change updates gwt footer', function(done) {
+ test('location change updates gwt footer', done => {
element._path = '/test/path';
- flush(function() {
- var gwtLink = element.$$('#gwtLink');
+ flush(() => {
+ const gwtLink = element.$$('#gwtLink');
assert.equal(gwtLink.href, 'http://' + location.host +
element.getBaseUrl() + '/?polygerrit=0#/test/path');
done();
});
});
- test('_handleLocationChange handles hashes', function(done) {
- var curLocation = {
+ test('_handleLocationChange handles hashes', done => {
+ const curLocation = {
pathname: '/c/1/1/testfile.txt',
hash: '#2',
host: location.host,
@@ -89,20 +89,20 @@
sandbox.stub(element, '_handleSearchPageChange');
element._handleLocationChange({detail: curLocation});
- flush(function() {
- var gwtLink = element.$$('#gwtLink');
+ flush(() => {
+ const gwtLink = element.$$('#gwtLink');
assert.equal(
- gwtLink.href,
- 'http://' + location.host + element.getBaseUrl() +
+ gwtLink.href,
+ 'http://' + location.host + element.getBaseUrl() +
'/?polygerrit=0#/c/1/1/testfile.txt@2'
);
done();
});
});
- test('passes config to gr-plugin-host', function(done) {
- element.$.restAPI.getConfig.lastCall.returnValue.then(function(config) {
- var pluginConfig = config.plugin;
+ test('passes config to gr-plugin-host', done => {
+ element.$.restAPI.getConfig.lastCall.returnValue.then(config => {
+ const pluginConfig = config.plugin;
assert.deepEqual(element.$.plugins.config, pluginConfig);
done();
});