Merge changes I433937b4,I3b1a8830

* changes:
  Enable `arrow-body-style` with as-needed
  Enable `no-confusing-arrow` and `newline-per-chained-call`
This commit is contained in:
Ben Rohlfs 2020-01-10 13:53:23 +00:00 committed by Gerrit Code Review
commit 5909ea1fed
130 changed files with 1395 additions and 1370 deletions

View File

@ -21,6 +21,9 @@
"flushAsynchronousOperations": false
},
"rules": {
"no-confusing-arrow": "error",
"newline-per-chained-call": ["error", { "ignoreChainWithDepth": 2 }],
"arrow-body-style": ["error", "as-needed", { "requireReturnForObjectLiteral": true }],
"arrow-parens": ["error", "as-needed"],
"block-spacing": ["error", "always"],
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],

View File

@ -139,15 +139,17 @@ limitations under the License.
*/
toSortedArray(obj) {
if (!obj) { return []; }
return Object.keys(obj).map(key => {
return {
id: key,
value: obj[key],
};
}).sort((a, b) => {
// Since IDs are strings, use localeCompare.
return a.id.localeCompare(b.id);
});
return Object.keys(obj)
.map(key => {
return {
id: key,
value: obj[key],
};
})
.sort((a, b) =>
// Since IDs are strings, use localeCompare.
a.id.localeCompare(b.id)
);
},
};

View File

@ -64,12 +64,11 @@ limitations under the License.
getAdminMenuLinks, opt_options));
}
return getAccountCapabilities()
.then(capabilities => {
return this._filterLinks(link => {
return !link.capability ||
capabilities.hasOwnProperty(link.capability);
}, getAdminMenuLinks, opt_options);
});
.then(capabilities => this._filterLinks(
link => !link.capability
|| capabilities.hasOwnProperty(link.capability),
getAdminMenuLinks,
opt_options));
},
/**
@ -92,15 +91,17 @@ limitations under the License.
const isExernalLink = link => link.url[0] !== '/';
// Append top-level links that are defined by plugins.
links.push(...getAdminMenuLinks().map(link => ({
url: link.url,
name: link.text,
capability: link.capability || null,
noBaseUrl: !isExernalLink(link),
view: null,
viewableToAll: !link.capability,
target: isExernalLink(link) ? '_blank' : null,
})));
links.push(...getAdminMenuLinks().map(link => {
return {
url: link.url,
name: link.text,
capability: link.capability || null,
noBaseUrl: !isExernalLink(link),
view: null,
viewableToAll: !link.capability,
target: isExernalLink(link) ? '_blank' : null,
};
}));
links = links.filter(filterFn);

View File

@ -95,9 +95,8 @@ limitations under the License.
if (expected.pluginGeneratedLinks) {
for (const link of expected.pluginGeneratedLinks) {
const linkMatch = res.links.find(l => {
return (l.url === link.url && l.name === link.text);
});
const linkMatch = res.links
.find(l => (l.url === link.url && l.name === link.text));
assert.isTrue(!!linkMatch);
// External links should open in new tab.
@ -325,7 +324,9 @@ limitations under the License.
let options;
const generatedLinks = [
{text: 'without capability', url: '/without'},
{text: 'with capability', url: '/with', capability: 'pluginCapability'},
{text: 'with capability',
url: '/with',
capability: 'pluginCapability'},
];
menuLinkStub.returns(generatedLinks);
expected = Object.assign(expected, {

View File

@ -46,9 +46,7 @@ limitations under the License.
* @return {!Array}
*/
getComplementColumns(columns) {
return this.columnNames.filter(column => {
return !columns.includes(column);
});
return this.columnNames.filter(column => !columns.includes(column));
},
/**

View File

@ -124,9 +124,9 @@ limitations under the License.
// Map a normal patchNum to 2 * (patchNum - 1) + 1... I.e. 1 -> 1,
// 2 -> 3, 3 -> 5, etc.
// Map an edit to the patchNum of parent*2... I.e. edit on 2 -> 4.
const num = r => r._number === Gerrit.PatchSetBehavior.EDIT_NAME ?
const num = r => (r._number === Gerrit.PatchSetBehavior.EDIT_NAME ?
2 * editParent :
2 * (r._number - 1) + 1;
2 * (r._number - 1) + 1);
return revisions.sort((a, b) => num(b) - num(a));
},
@ -150,9 +150,8 @@ limitations under the License.
if (!change) { return []; }
let patchNums = [];
if (change.revisions && Object.keys(change.revisions).length) {
const revisions = Object.keys(change.revisions).map(sha => {
return Object.assign({sha}, change.revisions[sha]);
});
const revisions = Object.keys(change.revisions)
.map(sha => Object.assign({sha}, change.revisions[sha]));
patchNums =
Gerrit.PatchSetBehavior.sortRevisions(revisions)
.map(e => {

View File

@ -170,9 +170,7 @@ limitations under the License.
messages: [],
work_in_progress: initialWip,
};
const revs = Object.keys(tagsByRevision).sort((a, b) => {
return a - b;
});
const revs = Object.keys(tagsByRevision).sort((a, b) => a - b);
for (const rev of revs) {
for (const tag of tagsByRevision[rev]) {
change.messages.push({
@ -190,9 +188,7 @@ limitations under the License.
}
const verifier = {
assertWip(revision, expectedWip) {
const patchNum = patchNums.find(patchNum => {
return patchNum.num == revision;
});
const patchNum = patchNums.find(patchNum => patchNum.num == revision);
if (!patchNum) {
assert.fail('revision ' + revision + ' not found');
}

View File

@ -146,9 +146,8 @@
allPermissions = labelOptions.concat(
this.toSortedArray(this.permissionValues));
}
return allPermissions.filter(permission => {
return !this.section.value.permissions[permission.id];
});
return allPermissions
.filter(permission => !this.section.value.permissions[permission.id]);
}
_computeHideEditClass(section) {
@ -248,7 +247,8 @@
_computeSectionClass(editing, canUpload, ownerOf, editingRef, deleted) {
const classList = [];
if (editing && this._isEditEnabled(canUpload, ownerOf, this.section.id)) {
if (editing
&& this._isEditEnabled(canUpload, ownerOf, this.section.id)) {
classList.push('editing');
}
if (editingRef) {

View File

@ -127,9 +127,10 @@ limitations under the License.
suite('filter', () => {
test('_paramsChanged', done => {
sandbox.stub(element.$.restAPI, 'getGroups', () => {
return Promise.resolve(groups);
});
sandbox.stub(
element.$.restAPI,
'getGroups',
() => Promise.resolve(groups));
const value = {
filter: 'test',
offset: 25,

View File

@ -101,13 +101,15 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
})
);
element.reload().then(() => {
assert.equal(element._filteredLinks.length, 3);
@ -127,9 +129,11 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({})
);
element.reload().then(() => {
assert.equal(element._filteredLinks.length, 2);
@ -185,13 +189,14 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
}));
element.reload().then(() => {
flushAsynchronousOperations();
assert.equal(Polymer.dom(element.root)
@ -214,13 +219,14 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getAccount').returns(Promise.resolve({
name: 'test-user',
}));
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
}));
element.reload().then(() => {
flushAsynchronousOperations();
assert.equal(element._filteredLinks.length, 3);
@ -239,16 +245,18 @@ limitations under the License.
});
test('Nav is reloaded when repo changes', () => {
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(element.$.restAPI, 'getAccount', () => {
return Promise.resolve({_id: 1});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
}));
sandbox.stub(
element.$.restAPI,
'getAccount',
() => Promise.resolve({_id: 1}));
sandbox.stub(element, 'reload');
element.params = {repo: 'Test Repo', adminView: 'gr-repo'};
assert.equal(element.reload.callCount, 1);
@ -259,16 +267,18 @@ limitations under the License.
test('Nav is reloaded when group changes', () => {
sandbox.stub(element, '_computeGroupName');
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(element.$.restAPI, 'getAccount', () => {
return Promise.resolve({_id: 1});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
}));
sandbox.stub(
element.$.restAPI,
'getAccount',
() => Promise.resolve({_id: 1}));
sandbox.stub(element, 'reload');
element.params = {groupId: '1', adminView: 'gr-group'};
assert.equal(element.reload.callCount, 1);
@ -304,7 +314,9 @@ limitations under the License.
assert.isOk(element.$$('.mainHeader'));
element._subsectionLinks = undefined;
flushAsynchronousOperations();
assert.equal(getComputedStyle(element.$$('.mainHeader')).display, 'none');
assert.equal(
getComputedStyle(element.$$('.mainHeader')).display,
'none');
});
test('Dropdown only triggers navigation on explicit select', done => {
@ -314,16 +326,18 @@ limitations under the License.
view: Gerrit.Nav.View.REPO,
detail: Gerrit.Nav.RepoDetailView.ACCESS,
};
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(element.$.restAPI, 'getAccount', () => {
return Promise.resolve({_id: 1});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
}));
sandbox.stub(
element.$.restAPI,
'getAccount',
() => Promise.resolve({_id: 1}));
flushAsynchronousOperations();
const expectedFilteredLinks = [
{
@ -475,16 +489,18 @@ limitations under the License.
suite('_computeSelectedClass', () => {
setup(() => {
sandbox.stub(element.$.restAPI, 'getAccountCapabilities', () => {
return Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
});
});
sandbox.stub(element.$.restAPI, 'getAccount', () => {
return Promise.resolve({_id: 1});
});
sandbox.stub(
element.$.restAPI,
'getAccountCapabilities',
() => Promise.resolve({
createGroup: true,
createProject: true,
viewPlugins: true,
}));
sandbox.stub(
element.$.restAPI,
'getAccount',
() => Promise.resolve({_id: 1}));
return element.reload();
});

View File

@ -81,9 +81,7 @@ limitations under the License.
};
const saveStub = sandbox.stub(element.$.restAPI,
'createChange', () => {
return Promise.resolve({});
});
'createChange', () => Promise.resolve({}));
element.branch = 'test-branch';
element.topic = 'test-topic';
@ -109,9 +107,7 @@ limitations under the License.
configured_value: 'TRUE',
inherited_value: false,
};
sandbox.stub(element, '_formatBooleanString', () => {
return Promise.resolve(true);
});
sandbox.stub(element, '_formatBooleanString', () => Promise.resolve(true));
flushAsynchronousOperations();
const configInputObj = {
@ -123,9 +119,7 @@ limitations under the License.
};
const saveStub = sandbox.stub(element.$.restAPI,
'createChange', () => {
return Promise.resolve({});
});
'createChange', () => Promise.resolve({}));
element.branch = 'test-branch';
element.topic = 'test-topic';

View File

@ -56,9 +56,10 @@ limitations under the License.
});
test('branch created', done => {
sandbox.stub(element.$.restAPI, 'createRepoBranch', () => {
return Promise.resolve({});
});
sandbox.stub(
element.$.restAPI,
'createRepoBranch',
() => Promise.resolve({}));
assert.isFalse(element.hasNewItemName);
@ -77,9 +78,10 @@ limitations under the License.
});
test('tag created', done => {
sandbox.stub(element.$.restAPI, 'createRepoTag', () => {
return Promise.resolve({});
});
sandbox.stub(
element.$.restAPI,
'createRepoTag',
() => Promise.resolve({}));
assert.isFalse(element.hasNewItemName);
@ -98,9 +100,10 @@ limitations under the License.
});
test('tag created with annotations', done => {
sandbox.stub(element.$.restAPI, 'createRepoTag', () => {
return Promise.resolve({});
});
sandbox.stub(
element.$.restAPI,
'createRepoTag',
() => Promise.resolve({}));
assert.isFalse(element.hasNewItemName);

View File

@ -66,9 +66,7 @@ limitations under the License.
};
const saveStub = sandbox.stub(element.$.restAPI,
'createRepo', () => {
return Promise.resolve({});
});
'createRepo', () => Promise.resolve({}));
assert.isFalse(element.hasNewRepoName);

View File

@ -153,9 +153,10 @@ limitations under the License.
element = fixture('basic');
sandbox.stub(element, 'getBaseUrl').returns('https://test/site');
element.groupId = 1;
groupStub = sandbox.stub(element.$.restAPI, 'getGroupConfig', () => {
return Promise.resolve(groups);
});
groupStub = sandbox.stub(
element.$.restAPI,
'getGroupConfig',
() => Promise.resolve(groups));
return element._loadGroupDetails();
});
@ -181,9 +182,7 @@ limitations under the License.
const memberName = 'test-admin';
const saveStub = sandbox.stub(element.$.restAPI, 'saveGroupMembers',
() => {
return Promise.resolve({});
});
() => Promise.resolve({}));
const button = element.$.saveGroupMember;
@ -208,9 +207,7 @@ limitations under the License.
const includedGroupName = 'testName';
const saveIncludedGroupStub = sandbox.stub(
element.$.restAPI, 'saveIncludedGroup', () => {
return Promise.resolve({});
});
element.$.restAPI, 'saveIncludedGroup', () => Promise.resolve({}));
const button = element.$.saveIncludedGroups;
@ -248,35 +245,31 @@ limitations under the License.
});
});
test('_getAccountSuggestions empty', () => {
return element._getAccountSuggestions('nonexistent').then(accounts => {
assert.equal(accounts.length, 0);
});
});
test('_getAccountSuggestions empty', () => element
._getAccountSuggestions('nonexistent').then(accounts => {
assert.equal(accounts.length, 0);
}));
test('_getAccountSuggestions non-empty', () => {
return element._getAccountSuggestions('test-').then(accounts => {
assert.equal(accounts.length, 3);
assert.equal(accounts[0].name,
'test-account <test.account@example.com>');
assert.equal(accounts[1].name, 'test-admin <test.admin@example.com>');
assert.equal(accounts[2].name, 'test-git');
});
});
test('_getAccountSuggestions non-empty', () => element
._getAccountSuggestions('test-').then(accounts => {
assert.equal(accounts.length, 3);
assert.equal(accounts[0].name,
'test-account <test.account@example.com>');
assert.equal(accounts[1].name, 'test-admin <test.admin@example.com>');
assert.equal(accounts[2].name, 'test-git');
}));
test('_getGroupSuggestions empty', () => {
return element._getGroupSuggestions('nonexistent').then(groups => {
assert.equal(groups.length, 0);
});
});
test('_getGroupSuggestions empty', () => element
._getGroupSuggestions('nonexistent').then(groups => {
assert.equal(groups.length, 0);
}));
test('_getGroupSuggestions non-empty', () => {
return element._getGroupSuggestions('test').then(groups => {
assert.equal(groups.length, 2);
assert.equal(groups[0].name, 'test-admin');
assert.equal(groups[1].name, 'test/Administrator (admin)');
});
});
test('_getGroupSuggestions non-empty', () => element
._getGroupSuggestions('test').then(groups => {
assert.equal(groups.length, 2);
assert.equal(groups[0].name, 'test-admin');
assert.equal(groups[1].name, 'test/Administrator (admin)');
}));
test('_computeHideItemClass returns string for admin', () => {
const admin = true;

View File

@ -56,9 +56,11 @@ limitations under the License.
getLoggedIn() { return Promise.resolve(true); },
});
element = fixture('basic');
groupStub = sandbox.stub(element.$.restAPI, 'getGroupConfig', () => {
return Promise.resolve(group);
});
groupStub = sandbox.stub(
element.$.restAPI,
'getGroupConfig',
() => Promise.resolve(group)
);
});
teardown(() => {
@ -74,9 +76,10 @@ limitations under the License.
});
test('default values are populated with internal group', done => {
sandbox.stub(element.$.restAPI, 'getIsGroupOwner', () => {
return Promise.resolve(true);
});
sandbox.stub(
element.$.restAPI,
'getIsGroupOwner',
() => Promise.resolve(true));
element.groupId = 1;
element._loadGroup().then(() => {
assert.isTrue(element._groupIsInternal);
@ -89,12 +92,14 @@ limitations under the License.
const groupExternal = Object.assign({}, group);
groupExternal.id = 'external-group-id';
groupStub.restore();
groupStub = sandbox.stub(element.$.restAPI, 'getGroupConfig', () => {
return Promise.resolve(groupExternal);
});
sandbox.stub(element.$.restAPI, 'getIsGroupOwner', () => {
return Promise.resolve(true);
});
groupStub = sandbox.stub(
element.$.restAPI,
'getGroupConfig',
() => Promise.resolve(groupExternal));
sandbox.stub(
element.$.restAPI,
'getIsGroupOwner',
() => Promise.resolve(true));
element.groupId = 1;
element._loadGroup().then(() => {
assert.isFalse(element._groupIsInternal);
@ -114,13 +119,15 @@ limitations under the License.
element._groupName = groupName;
element._groupOwner = true;
sandbox.stub(element.$.restAPI, 'getIsGroupOwner', () => {
return Promise.resolve(true);
});
sandbox.stub(
element.$.restAPI,
'getIsGroupOwner',
() => Promise.resolve(true));
sandbox.stub(element.$.restAPI, 'saveGroupName', () => {
return Promise.resolve({status: 200});
});
sandbox.stub(
element.$.restAPI,
'saveGroupName',
() => Promise.resolve({status: 200}));
const button = element.$.inputUpdateNameBtn;
@ -154,9 +161,10 @@ limitations under the License.
test('test for undefined group name', done => {
groupStub.restore();
sandbox.stub(element.$.restAPI, 'getGroupConfig', () => {
return Promise.resolve({});
});
sandbox.stub(
element.$.restAPI,
'getGroupConfig',
() => Promise.resolve({}));
assert.isUndefined(element.groupId);

View File

@ -209,9 +209,8 @@
_computeLabelValues(values) {
const valuesArr = [];
const keys = Object.keys(values).sort((a, b) => {
return parseInt(a, 10) - parseInt(b, 10);
});
const keys = Object.keys(values)
.sort((a, b) => parseInt(a, 10) - parseInt(b, 10));
for (const key of keys) {
let text = values[key];
@ -255,9 +254,8 @@
});
}
// Does not return groups in which we already have rules for.
return groups.filter(group => {
return !this._groupsWithRules[group.value.id];
});
return groups
.filter(group => !this._groupsWithRules[group.value.id]);
});
}
@ -268,7 +266,8 @@
_handleAddRuleItem(e) {
// The group id is encoded, but have to decode in order for the access
// API to work as expected.
const groupId = decodeURIComponent(e.detail.value.id).replace(/\+/g, ' ');
const groupId = decodeURIComponent(e.detail.value.id)
.replace(/\+/g, ' ');
this.set(['permission', 'value', 'rules', groupId], {});
// Purposely don't recompute sorted array so that the newly added rule

View File

@ -125,9 +125,10 @@ limitations under the License.
suite('filter', () => {
test('_paramsChanged', done => {
sandbox.stub(element.$.restAPI, 'getPlugins', () => {
return Promise.resolve(plugins);
});
sandbox.stub(
element.$.restAPI,
'getPlugins',
() => Promise.resolve(plugins));
const value = {
filter: 'test',
offset: 25,

View File

@ -579,8 +579,9 @@ limitations under the License.
remove: {},
};
element.$$('gr-access-section').$$('gr-permission')._handleAddRuleItem(
{detail: {value: {id: 'Maintainers'}}});
element.$$('gr-access-section').$$('gr-permission')
._handleAddRuleItem(
{detail: {value: {id: 'Maintainers'}}});
flushAsynchronousOperations();
assert.deepEqual(element._computeAddAndRemove(), expectedInput);

View File

@ -44,9 +44,10 @@ limitations under the License.
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
repoStub = sandbox.stub(element.$.restAPI, 'getProjectConfig', () => {
return Promise.resolve({});
});
repoStub = sandbox.stub(
element.$.restAPI,
'getProjectConfig',
() => Promise.resolve({}));
});
teardown(() => {

View File

@ -54,7 +54,7 @@
// Group by ref and sort by id.
const dashboards = res.concat.apply([], res).sort((a, b) =>
a.id < b.id ? -1 : 1);
(a.id < b.id ? -1 : 1));
const dashboardsByRef = {};
dashboards.forEach(d => {
if (!dashboardsByRef[d.ref]) {
@ -64,12 +64,13 @@
});
const dashboardBuilder = [];
Object.keys(dashboardsByRef).sort().forEach(ref => {
dashboardBuilder.push({
section: ref,
dashboards: dashboardsByRef[ref],
});
});
Object.keys(dashboardsByRef).sort()
.forEach(ref => {
dashboardBuilder.push({
section: ref,
dashboards: dashboardsByRef[ref],
});
});
this._dashboards = dashboardBuilder;
this._loading = false;

View File

@ -297,9 +297,10 @@ limitations under the License.
suite('filter', () => {
test('_paramsChanged', done => {
sandbox.stub(element.$.restAPI, 'getRepoBranches', () => {
return Promise.resolve(branches);
});
sandbox.stub(
element.$.restAPI,
'getRepoBranches',
() => Promise.resolve(branches));
const params = {
detail: 'branches',
repo: 'test',
@ -480,9 +481,10 @@ limitations under the License.
suite('filter', () => {
test('_paramsChanged', done => {
sandbox.stub(element.$.restAPI, 'getRepoTags', () => {
return Promise.resolve(tags);
});
sandbox.stub(
element.$.restAPI,
'getRepoTags',
() => Promise.resolve(tags));
const params = {
repo: 'test',
detail: 'tags',

View File

@ -127,9 +127,7 @@ limitations under the License.
});
test('_paramsChanged', done => {
sandbox.stub(element.$.restAPI, 'getRepos', () => {
return Promise.resolve(repos);
});
sandbox.stub(element.$.restAPI, 'getRepos', () => Promise.resolve(repos));
const value = {
filter: 'test',
offset: 25,

View File

@ -49,7 +49,8 @@
return [];
}
const {config} = dataRecord.base;
return Object.keys(config).map(_key => ({_key, info: config[_key]}));
return Object.keys(config)
.map(_key => { return {_key, info: config[_key]}; });
}
_isArray(type) {

View File

@ -136,7 +136,7 @@
const pluginConfig = configRecord.base;
return Object.keys(pluginConfig)
.map(name => ({name, config: pluginConfig[name]}));
.map(name => { return {name, config: pluginConfig[name]}; });
}
_loadRepo() {

View File

@ -120,9 +120,10 @@ limitations under the License.
},
});
element = fixture('basic');
repoStub = sandbox.stub(element.$.restAPI, 'getProjectConfig', () => {
return Promise.resolve(repoConf);
});
repoStub = sandbox.stub(
element.$.restAPI,
'getProjectConfig',
() => Promise.resolve(repoConf));
});
teardown(() => {
@ -187,12 +188,11 @@ limitations under the License.
test('form defaults to read only when logged in and not admin', done => {
element.repo = REPO;
sandbox.stub(element, '_getLoggedIn', () => {
return Promise.resolve(true);
});
sandbox.stub(element.$.restAPI, 'getRepoAccess', () => {
return Promise.resolve({'test-repo': {}});
});
sandbox.stub(element, '_getLoggedIn', () => Promise.resolve(true));
sandbox.stub(
element.$.restAPI,
'getRepoAccess',
() => Promise.resolve({'test-repo': {}}));
element._loadRepo().then(() => {
assert.isTrue(element._readOnly);
done();
@ -280,12 +280,11 @@ limitations under the License.
suite('admin', () => {
setup(() => {
element.repo = REPO;
sandbox.stub(element, '_getLoggedIn', () => {
return Promise.resolve(true);
});
sandbox.stub(element.$.restAPI, 'getRepoAccess', () => {
return Promise.resolve({'test-repo': {is_owner: true}});
});
sandbox.stub(element, '_getLoggedIn', () => Promise.resolve(true));
sandbox.stub(
element.$.restAPI,
'getRepoAccess',
() => Promise.resolve({'test-repo': {is_owner: true}}));
});
test('all form elements are enabled', done => {
@ -308,14 +307,13 @@ limitations under the License.
});
});
test('inherited submit type value is calculated correctly', () => {
return element._loadRepo().then(() => {
const sel = element.$.submitTypeSelect;
assert.equal(sel.bindValue, 'INHERIT');
assert.equal(
sel.nativeSelect.options[0].text, 'Inherit (Merge if necessary)');
});
});
test('inherited submit type value is calculated correctly', () => element
._loadRepo().then(() => {
const sel = element.$.submitTypeSelect;
assert.equal(sel.bindValue, 'INHERIT');
assert.equal(
sel.nativeSelect.options[0].text, 'Inherit (Merge if necessary)');
}));
test('fields update and save correctly', () => {
const configInputObj = {
@ -338,9 +336,7 @@ limitations under the License.
};
const saveStub = sandbox.stub(element.$.restAPI, 'saveRepoConfig'
, () => {
return Promise.resolve({});
});
, () => Promise.resolve({}));
const button = Polymer.dom(element.root).querySelector('gr-button');

View File

@ -121,7 +121,8 @@
} else {
classes['u-gray-background'] = true;
}
return Object.keys(classes).sort().join(' ');
return Object.keys(classes).sort()
.join(' ');
}
_computeLabelValue(change, labelName) {

View File

@ -163,24 +163,26 @@
// in an async so that attachment to the DOM can take place first.
this.async(() => this.fire('title-change', {title: this._query}));
this._getPreferences().then(prefs => {
this._changesPerPage = prefs.changes_per_page;
return this._getChanges();
}).then(changes => {
changes = changes || [];
if (this._query && changes.length === 1) {
for (const query in LookupQueryPatterns) {
if (LookupQueryPatterns.hasOwnProperty(query) &&
this._getPreferences()
.then(prefs => {
this._changesPerPage = prefs.changes_per_page;
return this._getChanges();
})
.then(changes => {
changes = changes || [];
if (this._query && changes.length === 1) {
for (const query in LookupQueryPatterns) {
if (LookupQueryPatterns.hasOwnProperty(query) &&
this._query.match(LookupQueryPatterns[query])) {
this._replaceCurrentLocation(
Gerrit.Nav.getUrlForChange(changes[0]));
return;
this._replaceCurrentLocation(
Gerrit.Nav.getUrlForChange(changes[0]));
return;
}
}
}
}
}
this._changes = changes;
this._loading = false;
});
this._changes = changes;
this._loading = false;
});
}
_loadPreferences() {

View File

@ -234,11 +234,8 @@
_processQuery(query) {
let tokens = query.split(' ');
const invalidTokens = ['limit:', 'age:', '-age:'];
tokens = tokens.filter(token => {
return !invalidTokens.some(invalidToken => {
return token.startsWith(invalidToken);
});
});
tokens = tokens.filter(token => !invalidTokens
.some(invalidToken => token.startsWith(invalidToken)));
return tokens.join(' ');
}

View File

@ -181,12 +181,14 @@
.then(() => {
this._maybeShowDraftsBanner();
this.$.reporting.dashboardDisplayed();
}).catch(err => {
})
.catch(err => {
this.fire('title-change', {
title: title || this._computeTitle(user),
});
console.warn(err);
}).then(() => { this._loading = false; });
})
.then(() => { this._loading = false; });
}
/**
@ -201,9 +203,9 @@
if (!res) { return Promise.resolve(); }
const queries = res.sections
.map(section => section.suffixForDashboard ?
.map(section => (section.suffixForDashboard ?
section.query + ' ' + section.suffixForDashboard :
section.query);
section.query));
if (checkForNewUser) {
queries.push('owner:self limit:1');
@ -216,13 +218,15 @@
const lastResultSet = changes.pop();
this._showNewUserHelp = lastResultSet.length == 0;
}
this._results = changes.map((results, i) => ({
name: res.sections[i].name,
countLabel: this._computeSectionCountLabel(results),
query: res.sections[i].query,
results,
isOutgoing: res.sections[i].isOutgoing,
})).filter((section, i) => i < res.sections.length && (
this._results = changes.map((results, i) => {
return {
name: res.sections[i].name,
countLabel: this._computeSectionCountLabel(results),
query: res.sections[i].query,
results,
isOutgoing: res.sections[i].isOutgoing,
};
}).filter((section, i) => i < res.sections.length && (
!res.sections[i].hideIfEmpty ||
section.results.length));
});

View File

@ -474,16 +474,18 @@
}
this._loading = true;
return this._getRevisionActions().then(revisionActions => {
if (!revisionActions) { return; }
return this._getRevisionActions()
.then(revisionActions => {
if (!revisionActions) { return; }
this.revisionActions = this._updateRebaseAction(revisionActions);
this._handleLoadingComplete();
}).catch(err => {
this.fire('show-alert', {message: ERR_REVISION_ACTIONS});
this._loading = false;
throw err;
});
this.revisionActions = this._updateRebaseAction(revisionActions);
this._handleLoadingComplete();
})
.catch(err => {
this.fire('show-alert', {message: ERR_REVISION_ACTIONS});
this._loading = false;
throw err;
});
}
_handleLoadingComplete() {
@ -515,7 +517,8 @@
label,
__type: type,
__key: ADDITIONAL_ACTION_KEY_PREFIX +
Math.random().toString(36).substr(2),
Math.random().toString(36)
.substr(2),
};
this.push('_additionalActions', action);
return action.__key;
@ -558,9 +561,8 @@
if (type !== ActionType.CHANGE && type !== ActionType.REVISION) {
throw Error(`Invalid action type given: ${type}`);
}
const index = this._actionPriorityOverrides.findIndex(action => {
return action.type === type && action.key === key;
});
const index = this._actionPriorityOverrides
.findIndex(action => action.type === type && action.key === key);
const action = {
type,
key,
@ -723,9 +725,7 @@
}
_getValuesFor(obj) {
return Object.keys(obj).map(key => {
return obj[key];
});
return Object.keys(obj).map(key => obj[key]);
}
_getLabelStatus(label) {
@ -790,9 +790,8 @@
hideQuickApproveAction() {
this._topLevelSecondaryActions =
this._topLevelSecondaryActions.filter(sa => {
return sa.key !== QUICK_APPROVE_ACTION.key;
});
this._topLevelSecondaryActions
.filter(sa => sa.key !== QUICK_APPROVE_ACTION.key);
this._hideQuickApproveAction = true;
}
@ -850,13 +849,13 @@
let additionalActions = (additionalActionsChangeRecord &&
additionalActionsChangeRecord.base) || [];
additionalActions = additionalActions.filter(a => {
return a.__type === type;
}).map(a => {
a.__primary = primaryActionKeys.includes(a.__key);
// Triggers a re-render by ensuring object inequality.
return Object.assign({}, a);
});
additionalActions = additionalActions
.filter(a => a.__type === type)
.map(a => {
a.__primary = primaryActionKeys.includes(a.__key);
// Triggers a re-render by ensuring object inequality.
return Object.assign({}, a);
});
return result.concat(additionalActions).concat(pluginActions);
}
@ -993,9 +992,7 @@
this._showActionDialog(this.$.confirmAbandonDialog);
break;
case QUICK_APPROVE_ACTION.key:
action = this._allActionValues.find(o => {
return o.key === key;
});
action = this._allActionValues.find(o => o.key === key);
this._fireAction(
this._prependSlash(key), action, true, action.payload);
break;
@ -1193,9 +1190,8 @@
}
_getActionOverflowIndex(type, key) {
return this._overflowActions.findIndex(action => {
return action.type === type && action.key === key;
});
return this._overflowActions
.findIndex(action => action.type === type && action.key === key);
}
_setLoadingOnButtonWithKey(type, key) {
@ -1457,9 +1453,8 @@
_getActionPriority(action) {
if (action.__type && action.__key) {
const overrideAction = this._actionPriorityOverrides.find(i => {
return i.type === action.__type && i.key === action.__key;
});
const overrideAction = this._actionPriorityOverrides
.find(i => i.type === action.__type && i.key === action.__key);
if (overrideAction !== undefined) {
return overrideAction.priority;

View File

@ -220,9 +220,8 @@ limitations under the License.
test('delete buttons have explicit labels', done => {
flush(() => {
const deleteItems = element.$.moreActions.items.filter(item => {
return item.id.startsWith('delete');
});
const deleteItems = element.$.moreActions.items
.filter(item => item.id.startsWith('delete'));
assert.equal(deleteItems.length, 1);
assert.notEqual(deleteItems[0].name);
assert.equal(deleteItems[0].name, 'Delete change');
@ -261,7 +260,7 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getFromProjectLookup')
.returns(Promise.resolve('test'));
sandbox.stub(element, 'fetchChangeUpdates',
() => { return Promise.resolve({isLatest: true}); });
() => Promise.resolve({isLatest: true}));
sandbox.stub(element.$.overlay, 'open').returns(Promise.resolve());
element.change = {
revisions: {
@ -284,7 +283,7 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getFromProjectLookup')
.returns(Promise.resolve('test'));
sandbox.stub(element, 'fetchChangeUpdates',
() => { return Promise.resolve({isLatest: true}); });
() => Promise.resolve({isLatest: true}));
sandbox.stub(element.$.overlay, 'open').returns(Promise.resolve());
element.change = {
revisions: {
@ -318,7 +317,7 @@ limitations under the License.
test('submit change with plugin hook', done => {
sandbox.stub(element, '_canSubmitChange',
() => { return false; });
() => false);
const fireActionStub = sandbox.stub(element, '_fireAction');
flush(() => {
const submitButton = element.$$('gr-button[data-action-key="submit"]');
@ -819,9 +818,9 @@ limitations under the License.
};
const newRevertMsg = 'Modified revert msg';
sandbox.stub(element, '_modifyRevertMsg',
() => { return newRevertMsg; });
() => newRevertMsg);
sandbox.stub(element.$.confirmRevertDialog, 'populateRevertMessage',
() => { return 'original msg'; });
() => 'original msg');
flush(() => {
const revertButton =
element.$$('gr-button[data-action-key="revert"]');
@ -837,7 +836,7 @@ limitations under the License.
current_revision: 'abc1234',
};
sandbox.stub(element.$.confirmRevertDialog, 'populateRevertMessage',
() => { return 'original msg'; });
() => 'original msg');
const revertButton = element.$$('gr-button[data-action-key="revert"]');
MockInteractions.tap(revertButton);
@ -1398,15 +1397,13 @@ limitations under the License.
sandbox.stub(element, 'async', fn => fn());
});
const makeGetChange = numTries => {
return () => {
if (numTries === 1) {
return Promise.resolve({_number: 123});
} else {
numTries--;
return Promise.resolve(undefined);
}
};
const makeGetChange = numTries => () => {
if (numTries === 1) {
return Promise.resolve({_number: 123});
} else {
numTries--;
return Promise.resolve(undefined);
}
};
test('succeed', () => {
@ -1457,15 +1454,14 @@ limitations under the License.
'navigateToChange').returns(Promise.resolve(true));
});
test('change action', () => {
return element._send('DELETE', payload, '/endpoint', false, cleanup)
.then(() => {
assert.isFalse(onShowError.called);
assert.isTrue(cleanup.calledOnce);
assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint',
null, payload));
});
});
test('change action', () => element
._send('DELETE', payload, '/endpoint', false, cleanup)
.then(() => {
assert.isFalse(onShowError.called);
assert.isTrue(cleanup.calledOnce);
assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint',
null, payload));
}));
suite('show revert submission dialog', () => {
setup(() => {
@ -1549,15 +1545,14 @@ limitations under the License.
});
});
test('revision action', () => {
return element._send('DELETE', payload, '/endpoint', true, cleanup)
.then(() => {
assert.isFalse(onShowError.called);
assert.isTrue(cleanup.calledOnce);
assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint',
12, payload));
});
});
test('revision action', () => element
._send('DELETE', payload, '/endpoint', true, cleanup)
.then(() => {
assert.isFalse(onShowError.called);
assert.isTrue(cleanup.calledOnce);
assert.isTrue(sendStub.calledWith(42, 'DELETE', '/endpoint',
12, payload));
}));
});
suite('failure modes', () => {

View File

@ -376,15 +376,18 @@
_handleTopicRemoved(e) {
const target = Polymer.dom(e).rootTarget;
target.disabled = true;
this.$.restAPI.setChangeTopic(this.change._number, null).then(() => {
target.disabled = false;
this.set(['change', 'topic'], '');
this.dispatchEvent(
new CustomEvent('topic-changed', {bubbles: true, composed: true}));
}).catch(err => {
target.disabled = false;
return;
});
this.$.restAPI.setChangeTopic(this.change._number, null)
.then(() => {
target.disabled = false;
this.set(['change', 'topic'], '');
this.dispatchEvent(
new CustomEvent('topic-changed',
{bubbles: true, composed: true}));
})
.catch(err => {
target.disabled = false;
return;
});
}
_handleHashtagRemoved(e) {
@ -396,7 +399,8 @@
.then(newHashtag => {
target.disabled = false;
this.set(['change', 'hashtags'], newHashtag);
}).catch(err => {
})
.catch(err => {
target.disabled = false;
return;
});

View File

@ -736,8 +736,8 @@ limitations under the License.
Gerrit.install(
p => {
plugin = p;
plugin.hook('change-metadata-item').getLastAttached().then(
el => hookEl = el);
plugin.hook('change-metadata-item').getLastAttached()
.then(el => hookEl = el);
},
'0.1',
'http://some/plugins/url.html');

View File

@ -362,16 +362,18 @@
this._setDiffViewMode();
});
Gerrit.awaitPluginsLoaded().then(() => {
this._dynamicTabHeaderEndpoints =
Gerrit.awaitPluginsLoaded()
.then(() => {
this._dynamicTabHeaderEndpoints =
Gerrit._endpoints.getDynamicEndpoints('change-view-tab-header');
this._dynamicTabContentEndpoints =
this._dynamicTabContentEndpoints =
Gerrit._endpoints.getDynamicEndpoints('change-view-tab-content');
if (this._dynamicTabContentEndpoints.length !==
if (this._dynamicTabContentEndpoints.length !==
this._dynamicTabHeaderEndpoints.length) {
console.warn('Different number of tab headers and tab content.');
}
}).then(() => this._setPrimaryTab());
console.warn('Different number of tab headers and tab content.');
}
})
.then(() => this._setPrimaryTab());
this.addEventListener('comment-save', this._handleCommentSave.bind(this));
this.addEventListener('comment-refresh', this._reloadDrafts.bind(this));
@ -413,15 +415,17 @@
_setDiffViewMode(opt_reset) {
if (!opt_reset && this.viewState.diffViewMode) { return; }
return this._getPreferences().then( prefs => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', prefs.default_diff_view);
}
}).then(() => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', 'SIDE_BY_SIDE');
}
});
return this._getPreferences()
.then( prefs => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', prefs.default_diff_view);
}
})
.then(() => {
if (!this.viewState.diffMode) {
this.set('viewState.diffMode', 'SIDE_BY_SIDE');
}
});
}
_onOpenFixPreview(e) {
@ -497,9 +501,10 @@
message);
this._editingCommitMessage = false;
this._reloadWindow();
}).catch(err => {
this.$.commitMessageEditor.disabled = false;
});
})
.catch(err => {
this.$.commitMessageEditor.disabled = false;
});
}
_reloadWindow() {
@ -603,11 +608,11 @@
}
}
diffDrafts[draft.path].push(draft);
diffDrafts[draft.path].sort((c1, c2) => {
diffDrafts[draft.path].sort((c1, c2) =>
// No line number means that its a file comment. Sort it above the
// others.
return (c1.line || -1) - (c2.line || -1);
});
(c1.line || -1) - (c2.line || -1)
);
this._diffDrafts = diffDrafts;
}
@ -689,7 +694,8 @@
_handleMessageReply(e) {
const msg = e.detail.message.message;
const quoteStr = msg.split('\n').map(
line => { return '> ' + line; }).join('\n') + '\n\n';
line => '> ' + line)
.join('\n') + '\n\n';
this.$.replyDialog.quote = quoteStr;
this._openReplyDialog(this.$.replyDialog.FocusTarget.BODY);
}
@ -1087,9 +1093,8 @@
}
const drafts = (changeRecord && changeRecord.base) || {};
const draftCount = Object.keys(drafts).reduce((count, file) => {
return count + drafts[file].length;
}, 0);
const draftCount = Object.keys(drafts)
.reduce((count, file) => count + drafts[file].length, 0);
let label = 'Reply';
if (draftCount > 0) {
@ -1395,9 +1400,7 @@
}
_reloadDraftsWithCallback(e) {
return this._reloadDrafts().then(() => {
return e.detail.resolve();
});
return this._reloadDrafts().then(() => e.detail.resolve());
}
/**

View File

@ -91,9 +91,7 @@ limitations under the License.
});
});
getCustomCssValue = cssParam => {
return util.getComputedStyleValue(cssParam, element);
};
getCustomCssValue = cssParam => util.getComputedStyleValue(cssParam, element);
test('_handleMessageAnchorTap', () => {
element._changeNum = '1';
@ -725,10 +723,10 @@ limitations under the License.
test('dont reload entire page when patchRange changes', () => {
const reloadStub = sandbox.stub(element, '_reload',
() => { return Promise.resolve(); });
() => Promise.resolve());
const reloadPatchDependentStub = sandbox.stub(element,
'_reloadPatchNumDependentResources',
() => { return Promise.resolve(); });
() => Promise.resolve());
const relatedClearSpy = sandbox.spy(element.$.relatedChanges, 'clear');
const collapseStub = sandbox.stub(element.$.fileList, 'collapseAllDiffs');
@ -753,7 +751,7 @@ limitations under the License.
test('reload entire page when patchRange doesnt change', () => {
const reloadStub = sandbox.stub(element, '_reload',
() => { return Promise.resolve(); });
() => Promise.resolve());
const collapseStub = sandbox.stub(element.$.fileList, 'collapseAllDiffs');
const value = {
view: Gerrit.Nav.View.CHANGE,
@ -769,11 +767,9 @@ limitations under the License.
test('related changes are updated and new patch selected after rebase',
done => {
element._changeNum = '42';
sandbox.stub(element, 'computeLatestPatchNum', () => {
return 1;
});
sandbox.stub(element, 'computeLatestPatchNum', () => 1);
sandbox.stub(element, '_reload',
() => { return Promise.resolve(); });
() => Promise.resolve());
const e = {detail: {action: 'rebase'}};
element._handleReloadChange(e).then(() => {
assert.isTrue(navigateToChangeStub.lastCall.calledWithExactly(
@ -783,7 +779,7 @@ limitations under the License.
});
test('related changes are not updated after other action', done => {
sandbox.stub(element, '_reload', () => { return Promise.resolve(); });
sandbox.stub(element, '_reload', () => Promise.resolve());
sandbox.stub(element.$.relatedChanges, 'reload');
const e = {detail: {action: 'abandon'}};
element._handleReloadChange(e).then(() => {
@ -929,14 +925,12 @@ limitations under the License.
test('topic is coalesced to null', done => {
sandbox.stub(element, '_changeChanged');
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
return Promise.resolve({
id: '123456789',
labels: {},
current_revision: 'foo',
revisions: {foo: {commit: {}}},
});
});
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => Promise.resolve({
id: '123456789',
labels: {},
current_revision: 'foo',
revisions: {foo: {commit: {}}},
}));
element._getChangeDetail().then(() => {
assert.isNull(element._change.topic);
@ -946,14 +940,12 @@ limitations under the License.
test('commit sha is populated from getChangeDetail', done => {
sandbox.stub(element, '_changeChanged');
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
return Promise.resolve({
id: '123456789',
labels: {},
current_revision: 'foo',
revisions: {foo: {commit: {}}},
});
});
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => Promise.resolve({
id: '123456789',
labels: {},
current_revision: 'foo',
revisions: {foo: {commit: {}}},
}));
element._getChangeDetail().then(() => {
assert.equal('foo', element._commitInfo.commit);
@ -963,20 +955,16 @@ limitations under the License.
test('edit is added to change', () => {
sandbox.stub(element, '_changeChanged');
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
return Promise.resolve({
id: '123456789',
labels: {},
current_revision: 'foo',
revisions: {foo: {commit: {}}},
});
});
sandbox.stub(element, '_getEdit', () => {
return Promise.resolve({
base_patch_set_number: 1,
commit: {commit: 'bar'},
});
});
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => Promise.resolve({
id: '123456789',
labels: {},
current_revision: 'foo',
revisions: {foo: {commit: {}}},
}));
sandbox.stub(element, '_getEdit', () => Promise.resolve({
base_patch_set_number: 1,
commit: {commit: 'bar'},
}));
element._patchRange = {};
return element._getChangeDetail().then(() => {
@ -1097,12 +1085,8 @@ limitations under the License.
});
test('revert dialog opened with revert param', done => {
sandbox.stub(element.$.restAPI, 'getLoggedIn', () => {
return Promise.resolve(true);
});
sandbox.stub(Gerrit, 'awaitPluginsLoaded', () => {
return Promise.resolve();
});
sandbox.stub(element.$.restAPI, 'getLoggedIn', () => Promise.resolve(true));
sandbox.stub(Gerrit, 'awaitPluginsLoaded', () => Promise.resolve());
element._patchRange = {
basePatchNum: 'PARENT',
@ -1173,7 +1157,7 @@ limitations under the License.
setup(() => {
sandbox.stub(element.$.replyDialog, '_draftChanged');
sandbox.stub(element.$.replyDialog, 'fetchChangeUpdates',
() => { return Promise.resolve({isLatest: true}); });
() => Promise.resolve({isLatest: true}));
element._change = {labels: {}};
});
@ -1222,7 +1206,7 @@ limitations under the License.
suite('commit message expand/collapse', () => {
setup(() => {
sandbox.stub(element, 'fetchChangeUpdates',
() => { return Promise.resolve({isLatest: false}); });
() => Promise.resolve({isLatest: false}));
});
test('commitCollapseToggle hidden for short commit message', () => {
@ -1260,7 +1244,7 @@ limitations under the License.
sandbox.stub(element, '_getOffsetHeight', () => 50);
sandbox.stub(element, '_getScrollHeight', () => 60);
sandbox.stub(element, '_getLineHeight', () => 5);
sandbox.stub(window, 'matchMedia', () => ({matches: true}));
sandbox.stub(window, 'matchMedia', () => { return {matches: true}; });
element.$.relatedChanges.dispatchEvent(
new CustomEvent('new-section-loaded'));
assert.isTrue(element.$.relatedChangesToggle.classList
@ -1275,7 +1259,7 @@ limitations under the License.
sandbox.stub(element, '_getOffsetHeight', () => 50);
sandbox.stub(element, '_getScrollHeight', () => 40);
sandbox.stub(element, '_getLineHeight', () => 5);
sandbox.stub(window, 'matchMedia', () => ({matches: true}));
sandbox.stub(window, 'matchMedia', () => { return {matches: true}; });
element.$.relatedChanges.dispatchEvent(
new CustomEvent('new-section-loaded'));
assert.isFalse(element.$.relatedChangesToggle.classList
@ -1285,7 +1269,7 @@ limitations under the License.
test('relatedChangesToggle functions', () => {
sandbox.stub(element, '_getOffsetHeight', () => 50);
sandbox.stub(window, 'matchMedia', () => ({matches: false}));
sandbox.stub(window, 'matchMedia', () => { return {matches: false}; });
element._relatedChangesLoading = false;
assert.isTrue(element._relatedChangesCollapsed);
assert.isTrue(
@ -1299,7 +1283,7 @@ limitations under the License.
test('_updateRelatedChangeMaxHeight without commit toggle', () => {
sandbox.stub(element, '_getOffsetHeight', () => 50);
sandbox.stub(element, '_getLineHeight', () => 12);
sandbox.stub(window, 'matchMedia', () => ({matches: false}));
sandbox.stub(window, 'matchMedia', () => { return {matches: false}; });
// 50 (existing height) - 30 (extra height) = 20 (adjusted height).
// 20 (max existing height) % 12 (line height) = 6 (remainder).
@ -1316,7 +1300,7 @@ limitations under the License.
element._latestCommitMessage = _.times(31, String).join('\n');
sandbox.stub(element, '_getOffsetHeight', () => 50);
sandbox.stub(element, '_getLineHeight', () => 12);
sandbox.stub(window, 'matchMedia', () => ({matches: false}));
sandbox.stub(window, 'matchMedia', () => { return {matches: false}; });
// 50 (existing height) % 12 (line height) = 2 (remainder).
// 50 (existing height) - 2 (remainder) = 48 (max height to set).
@ -1332,7 +1316,7 @@ limitations under the License.
element._latestCommitMessage = _.times(31, String).join('\n');
sandbox.stub(element, '_getOffsetHeight', () => 50);
sandbox.stub(element, '_getLineHeight', () => 12);
sandbox.stub(window, 'matchMedia', () => ({matches: true}));
sandbox.stub(window, 'matchMedia', () => { return {matches: true}; });
element._updateRelatedChangeMaxHeight();
@ -1383,7 +1367,7 @@ limitations under the License.
test('_startUpdateCheckTimer up-to-date', () => {
sandbox.stub(element, 'fetchChangeUpdates',
() => { return Promise.resolve({isLatest: true}); });
() => Promise.resolve({isLatest: true}));
element._serverConfig = {change: {update_delay: 12345}};
@ -1394,7 +1378,7 @@ limitations under the License.
test('_startUpdateCheckTimer out-of-date shows an alert', done => {
sandbox.stub(element, 'fetchChangeUpdates',
() => { return Promise.resolve({isLatest: false}); });
() => Promise.resolve({isLatest: false}));
element.addEventListener('show-alert', e => {
assert.equal(e.detail.message,
'A newer patch set has been uploaded');
@ -1738,8 +1722,9 @@ limitations under the License.
Gerrit.install(
p => {
plugin = p;
plugin.hook('change-view-integration').getLastAttached().then(
el => hookEl = el);
plugin.hook('change-view-integration').getLastAttached()
.then(
el => hookEl = el);
},
'0.1',
'http://some/plugins/url.html');

View File

@ -153,15 +153,17 @@ limitations under the License.
test('_getRecentChanges', () => {
sandbox.spy(element, '_getRecentChanges');
return element._getRecentChanges().then(() => {
assert.deepEqual(element._recentChanges, recentChanges);
assert.equal(element.$.restAPI.getChanges.callCount, 1);
// When called a second time, should not re-request recent changes.
element._getRecentChanges();
}).then(() => {
assert.equal(element._getRecentChanges.callCount, 2);
assert.equal(element.$.restAPI.getChanges.callCount, 1);
});
return element._getRecentChanges()
.then(() => {
assert.deepEqual(element._recentChanges, recentChanges);
assert.equal(element.$.restAPI.getChanges.callCount, 1);
// When called a second time, should not re-request recent changes.
element._getRecentChanges();
})
.then(() => {
assert.equal(element._getRecentChanges.callCount, 2);
assert.equal(element.$.restAPI.getChanges.callCount, 1);
});
});
test('_filterChanges', () => {

View File

@ -201,7 +201,8 @@
this.set(['change', 'revisions', sha, 'description'], desc);
this._patchsetDescription = desc;
}
}).catch(err => {
})
.catch(err => {
if (target) { target.disabled = false; }
return;
});

View File

@ -133,35 +133,37 @@ limitations under the License.
// Simulate tapping the remove button, but call function directly so that
// can determine what happens after the promise is resolved.
return element._handleDescriptionRemoved().then(() => {
// The API stub should be called with an empty string for the new
// description.
assert.equal(putDescStub.lastCall.args[2], '');
assert.equal(element.change.revisions.rev1.description, '');
return element._handleDescriptionRemoved()
.then(() => {
// The API stub should be called with an empty string for the new
// description.
assert.equal(putDescStub.lastCall.args[2], '');
assert.equal(element.change.revisions.rev1.description, '');
flushAsynchronousOperations();
// The editable label should now be visible and the chip hidden.
label = Polymer.dom(element.root).querySelector('#descriptionLabel');
assert.isOk(label);
assert.equal(getComputedStyle(chip).display, 'none');
assert.notEqual(getComputedStyle(label).display, 'none');
assert.isFalse(label.readOnly);
// Edit the label to have a new value of test2, and save.
label.editing = true;
label._inputText = 'test2';
label._save();
flushAsynchronousOperations();
// The API stub should be called with an `test2` for the new
// description.
assert.equal(putDescStub.callCount, 2);
assert.equal(putDescStub.lastCall.args[2], 'test2');
}).then(() => {
flushAsynchronousOperations();
// The chip should be visible again, and the label hidden.
assert.equal(element.change.revisions.rev1.description, 'test2');
assert.equal(getComputedStyle(label).display, 'none');
assert.notEqual(getComputedStyle(chip).display, 'none');
});
flushAsynchronousOperations();
// The editable label should now be visible and the chip hidden.
label = Polymer.dom(element.root).querySelector('#descriptionLabel');
assert.isOk(label);
assert.equal(getComputedStyle(chip).display, 'none');
assert.notEqual(getComputedStyle(label).display, 'none');
assert.isFalse(label.readOnly);
// Edit the label to have a new value of test2, and save.
label.editing = true;
label._inputText = 'test2';
label._save();
flushAsynchronousOperations();
// The API stub should be called with an `test2` for the new
// description.
assert.equal(putDescStub.callCount, 2);
assert.equal(putDescStub.lastCall.args[2], 'test2');
})
.then(() => {
flushAsynchronousOperations();
// The chip should be visible again, and the label hidden.
assert.equal(element.change.revisions.rev1.description, 'test2');
assert.equal(getComputedStyle(label).display, 'none');
assert.notEqual(getComputedStyle(chip).display, 'none');
});
});
test('expandAllDiffs called when expand button clicked', () => {

View File

@ -297,15 +297,15 @@
promises.push(this._getFiles().then(filesByPath => {
this._filesByPath = filesByPath;
}));
promises.push(this._getLoggedIn().then(loggedIn => {
return this._loggedIn = loggedIn;
}).then(loggedIn => {
if (!loggedIn) { return; }
promises.push(this._getLoggedIn()
.then(loggedIn => this._loggedIn = loggedIn)
.then(loggedIn => {
if (!loggedIn) { return; }
return this._getReviewedFiles().then(reviewed => {
this._reviewed = reviewed;
});
}));
return this._getReviewedFiles().then(reviewed => {
this._reviewed = reviewed;
});
}));
promises.push(this._getDiffPreferences().then(prefs => {
this.diffPrefs = prefs;
@ -1063,30 +1063,28 @@
return (new Promise(resolve => {
this.fire('reload-drafts', {resolve});
})).then(() => {
return this.asyncForeach(paths, (path, cancel) => {
this._cancelForEachDiff = cancel;
})).then(() => this.asyncForeach(paths, (path, cancel) => {
this._cancelForEachDiff = cancel;
iter++;
console.log('Expanding diff', iter, 'of', initialCount, ':',
path);
const diffElem = this._findDiffByPath(path, diffElements);
diffElem.comments = this.changeComments.getCommentsBySideForPath(
path, this.patchRange, this.projectConfig);
const promises = [diffElem.reload()];
if (this._loggedIn && !this.diffPrefs.manual_review) {
promises.push(this._reviewFile(path, true));
}
return Promise.all(promises);
}).then(() => {
this._cancelForEachDiff = null;
this._nextRenderParams = null;
console.log('Finished expanding', initialCount, 'diff(s)');
this.$.reporting.timeEndWithAverage(EXPAND_ALL_TIMING_LABEL,
EXPAND_ALL_AVG_TIMING_LABEL, initialCount);
this.$.diffCursor.handleDiffUpdate();
});
});
iter++;
console.log('Expanding diff', iter, 'of', initialCount, ':',
path);
const diffElem = this._findDiffByPath(path, diffElements);
diffElem.comments = this.changeComments.getCommentsBySideForPath(
path, this.patchRange, this.projectConfig);
const promises = [diffElem.reload()];
if (this._loggedIn && !this.diffPrefs.manual_review) {
promises.push(this._reviewFile(path, true));
}
return Promise.all(promises);
}).then(() => {
this._cancelForEachDiff = null;
this._nextRenderParams = null;
console.log('Finished expanding', initialCount, 'diff(s)');
this.$.reporting.timeEndWithAverage(EXPAND_ALL_TIMING_LABEL,
EXPAND_ALL_AVG_TIMING_LABEL, initialCount);
this.$.diffCursor.handleDiffUpdate();
}));
}
/** Cancel the rendering work of every diff in the list */
@ -1141,9 +1139,9 @@
// comments due to use in the _handleCommentUpdate function.
// The comment thread already has a side associated with it, so
// set the comment's side to match.
threadEl.comments = newComments.map(c => {
return Object.assign(c, {__commentSide: threadEl.commentSide});
});
threadEl.comments = newComments.map(c => Object.assign(
c, {__commentSide: threadEl.commentSide}
));
Polymer.dom.flush();
return;
}

View File

@ -115,7 +115,7 @@ limitations under the License.
patchNum: '2',
};
saveStub = sandbox.stub(element, '_saveReviewedState',
() => { return Promise.resolve(); });
() => Promise.resolve());
});
teardown(() => {
@ -686,7 +686,7 @@ limitations under the License.
});
test('r key toggles reviewed flag', () => {
const reducer = (accum, file) => file.isReviewed ? ++accum : accum;
const reducer = (accum, file) => (file.isReviewed ? ++accum : accum);
const getNumReviewed = () => element._files.reduce(reducer, 0);
flushAsynchronousOperations();
@ -865,7 +865,8 @@ limitations under the License.
// Click inside the diff. This should result in no additional calls to
// _togglePathExpanded or _reviewFile.
Polymer.dom(element.root).querySelector('gr-diff-host').click();
Polymer.dom(element.root).querySelector('gr-diff-host')
.click();
assert.isTrue(clickSpy.calledTwice);
assert.isTrue(toggleExpandSpy.calledOnce);
assert.isFalse(reviewStub.called);
@ -1476,9 +1477,7 @@ limitations under the License.
basePatchNum: 'PARENT',
patchNum: '2',
};
sandbox.stub(window, 'fetch', () => {
return Promise.resolve();
});
sandbox.stub(window, 'fetch', () => Promise.resolve());
flushAsynchronousOperations();
});

View File

@ -97,12 +97,13 @@
const labelsObj = labelRecord.base;
if (!labelsObj) { return []; }
return Object.keys(labelsObj).sort().map(key => {
return {
name: key,
value: this._getVoteForAccount(labelsObj, key, this.account),
};
});
return Object.keys(labelsObj).sort()
.map(key => {
return {
name: key,
value: this._getVoteForAccount(labelsObj, key, this.account),
};
});
}
_computeColumns(permittedLabels) {
@ -114,9 +115,7 @@
}
}
const orderedValues = Object.keys(values).sort((a, b) => {
return a - b;
});
const orderedValues = Object.keys(values).sort((a, b) => a - b);
for (let i = 0; i < orderedValues.length; i++) {
values[orderedValues[i]] = i;

View File

@ -207,7 +207,7 @@
return scoresRaw.split(' ')
.map(s => s.match(LABEL_TITLE_SCORE_PATTERN))
.filter(ms => ms && ms.length === 3)
.map(ms => ({label: ms[1], value: ms[2]}));
.map(ms => { return {label: ms[1], value: ms[2]}; });
}
_computeScoreClass(score, labelExtremes) {

View File

@ -324,9 +324,7 @@
}
_getHumanMessages(messages) {
return messages.filter(msg => {
return !this._isAutomated(msg);
});
return messages.filter(msg => !this._isAutomated(msg));
}
_computeShowHideTextHidden(visibleMessages, messages,

View File

@ -354,7 +354,7 @@
changeRevision = rev;
}
}
const commits = relatedChanges.map(c => { return c.commit; });
const commits = relatedChanges.map(c => c.commit);
let pos = commits.length - 1;
while (pos >= 0) {

View File

@ -474,28 +474,31 @@
this.disabled = true;
const errFn = this._handle400Error.bind(this);
return this._saveReview(obj, errFn).then(response => {
if (!response) {
// Null or undefined response indicates that an error handler
// took responsibility, so just return.
return {};
}
if (!response.ok) {
this.fire('server-error', {response});
return {};
}
return this._saveReview(obj, errFn)
.then(response => {
if (!response) {
// Null or undefined response indicates that an error handler
// took responsibility, so just return.
return {};
}
if (!response.ok) {
this.fire('server-error', {response});
return {};
}
this.draft = '';
this._includeComments = true;
this.fire('send', null, {bubbles: false});
return accountAdditions;
}).then(result => {
this.disabled = false;
return result;
}).catch(err => {
this.disabled = false;
throw err;
});
this.draft = '';
this._includeComments = true;
this.fire('send', null, {bubbles: false});
return accountAdditions;
})
.then(result => {
this.disabled = false;
return result;
})
.catch(err => {
this.disabled = false;
throw err;
});
}
_focusOn(section) {

View File

@ -136,23 +136,24 @@ limitations under the License.
});
function stubSaveReview(jsonResponseProducer) {
return sandbox.stub(element, '_saveReview', review => {
return new Promise((resolve, reject) => {
try {
const result = jsonResponseProducer(review) || {};
const resultStr =
element.$.restAPI.JSON_PREFIX + JSON.stringify(result);
resolve({
ok: true,
text() {
return Promise.resolve(resultStr);
},
});
} catch (err) {
reject(err);
}
});
});
return sandbox.stub(
element,
'_saveReview',
review => new Promise((resolve, reject) => {
try {
const result = jsonResponseProducer(review) || {};
const resultStr =
element.$.restAPI.JSON_PREFIX + JSON.stringify(result);
resolve({
ok: true,
text() {
return Promise.resolve(resultStr);
},
});
} catch (err) {
reject(err);
}
}));
}
test('default to publishing drafts with reply', done => {
@ -271,7 +272,8 @@ limitations under the License.
test('getlabelValue when no score is selected', done => {
flush(() => {
element.$$('gr-label-scores')
.$$(`gr-label-score-row[name="Code-Review"]`).setSelectedValue(-1);
.$$(`gr-label-score-row[name="Code-Review"]`)
.setSelectedValue(-1);
assert.strictEqual(element.getLabelValue('Verified'), ' 0');
done();
});
@ -372,73 +374,87 @@ limitations under the License.
element._pendingConfirmationDetails);
}
observer.then(() => {
assert.isTrue(isVisible(element.$.reviewerConfirmationOverlay));
observer = overlayObserver('closed');
const expected = 'Group name has 10 members';
assert.notEqual(
element.$.reviewerConfirmationOverlay.innerText.indexOf(expected),
-1);
MockInteractions.tap(noButton); // close the overlay
return observer;
}).then(() => {
assert.isFalse(isVisible(element.$.reviewerConfirmationOverlay));
observer
.then(() => {
assert.isTrue(isVisible(element.$.reviewerConfirmationOverlay));
observer = overlayObserver('closed');
const expected = 'Group name has 10 members';
assert.notEqual(
element.$.reviewerConfirmationOverlay.innerText
.indexOf(expected),
-1);
MockInteractions.tap(noButton); // close the overlay
return observer;
}).then(() => {
assert.isFalse(isVisible(element.$.reviewerConfirmationOverlay));
// We should be focused on account entry input.
assert.isTrue(
isFocusInsideElement(element.$.reviewers.$.entry.$.input.$.input));
// We should be focused on account entry input.
assert.isTrue(
isFocusInsideElement(
element.$.reviewers.$.entry.$.input.$.input
)
);
// No reviewer/CC should have been added.
assert.equal(element.$.ccs.additions().length, 0);
assert.equal(element.$.reviewers.additions().length, 0);
// No reviewer/CC should have been added.
assert.equal(element.$.ccs.additions().length, 0);
assert.equal(element.$.reviewers.additions().length, 0);
// Reopen confirmation dialog.
observer = overlayObserver('opened');
if (cc) {
element._ccPendingConfirmation = {
group,
count: 10,
};
} else {
element._reviewerPendingConfirmation = {
group,
count: 10,
};
}
return observer;
}).then(() => {
assert.isTrue(isVisible(element.$.reviewerConfirmationOverlay));
observer = overlayObserver('closed');
MockInteractions.tap(yesButton); // Confirm the group.
return observer;
}).then(() => {
assert.isFalse(isVisible(element.$.reviewerConfirmationOverlay));
const additions = cc ?
element.$.ccs.additions() :
element.$.reviewers.additions();
assert.deepEqual(
additions,
[
{
group: {
id: 'id',
name: 'name',
confirmed: true,
_group: true,
_pendingAdd: true,
},
},
]);
// Reopen confirmation dialog.
observer = overlayObserver('opened');
if (cc) {
element._ccPendingConfirmation = {
group,
count: 10,
};
} else {
element._reviewerPendingConfirmation = {
group,
count: 10,
};
}
return observer;
})
.then(() => {
assert.isTrue(isVisible(element.$.reviewerConfirmationOverlay));
observer = overlayObserver('closed');
MockInteractions.tap(yesButton); // Confirm the group.
return observer;
})
.then(() => {
assert.isFalse(isVisible(element.$.reviewerConfirmationOverlay));
const additions = cc ?
element.$.ccs.additions() :
element.$.reviewers.additions();
assert.deepEqual(
additions,
[
{
group: {
id: 'id',
name: 'name',
confirmed: true,
_group: true,
_pendingAdd: true,
},
},
]);
// We should be focused on account entry input.
if (cc) {
assert.isTrue(
isFocusInsideElement(element.$.ccs.$.entry.$.input.$.input));
} else {
assert.isTrue(
isFocusInsideElement(element.$.reviewers.$.entry.$.input.$.input));
}
}).then(done);
// We should be focused on account entry input.
if (cc) {
assert.isTrue(
isFocusInsideElement(
element.$.ccs.$.entry.$.input.$.input
)
);
} else {
assert.isTrue(
isFocusInsideElement(
element.$.reviewers.$.entry.$.input.$.input
)
);
}
})
.then(done);
}
test('cc confirmation', done => {
@ -673,7 +689,8 @@ limitations under the License.
// fail.
element.$$('gr-label-scores').$$(
'gr-label-score-row[name="Verified"]').setSelectedValue(-1);
'gr-label-score-row[name="Verified"]')
.setSelectedValue(-1);
MockInteractions.tap(element.$$('.send'));
});
});
@ -967,9 +984,10 @@ limitations under the License.
let startReviewStub;
setup(() => {
startReviewStub = sandbox.stub(element.$.restAPI, 'startReview', () => {
return Promise.resolve();
});
startReviewStub = sandbox.stub(
element.$.restAPI,
'startReview',
() => Promise.resolve());
});
test('ready property in review input on start review', () => {

View File

@ -102,10 +102,12 @@
*/
_permittedLabelsToNumericScores(labels) {
if (!labels) return [];
return Object.keys(labels).map(label => ({
label,
scores: labels[label].map(v => parseInt(v, 10)),
}));
return Object.keys(labels).map(label => {
return {
label,
scores: labels[label].map(v => parseInt(v, 10)),
};
});
}
/**
@ -116,10 +118,12 @@
*/
_getMaxPermittedScores(change) {
return this._permittedLabelsToNumericScores(change.permitted_labels)
.map(({label, scores}) => ({
[label]: scores
.map(v => parseInt(v, 10))
.reduce((a, b) => Math.max(a, b))}))
.map(({label, scores}) => {
return {
[label]: scores
.map(v => parseInt(v, 10))
.reduce((a, b) => Math.max(a, b))};
})
.reduce((acc, i) => Object.assign(acc, i), {});
}
@ -189,9 +193,8 @@
result = result.concat(reviewers[key]);
}
}
this._reviewers = result.filter(reviewer => {
return reviewer._account_id != owner._account_id;
});
this._reviewers = result
.filter(reviewer => reviewer._account_id != owner._account_id);
// If there is one or two more than the max reviewers, don't show the
// 'show more' button, because it takes up just as much space.
@ -249,10 +252,11 @@
}
}
}
}).catch(err => {
this.disabled = false;
throw err;
});
})
.catch(err => {
this.disabled = false;
throw err;
});
}
_handleAddTap(e) {

View File

@ -67,16 +67,18 @@
attached() {
super.attached();
this.$.restAPI.getLoggedIn().then(loggedIn => {
if (loggedIn) {
return this.$.restAPI.getPreferences();
}
}).then(prefs => {
if (prefs) {
this._preferredDownloadCommand = prefs.download_command;
this._preferredDownloadScheme = prefs.download_scheme;
}
});
this.$.restAPI.getLoggedIn()
.then(loggedIn => {
if (loggedIn) {
return this.$.restAPI.getPreferences();
}
})
.then(prefs => {
if (prefs) {
this._preferredDownloadCommand = prefs.download_command;
this._preferredDownloadScheme = prefs.download_scheme;
}
});
}
_handleCloseTap(e) {

View File

@ -102,9 +102,9 @@
}
_interpolateUrl(url, replacements) {
return url.replace(INTERPOLATE_URL_PATTERN, (match, p1) => {
return replacements[p1] || '';
});
return url.replace(
INTERPOLATE_URL_PATTERN,
(match, p1) => replacements[p1] || '');
}
_accountName(account) {

View File

@ -107,7 +107,7 @@ limitations under the License.
test('show normal Error', done => {
const showErrorStub = sandbox.stub(element, '_showErrorDialog');
const textSpy = sandbox.spy(() => { return Promise.resolve('ZOMG'); });
const textSpy = sandbox.spy(() => Promise.resolve('ZOMG'));
element.fire('server-error', {response: {status: 500, text: textSpy}});
assert.isTrue(textSpy.called);
@ -129,8 +129,9 @@ limitations under the License.
'Error 409');
assert.equal(element._constructServerErrorMsg({status, url}),
'Error 409: \nEndpoint: /my/test/url');
assert.equal(element._constructServerErrorMsg({status, statusText, url}),
'Error 409 (Conflict): \nEndpoint: /my/test/url');
assert.equal(element.
_constructServerErrorMsg({status, statusText, url}),
'Error 409 (Conflict): \nEndpoint: /my/test/url');
assert.equal(element._constructServerErrorMsg({
status,
statusText,
@ -142,9 +143,9 @@ limitations under the License.
test('suppress TOO_MANY_FILES error', done => {
const showAlertStub = sandbox.stub(element, '_showAlert');
const textSpy = sandbox.spy(() => {
return Promise.resolve('too many files to find conflicts');
});
const textSpy = sandbox.spy(
() => Promise.resolve('too many files to find conflicts')
);
element.fire('server-error', {response: {status: 500, text: textSpy}});
assert.isTrue(textSpy.called);
@ -172,7 +173,7 @@ limitations under the License.
// starts with authed state
element.$.restAPI.getLoggedIn();
const refreshStub = sandbox.stub(element.$.restAPI, 'getAccount',
() => { return Promise.resolve({}); });
() => Promise.resolve({}));
const toastSpy = sandbox.spy(element, '_createToastAlert');
const windowOpen = sandbox.stub(window, 'open');
const responseText = Promise.resolve('Authentication required\n');
@ -297,7 +298,10 @@ limitations under the License.
test('show-error', () => {
const openStub = sandbox.stub(element.$.errorOverlay, 'open');
const closeStub = sandbox.stub(element.$.errorOverlay, 'close');
const reportStub = sandbox.stub(element.$.reporting, 'reportErrorDialog');
const reportStub = sandbox.stub(
element.$.reporting,
'reportErrorDialog'
);
const message = 'test message';
element.fire('show-error', {message});
@ -317,7 +321,9 @@ limitations under the License.
const accountPromise = Promise.resolve({_account_id: 1234});
sandbox.stub(element.$.restAPI, 'getAccount')
.returns(accountPromise);
const requestCheckStub = sandbox.stub(element, '_requestCheckLoggedIn');
const requestCheckStub = sandbox.stub(
element,
'_requestCheckLoggedIn');
const handleRefreshStub = sandbox.stub(element,
'_handleCredentialRefreshed');
const reloadStub = sandbox.stub(element, '_reloadPage');
@ -344,7 +350,9 @@ limitations under the License.
});
test('refresh loop continues on credential fail', done => {
const requestCheckStub = sandbox.stub(element, '_requestCheckLoggedIn');
const requestCheckStub = sandbox.stub(
element,
'_requestCheckLoggedIn');
const handleRefreshStub = sandbox.stub(element,
'_handleCredentialRefreshed');
const reloadStub = sandbox.stub(element, '_reloadPage');

View File

@ -231,10 +231,10 @@
const topMenuLinks = [];
links.forEach(link => { topMenuLinks[link.title] = link.links; });
for (const m of topMenus) {
const items = m.items.map(this._fixCustomMenuItem).filter(link => {
const items = m.items.map(this._fixCustomMenuItem).filter(link =>
// Ignore GWT project links
return !link.url.includes('${projectName}');
});
!link.url.includes('${projectName}')
);
if (m.name in topMenuLinks) {
items.forEach(link => { topMenuLinks[m.name].push(link); });
} else {

View File

@ -634,7 +634,8 @@
* @return {!string} Everything after the first '#' ("a#b#c" -> "b#c").
*/
_getHashFromCanonicalPath(canonicalPath) {
return canonicalPath.split('#').slice(1).join('#');
return canonicalPath.split('#').slice(1)
.join('#');
}
_parseLineAddress(hash) {

View File

@ -74,7 +74,7 @@ limitations under the License.
test('_getChangeWeblinks', () => {
const link = {name: 'test', url: 'test/url'};
const browserLink = {name: 'browser', url: 'browser/url'};
const mapLinksToConfig = weblinks => ({options: {weblinks}});
const mapLinksToConfig = weblinks => { return {options: {weblinks}}; };
sandbox.stub(element, '_getBrowseCommitWeblink').returns(browserLink);
assert.deepEqual(

View File

@ -200,9 +200,7 @@
const trimmedInput = this._inputVal && this._inputVal.trim();
if (trimmedInput) {
const predefinedOpOnlyQuery = SEARCH_OPERATORS_WITH_NEGATIONS.some(
op => {
return op.endsWith(':') && op === trimmedInput;
}
op => op.endsWith(':') && op === trimmedInput
);
if (predefinedOpOnlyQuery) {
return;
@ -252,7 +250,7 @@
default:
return Promise.resolve(SEARCH_OPERATORS_WITH_NEGATIONS
.filter(operator => operator.includes(input))
.map(operator => ({text: operator})));
.map(operator => { return {text: operator}; }));
}
}

View File

@ -59,11 +59,9 @@ limitations under the License.
assert.equal(element._inputVal, 'foo');
});
getActiveElement = () => {
return document.activeElement.shadowRoot ?
document.activeElement.shadowRoot.activeElement :
document.activeElement;
};
getActiveElement = () => (document.activeElement.shadowRoot ?
document.activeElement.shadowRoot.activeElement :
document.activeElement);
test('enter in search input fires event', done => {
element.addEventListener('handle-search', () => {

View File

@ -91,7 +91,7 @@
.then(projects => {
if (!projects) { return []; }
const keys = Object.keys(projects);
return keys.map(key => ({text: predicate + ':' + key}));
return keys.map(key => { return {text: predicate + ':' + key}; });
});
}
@ -113,7 +113,7 @@
.then(groups => {
if (!groups) { return []; }
const keys = Object.keys(groups);
return keys.map(key => ({text: predicate + ':' + key}));
return keys.map(key => { return {text: predicate + ':' + key}; });
});
}
@ -135,7 +135,8 @@
.then(accounts => {
if (!accounts) { return []; }
return this._mapAccountsHelper(accounts, predicate);
}).then(accounts => {
})
.then(accounts => {
// When the expression supplied is a beginning substring of 'self',
// add it as an autocomplete option.
if (SELF_EXPRESSION.startsWith(expression)) {
@ -150,12 +151,14 @@
}
_mapAccountsHelper(accounts, predicate) {
return accounts.map(account => ({
label: account.name || '',
text: account.email ?
`${predicate}:${account.email}` :
`${predicate}:"${this._accountOrAnon(account)}"`,
}));
return accounts.map(account => {
return {
label: account.name || '',
text: account.email ?
`${predicate}:${account.email}` :
`${predicate}:"${this._accountOrAnon(account)}"`,
};
});
}
}

View File

@ -71,12 +71,15 @@ limitations under the License.
},
])
);
element._fetchAccounts('owner', 's').then(s => {
assert.deepEqual(s[0], {text: 'owner:fred@goog.co', label: 'fred'});
assert.deepEqual(s[1], {text: 'owner:self'});
}).then(() => element._fetchAccounts('owner', 'selfs')).then(s => {
assert.notEqual(s[0], {text: 'owner:self'});
});
element._fetchAccounts('owner', 's')
.then(s => {
assert.deepEqual(s[0], {text: 'owner:fred@goog.co', label: 'fred'});
assert.deepEqual(s[1], {text: 'owner:self'});
})
.then(() => element._fetchAccounts('owner', 'selfs'))
.then(s => {
assert.notEqual(s[0], {text: 'owner:self'});
});
});
test('Inserts me as option when valid', () => {
@ -88,12 +91,15 @@ limitations under the License.
},
])
);
return element._fetchAccounts('owner', 'm').then(s => {
assert.deepEqual(s[0], {text: 'owner:fred@goog.co', label: 'fred'});
assert.deepEqual(s[1], {text: 'owner:me'});
}).then(() => element._fetchAccounts('owner', 'meme')).then(s => {
assert.notEqual(s[0], {text: 'owner:me'});
});
return element._fetchAccounts('owner', 'm')
.then(s => {
assert.deepEqual(s[0], {text: 'owner:fred@goog.co', label: 'fred'});
assert.deepEqual(s[1], {text: 'owner:me'});
})
.then(() => element._fetchAccounts('owner', 'meme'))
.then(s => {
assert.notEqual(s[0], {text: 'owner:me'});
});
});
test('Autocompletes groups', () => {

View File

@ -85,11 +85,13 @@
.getRobotCommentFixPreview(this.changeNum, this._patchNum, fixId)
.then(res => {
if (res != null) {
const previews = Object.keys(res).map(key =>
({filepath: key, preview: res[key]}));
const previews = Object.keys(res).map(key => {
return {filepath: key, preview: res[key]};
});
this._currentPreviews = previews;
}
}).catch(err => {
})
.catch(err => {
this._close();
this.dispatchEvent(new CustomEvent('show-error', {
bubbles: true,
@ -175,13 +177,14 @@
this._currentFix.fix_id).then(res => {
Gerrit.Nav.navigateToChange(this.change, 'edit', this._patchNum);
this._close();
}).catch(err => {
this.dispatchEvent(new CustomEvent('show-error', {
bubbles: true,
composed: true,
detail: {message: `Error applying fix suggestion: ${err}`},
}));
});
})
.catch(err => {
this.dispatchEvent(new CustomEvent('show-error', {
bubbles: true,
composed: true,
detail: {message: `Error applying fix suggestion: ${err}`},
}));
});
},
getFixDescription(currentFix) {

View File

@ -39,9 +39,7 @@
* file simpler by just using _reloadComments here instead.
*/
_reloadDraftsWithCallback(e) {
return this._reloadComments().then(() => {
return e.detail.resolve();
});
return this._reloadComments().then(() => e.detail.resolve());
}
_reloadComments() {

View File

@ -362,9 +362,10 @@
};
ChangeComments.prototype._sortComments = function(comments) {
return comments.slice(0).sort((c1, c2) => {
return util.parseDate(c1.updated) - util.parseDate(c2.updated);
});
return comments.slice(0)
.sort(
(c1, c2) => util.parseDate(c1.updated) - util.parseDate(c2.updated)
);
};
/**

View File

@ -131,19 +131,21 @@ limitations under the License.
test('with loadAll first', done => {
assert.isNotOk(element._changeComments);
element.loadAll().then(() => {
assert.isOk(element._changeComments);
assert.equal(commentStub.callCount, 1);
assert.equal(robotCommentStub.callCount, 1);
assert.equal(draftStub.callCount, 1);
return element.reloadDrafts();
}).then(() => {
assert.isOk(element._changeComments);
assert.equal(commentStub.callCount, 1);
assert.equal(robotCommentStub.callCount, 1);
assert.equal(draftStub.callCount, 2);
done();
});
element.loadAll()
.then(() => {
assert.isOk(element._changeComments);
assert.equal(commentStub.callCount, 1);
assert.equal(robotCommentStub.callCount, 1);
assert.equal(draftStub.callCount, 1);
return element.reloadDrafts();
})
.then(() => {
assert.isOk(element._changeComments);
assert.equal(commentStub.callCount, 1);
assert.equal(robotCommentStub.callCount, 1);
assert.equal(draftStub.callCount, 2);
done();
});
});
});

View File

@ -230,7 +230,7 @@
GrDiffBuilder.prototype.getSectionsByLineRange = function(
startLine, endLine, opt_side) {
return this.getGroupsByLineRange(startLine, endLine, opt_side).map(
group => { return group.element; });
group => group.element);
};
GrDiffBuilder.prototype._createContextControl = function(section, line) {

View File

@ -322,7 +322,8 @@ limitations under the License.
const lineNumberEl = document.createElement('td');
function slice(str, start, end) {
return Array.from(str).slice(start, end).join('');
return Array.from(str).slice(start, end)
.join('');
}
setup(() => {
@ -811,9 +812,8 @@ limitations under the License.
sandbox.stub(builder, 'addColumns');
builder.buildSectionElement = function(group) {
const section = document.createElement('stub');
section.textContent = group.lines.reduce((acc, line) => {
return acc + line.text;
}, '');
section.textContent = group.lines
.reduce((acc, line) => acc + line.text, '');
return section;
};
return builder;
@ -858,7 +858,7 @@ limitations under the License.
const dispatchEventStub = sandbox.stub(element, 'dispatchEvent');
element.render(keyLocations, {}).then(() => {
const firedEventTypes = dispatchEventStub.getCalls()
.map(c => { return c.args[0].type; });
.map(c => c.args[0].type);
assert.include(firedEventTypes, 'render-start');
assert.include(firedEventTypes, 'render-content');
done();

View File

@ -165,9 +165,7 @@
moveToNextChunk(opt_clipToTop) {
this.$.cursorManager.next(this._isFirstRowOfChunk.bind(this),
target => {
return target.parentNode.scrollHeight;
}, opt_clipToTop);
target => target.parentNode.scrollHeight, opt_clipToTop);
this._fixSide();
}
@ -273,9 +271,8 @@
}
createCommentInPlace() {
const diffWithRangeSelected = this.diffs.find(diff => {
return diff.isRangeSelected();
});
const diffWithRangeSelected = this.diffs
.find(diff => diff.isRangeSelected());
if (diffWithRangeSelected) {
diffWithRangeSelected.createRangeComment();
} else {
@ -404,9 +401,7 @@
_getStops() {
return this.diffs.reduce(
(stops, diff) => {
return stops.concat(diff.getCursorStops());
}, []);
(stops, diff) => stops.concat(diff.getCursorStops()), []);
}
_updateStops() {

View File

@ -377,7 +377,8 @@ limitations under the License.
const getRangeAtStub = sandbox.stub();
getRangeAtStub
.onFirstCall().returns(startRange)
.onSecondCall().returns(endRange);
.onSecondCall()
.returns(endRange);
const selection = {
rangeCount: 2,
getRangeAt: getRangeAtStub,

View File

@ -412,7 +412,8 @@
range.side);
});
});
}).catch(err => {
})
.catch(err => {
console.warn('Loading coverage ranges failed: ', err);
});
}

View File

@ -123,9 +123,8 @@ limitations under the License.
element.comments.left.push(comment);
comment.id = id;
element.fire('comment-discard', {comment});
const drafts = element.comments.left.filter(item => {
return item.__draftID === draftID;
});
const drafts = element.comments.left
.filter(item => item.__draftID === draftID);
assert.equal(drafts.length, 0);
assert.isTrue(diffCommentsModifiedStub.called);
});
@ -145,9 +144,8 @@ limitations under the License.
element.comments.left.push(comment);
comment.id = id;
element.fire('comment-save', {comment});
const drafts = element.comments.left.filter(item => {
return item.__draftID === draftID;
});
const drafts = element.comments.left
.filter(item => item.__draftID === draftID);
assert.equal(drafts.length, 1);
assert.equal(drafts[0].id, id);
assert.isTrue(diffCommentsModifiedStub.called);
@ -361,12 +359,14 @@ limitations under the License.
Promise.resolve({content: []}));
element.patchRange = {};
let reloadComplete = false;
element.$.restAPI.getDiffPreferences().then(prefs => {
element.prefs = prefs;
return element.reload();
}).then(() => {
reloadComplete = true;
});
element.$.restAPI.getDiffPreferences()
.then(prefs => {
element.prefs = prefs;
return element.reload();
})
.then(() => {
reloadComplete = true;
});
// Multiple cascading microtasks are scheduled.
setTimeout(() => {
assert.isFalse(reloadComplete);
@ -506,10 +506,10 @@ limitations under the License.
};
sandbox.stub(element.$.restAPI,
'getB64FileContents',
(changeId, patchNum, path, opt_parentIndex) => {
return Promise.resolve(opt_parentIndex === 1 ? mockFile1 :
mockFile2);
});
(changeId, patchNum, path, opt_parentIndex) => Promise.resolve(
opt_parentIndex === 1 ? mockFile1 :
mockFile2)
);
element.patchRange = {basePatchNum: 'PARENT', patchNum: 1};
element.comments = {
@ -1380,7 +1380,8 @@ limitations under the License.
});
test('starts syntax layer processing on render event', done => {
sandbox.stub(element.$.syntaxLayer, 'process').returns(Promise.resolve());
sandbox.stub(element.$.syntaxLayer, 'process')
.returns(Promise.resolve());
sandbox.stub(element.$.restAPI, 'getDiff').returns(
Promise.resolve({content: []}));
element.reload();

View File

@ -500,7 +500,7 @@ limitations under the License.
test('breaks down shared chunks w/ whole-file', () => {
const size = 120 * 2 + 5;
const content = [{
ab: _.times(size, () => { return `${Math.random()}`; }),
ab: _.times(size, () => `${Math.random()}`),
}];
element.context = -1;
const result = element._splitLargeChunks(content);
@ -511,7 +511,7 @@ limitations under the License.
test('does not break-down common chunks w/ context', () => {
const content = [{
ab: _.times(75, () => { return `${Math.random()}`; }),
ab: _.times(75, () => `${Math.random()}`),
}];
element.context = 4;
const result =
@ -897,7 +897,7 @@ limitations under the License.
assert.isAtMost(subResult.length, size);
}
const flattened = result
.reduce((a, b) => { return a.concat(b); }, []);
.reduce((a, b) => a.concat(b), []);
assert.deepEqual(flattened, array);
});

View File

@ -169,7 +169,7 @@
},
_panelFloatingDisabled: {
type: Boolean,
value: () => { return window.PANEL_FLOATING_DISABLED; },
value: () => window.PANEL_FLOATING_DISABLED,
},
_editMode: {
type: Boolean,
@ -678,23 +678,25 @@
promises.push(this._getChangeEdit(this._changeNum));
this._loading = true;
return Promise.all(promises).then(r => {
const edit = r[4];
if (edit) {
this.set('_change.revisions.' + edit.commit.commit, {
_number: this.EDIT_NAME,
basePatchNum: edit.base_patch_set_number,
commit: edit.commit,
return Promise.all(promises)
.then(r => {
const edit = r[4];
if (edit) {
this.set('_change.revisions.' + edit.commit.commit, {
_number: this.EDIT_NAME,
basePatchNum: edit.base_patch_set_number,
commit: edit.commit,
});
}
this._loading = false;
this.$.diffHost.comments = this._commentsForDiff;
return this.$.diffHost.reload(true);
})
.then(() => {
this.$.reporting.diffViewFullyLoaded();
// If diff view displayed has not ended yet, it ends here.
this.$.reporting.diffViewDisplayed();
});
}
this._loading = false;
this.$.diffHost.comments = this._commentsForDiff;
return this.$.diffHost.reload(true);
}).then(() => {
this.$.reporting.diffViewFullyLoaded();
// If diff view displayed has not ended yet, it ends here.
this.$.reporting.diffViewDisplayed();
});
}
_changeViewStateChanged(changeViewState) {

View File

@ -281,8 +281,11 @@ limitations under the License.
MockInteractions.pressAndReleaseKeyOn(element, 219, null, '[');
assert.isTrue(element._loading);
assert(diffNavStub.lastCall.calledWithExactly(element._change, 'chell.go',
'10', '5'),
assert(diffNavStub.lastCall.calledWithExactly(
element._change,
'chell.go',
'10',
'5'),
'Should navigate to /c/42/5..10/chell.go');
element._path = 'chell.go';
@ -342,8 +345,11 @@ limitations under the License.
element._path = 'glados.txt';
MockInteractions.pressAndReleaseKeyOn(element, 219, null, '[');
assert(diffNavStub.lastCall.calledWithExactly(element._change, 'chell.go',
'1', PARENT), 'Should navigate to /c/42/1/chell.go');
assert(diffNavStub.lastCall.calledWithExactly(
element._change,
'chell.go',
'1',
PARENT), 'Should navigate to /c/42/1/chell.go');
element._path = 'chell.go';
MockInteractions.pressAndReleaseKeyOn(element, 219, null, '[');
@ -429,12 +435,14 @@ limitations under the License.
suite('url params', () => {
setup(() => {
sandbox.stub(Gerrit.Nav, 'getUrlForDiff', (c, p, pn, bpn) => {
return `${c._number}-${p}-${pn}-${bpn}`;
});
sandbox.stub(Gerrit.Nav, 'getUrlForChange', (c, pn, bpn) => {
return `${c._number}-${pn}-${bpn}`;
});
sandbox.stub(
Gerrit.Nav,
'getUrlForDiff',
(c, p, pn, bpn) => `${c._number}-${p}-${pn}-${bpn}`);
sandbox.stub(
Gerrit.Nav
, 'getUrlForChange',
(c, pn, bpn) => `${c._number}-${pn}-${bpn}`);
});
test('_formattedFiles', () => {

View File

@ -374,10 +374,11 @@
.map(commentRangeFromThreadEl)
.filter(({range}) => range);
for (const removedCommentRange of removedCommentRanges) {
const i = this._commentRanges.findIndex(commentRange => {
return commentRange.side === removedCommentRange.side &&
Gerrit.rangesEqual(commentRange.range, removedCommentRange.range);
});
const i = this._commentRanges
.findIndex(
cr => cr.side === removedCommentRange.side &&
Gerrit.rangesEqual(cr.range, removedCommentRange.range)
);
this.splice('_commentRanges', i, 1);
}
@ -584,7 +585,7 @@
* @param {string=} side
* @param {!Object=} range
*/
_createComment(lineEl, lineNum=undefined, side=undefined, range=undefined) {
_createComment(lineEl, lineNum, side, range) {
const contentText = this.$.diffBuilder.getContentByLineEl(lineEl);
const contentEl = contentText.parentElement;
side = side ||
@ -870,13 +871,12 @@
_computeDiffHeaderItems(diffInfoRecord) {
const diffInfo = diffInfoRecord.base;
if (!diffInfo || !diffInfo.diff_header) { return []; }
return diffInfo.diff_header.filter(item => {
return !(item.startsWith('diff --git ') ||
return diffInfo.diff_header
.filter(item => !(item.startsWith('diff --git ') ||
item.startsWith('index ') ||
item.startsWith('+++ ') ||
item.startsWith('--- ') ||
item === 'Binary files differ');
});
item === 'Binary files differ'));
}
/** @return {boolean} */

View File

@ -235,10 +235,11 @@ limitations under the License.
// Should be recomputed for each available patch
sandbox.stub(element, '_computeBaseDropdownContent');
assert.equal(element._computeBaseDropdownContent.callCount, 0);
commentApiWrapper.loadComments().then().then(() => {
assert.equal(element._computeBaseDropdownContent.callCount, 1);
done();
});
commentApiWrapper.loadComments().then()
.then(() => {
assert.equal(element._computeBaseDropdownContent.callCount, 1);
done();
});
});
test('_computePatchDropdownContent called when basePatchNum updates', () => {
@ -286,9 +287,10 @@ limitations under the License.
// Should be recomputed for each available patch
sandbox.stub(element, '_computePatchDropdownContent');
assert.equal(element._computePatchDropdownContent.callCount, 0);
commentApiWrapper.loadComments().then().then(() => {
done();
});
commentApiWrapper.loadComments().then()
.then(() => {
done();
});
});
test('_computePatchDropdownContent', () => {

View File

@ -208,7 +208,7 @@
return range;
})
// Sort the ranges so that hovering highlights are on top.
.sort((a, b) => a.hovering && !b.hovering ? 1 : 0);
.sort((a, b) => (a.hovering && !b.hovering ? 1 : 0));
}
}

View File

@ -271,39 +271,37 @@
const rangesCache = new Map();
this._processPromise = util.makeCancelable(this._loadHLJS()
.then(() => {
return new Promise(resolve => {
const nextStep = () => {
this._processHandle = null;
this._processNextLine(state, rangesCache);
.then(() => new Promise(resolve => {
const nextStep = () => {
this._processHandle = null;
this._processNextLine(state, rangesCache);
// Move to the next line in the section.
state.lineIndex++;
// Move to the next line in the section.
state.lineIndex++;
// If the section has been exhausted, move to the next one.
if (this._isSectionDone(state)) {
state.lineIndex = 0;
state.sectionIndex++;
}
// If the section has been exhausted, move to the next one.
if (this._isSectionDone(state)) {
state.lineIndex = 0;
state.sectionIndex++;
}
// If all sections have been exhausted, finish.
if (state.sectionIndex >= this.diff.content.length) {
resolve();
this._notify(state);
return;
}
// If all sections have been exhausted, finish.
if (state.sectionIndex >= this.diff.content.length) {
resolve();
this._notify(state);
return;
}
if (state.lineIndex % 100 === 0) {
this._notify(state);
this._processHandle = this.async(nextStep, ASYNC_DELAY);
} else {
nextStep.call(this);
}
};
if (state.lineIndex % 100 === 0) {
this._notify(state);
this._processHandle = this.async(nextStep, ASYNC_DELAY);
} else {
nextStep.call(this);
}
};
this._processHandle = this.async(nextStep, 1);
});
}));
this._processHandle = this.async(nextStep, 1);
})));
return this._processPromise
.finally(() => { this._processPromise = null; });
}

View File

@ -194,7 +194,7 @@ limitations under the License.
const mockHLJS = getMockHLJS();
const highlightSpy = sinon.spy(mockHLJS, 'highlight');
sandbox.stub(element.$.libLoader, 'getHLJS',
() => { return Promise.resolve(mockHLJS); });
() => Promise.resolve(mockHLJS));
const processNextSpy = sandbox.spy(element, '_processNextLine');
const processPromise = element.process();

View File

@ -90,9 +90,10 @@ limitations under the License.
});
test('_paramsChanged', done => {
sandbox.stub(element.$.restAPI, 'getDocumentationSearches', () => {
return Promise.resolve(documentationSearches);
});
sandbox.stub(
element.$.restAPI,
'getDocumentationSearches',
() => Promise.resolve(documentationSearches));
const value = {
filter: 'test',
};

View File

@ -336,13 +336,12 @@ suite('gr-edit-controls tests', () => {
});
});
test('openOpenDialog', () => {
return element.openOpenDialog('test/path.cpp').then(() => {
assert.isFalse(element.$.openDialog.hasAttribute('hidden'));
assert.equal(element.$.openDialog.querySelector('gr-autocomplete').text,
'test/path.cpp');
});
});
test('openOpenDialog', () => element.openOpenDialog('test/path.cpp')
.then(() => {
assert.isFalse(element.$.openDialog.hasAttribute('hidden'));
assert.equal(element.$.openDialog.querySelector('gr-autocomplete').text,
'test/path.cpp');
}));
test('_getDialogFromEvent', () => {
const spy = sandbox.spy(element, '_getDialogFromEvent');

View File

@ -82,9 +82,7 @@ limitations under the License.
sandbox.restore();
});
appElement = () => {
return element.$['app-element'];
};
appElement = () => element.$['app-element'];
test('reporting', () => {
assert.isTrue(appElement().$.reporting.appStarted.calledOnce);

View File

@ -148,14 +148,16 @@
ready() {
super.ready();
Gerrit._endpoints.onNewEndpoint(this.name, this._initModule.bind(this));
Gerrit.awaitPluginsLoaded().then(() => Promise.all(
Gerrit._endpoints.getPlugins(this.name).map(
pluginUrl => this._import(pluginUrl)))
).then(() =>
Gerrit._endpoints
.getDetails(this.name)
.forEach(this._initModule, this)
);
Gerrit.awaitPluginsLoaded()
.then(() => Promise.all(
Gerrit._endpoints.getPlugins(this.name).map(
pluginUrl => this._import(pluginUrl)))
)
.then(() =>
Gerrit._endpoints
.getDetails(this.name)
.forEach(this._initModule, this)
);
}
}

View File

@ -96,10 +96,11 @@ limitations under the License.
assert.equal(module['someparam'], 'barbar');
return decorationHook.getLastAttached().then(element => {
assert.strictEqual(element, module);
}).then(() => {
element.remove();
assert.equal(decorationHook.getAllAttached().length, 0);
});
})
.then(() => {
element.remove();
assert.equal(decorationHook.getAllAttached().length, 0);
});
});
test('replacement', () => {
@ -109,12 +110,14 @@ limitations under the License.
element => element.nodeName === 'OTHER-MODULE');
assert.isOk(module);
assert.equal(module['someparam'], 'foofoo');
return replacementHook.getLastAttached().then(element => {
assert.strictEqual(element, module);
}).then(() => {
element.remove();
assert.equal(replacementHook.getAllAttached().length, 0);
});
return replacementHook.getLastAttached()
.then(element => {
assert.strictEqual(element, module);
})
.then(() => {
element.remove();
assert.equal(replacementHook.getAllAttached().length, 0);
});
});
test('late registration', done => {

View File

@ -81,7 +81,8 @@ limitations under the License.
test('skip theme if preloaded', () => {
sandbox.stub(Gerrit, '_isPluginPreloaded')
.withArgs('preloaded:gerrit-theme').returns(true);
.withArgs('preloaded:gerrit-theme')
.returns(true);
sandbox.stub(Gerrit, '_loadPlugins');
element.config = {
default_theme: '/oof',

View File

@ -56,11 +56,9 @@ limitations under the License.
assert.isOk(element);
});
test('open uses open() from gr-overlay', () => {
return element.open().then(() => {
assert.isTrue(element.$.overlay.open.called);
});
});
test('open uses open() from gr-overlay', () => element.open().then(() => {
assert.isTrue(element.$.overlay.open.called);
}));
test('close uses close() from gr-overlay', () => {
element.close();

View File

@ -69,26 +69,22 @@ limitations under the License.
instance = new GrPopupInterface(plugin);
});
test('open', () => {
return instance.open().then(api => {
assert.strictEqual(api, instance);
const manual = document.createElement('div');
manual.id = 'foobar';
manual.innerHTML = 'manual content';
api._getElement().appendChild(manual);
flushAsynchronousOperations();
assert.equal(
container.querySelector('#foobar').textContent, 'manual content');
});
});
test('open', () => instance.open().then(api => {
assert.strictEqual(api, instance);
const manual = document.createElement('div');
manual.id = 'foobar';
manual.innerHTML = 'manual content';
api._getElement().appendChild(manual);
flushAsynchronousOperations();
assert.equal(
container.querySelector('#foobar').textContent, 'manual content');
}));
test('close', () => {
return instance.open().then(api => {
assert.isTrue(api._getElement().node.opened);
api.close();
assert.isFalse(api._getElement().node.opened);
});
});
test('close', () => instance.open().then(api => {
assert.isTrue(api._getElement().node.opened);
api.close();
assert.isFalse(api._getElement().node.opened);
}));
});
suite('components', () => {
@ -96,20 +92,16 @@ limitations under the License.
instance = new GrPopupInterface(plugin, 'gr-user-test-popup');
});
test('open', () => {
return instance.open().then(api => {
assert.isNotNull(
Polymer.dom(container).querySelector('gr-user-test-popup'));
});
});
test('open', () => instance.open().then(api => {
assert.isNotNull(
Polymer.dom(container).querySelector('gr-user-test-popup'));
}));
test('close', () => {
return instance.open().then(api => {
assert.isTrue(api._getElement().node.opened);
api.close();
assert.isFalse(api._getElement().node.opened);
});
});
test('close', () => instance.open().then(api => {
assert.isTrue(api._getElement().node.opened);
api.close();
assert.isFalse(api._getElement().node.opened);
}));
});
});
</script>

View File

@ -22,7 +22,8 @@
this._title = '(no title)';
// Generate default screen URL token, specific to plugin, and unique(ish).
this._token =
plugin.getPluginName() + Math.random().toString(36).substr(5);
plugin.getPluginName() + Math.random().toString(36)
.substr(5);
this.plugin = plugin;
}

View File

@ -59,9 +59,7 @@
}));
promises.push(this.$.restAPI.getAccountGroups().then(groups => {
this._groups = groups.sort((a, b) => {
return a.name.localeCompare(b.name);
});
this._groups = groups.sort((a, b) => a.name.localeCompare(b.name));
}));
promises.push(this.$.restAPI.getAccountAgreements().then(agreements => {

View File

@ -96,7 +96,8 @@
this.$.newKey.disabled = false;
this._newKey = '';
this.loadData();
}).catch(() => {
})
.catch(() => {
this.$.addButton.disabled = false;
this.$.newKey.disabled = false;
});

View File

@ -90,7 +90,7 @@ limitations under the License.
const lastKey = keys[Object.keys(keys)[1]];
const saveStub = sinon.stub(element.$.restAPI, 'deleteAccountGPGKey',
() => { return Promise.resolve(); });
() => Promise.resolve());
assert.equal(element._keysToRemove.length, 0);
assert.isFalse(element.hasUnsavedChanges);
@ -146,7 +146,7 @@ limitations under the License.
};
const addStub = sinon.stub(element.$.restAPI, 'addAccountGPGKey',
() => { return Promise.resolve(newKeyObject); });
() => Promise.resolve(newKeyObject));
element._newKey = newKeyString;
@ -171,7 +171,7 @@ limitations under the License.
const newKeyString = 'not even close to valid';
const addStub = sinon.stub(element.$.restAPI, 'addAccountGPGKey',
() => { return Promise.reject(new Error('error')); });
() => Promise.reject(new Error('error')));
element._newKey = newKeyString;

View File

@ -30,9 +30,7 @@
loadData() {
return this.$.restAPI.getAccountGroups().then(groups => {
this._groups = groups.sort((a, b) => {
return a.name.localeCompare(b.name);
});
this._groups = groups.sort((a, b) => a.name.localeCompare(b.name));
});
}

View File

@ -58,11 +58,9 @@ limitations under the License.
const nextPassword = 'the new password';
let generateResolve;
const generateStub = sinon.stub(element.$.restAPI,
'generateAccountHttpPassword', () => {
return new Promise(resolve => {
generateResolve = resolve;
});
});
'generateAccountHttpPassword', () => new Promise(resolve => {
generateResolve = resolve;
}));
assert.isNotOk(element._generatedPassword);

View File

@ -40,7 +40,7 @@ limitations under the License.
let menu;
function assertMenuNamesEqual(element, expected) {
const names = element.menuItems.map(i => { return i.name; });
const names = element.menuItems.map(i => i.name);
assert.equal(names.length, expected.length);
for (let i = 0; i < names.length; i++) {
assert.equal(names[i], expected[i]);
@ -53,7 +53,8 @@ limitations under the License.
const selector = 'tr:nth-child(' + (index + 1) + ') .move' +
direction + 'Button';
const button =
element.$$('tbody').querySelector(selector).$$('paper-button');
element.$$('tbody').querySelector(selector)
.$$('paper-button');
MockInteractions.tap(button);
}
@ -147,14 +148,16 @@ limitations under the License.
// Tap the delete button for the middle item.
MockInteractions.tap(element.$$('tbody')
.querySelector('tr:nth-child(2) .remove-button').$$('paper-button'));
.querySelector('tr:nth-child(2) .remove-button')
.$$('paper-button'));
assertMenuNamesEqual(element, ['first name', 'third name']);
// Delete remaining items.
for (let i = 0; i < 2; i++) {
MockInteractions.tap(element.$$('tbody')
.querySelector('tr:first-child .remove-button').$$('paper-button'));
.querySelector('tr:first-child .remove-button')
.$$('paper-button'));
}
assertMenuNamesEqual(element, []);

View File

@ -146,11 +146,13 @@ limitations under the License.
assert.equal(account.email, 'email');
// Save and verify new values are committed.
save().then(() => {
assert.equal(account.name, 'new name');
assert.equal(account.username, 'new username');
assert.equal(account.email, 'email3');
}).then(done);
save()
.then(() => {
assert.equal(account.name, 'new name');
assert.equal(account.username, 'new username');
assert.equal(account.email, 'email3');
})
.then(done);
});
});

View File

@ -70,7 +70,7 @@ limitations under the License.
function stubAddAccountEmail(statusCode) {
return sandbox.stub(element.$.restAPI, 'addAccountEmail',
() => { return Promise.resolve({status: statusCode}); });
() => Promise.resolve({status: statusCode}));
}
setup(done => {
@ -487,9 +487,10 @@ limitations under the License.
setup(() => {
sandbox.stub(element.$.emailEditor, 'loadData');
sandbox.stub(element.$.restAPI, 'confirmEmail', () => {
return new Promise(resolve => { resolveConfirm = resolve; });
});
sandbox.stub(
element.$.restAPI,
'confirmEmail',
() => new Promise(resolve => { resolveConfirm = resolve; }));
element.params = {emailToken: 'foo'};
element.attached();
});

View File

@ -91,7 +91,8 @@
this.$.newKey.disabled = false;
this._newKey = '';
this.push('_keys', key);
}).catch(() => {
})
.catch(() => {
this.$.addButton.disabled = false;
this.$.newKey.disabled = false;
});

View File

@ -81,7 +81,7 @@ limitations under the License.
const lastKey = keys[1];
const saveStub = sinon.stub(element.$.restAPI, 'deleteAccountSSHKey',
() => { return Promise.resolve(); });
() => Promise.resolve());
assert.equal(element._keysToRemove.length, 0);
assert.isFalse(element.hasUnsavedChanges);
@ -132,7 +132,7 @@ limitations under the License.
};
const addStub = sinon.stub(element.$.restAPI, 'addAccountSSHKey',
() => { return Promise.resolve(newKeyObject); });
() => Promise.resolve(newKeyObject));
element._newKey = newKeyString;
@ -157,7 +157,7 @@ limitations under the License.
const newKeyString = 'not even close to valid';
const addStub = sinon.stub(element.$.restAPI, 'addAccountSSHKey',
() => { return Promise.reject(new Error('error')); });
() => Promise.reject(new Error('error')));
element._newKey = newKeyString;

View File

@ -68,9 +68,7 @@
}
return deletePromise
.then(() => {
return this.$.restAPI.saveWatchedProjects(this._projects);
})
.then(() => this.$.restAPI.saveWatchedProjects(this._projects))
.then(projects => {
this._projects = projects;
this._projectsToRemove = [];

View File

@ -88,7 +88,7 @@ limitations under the License.
function getKeysOfRow(row) {
const boxes = rows[row].querySelectorAll('input[checked]');
return Array.prototype.map.call(boxes,
e => { return e.getAttribute('data-key'); });
e => e.getAttribute('data-key'));
}
let checkedKeys = getKeysOfRow(0);

View File

@ -80,9 +80,10 @@
}
_getHasAvatars() {
return this.$.restAPI.getConfig().then(cfg => {
return Promise.resolve(!!(cfg && cfg.plugin && cfg.plugin.has_avatars));
});
return this.$.restAPI.getConfig()
.then(cfg => Promise.resolve(!!(
cfg && cfg.plugin && cfg.plugin.has_avatars
)));
}
}

View File

@ -67,13 +67,11 @@ limitations under the License.
suite('stubbed values for querySuggestions', () => {
setup(() => {
element.querySuggestions = input => {
return Promise.resolve([
suggestion1,
suggestion2,
suggestion3,
]);
};
element.querySuggestions = input => Promise.resolve([
suggestion1,
suggestion2,
suggestion3,
]);
});
});

View File

@ -333,15 +333,15 @@
}
additions() {
return this.accounts.filter(account => {
return account._pendingAdd;
}).map(account => {
if (account._group) {
return {group: account};
} else {
return {account};
}
});
return this.accounts
.filter(account => account._pendingAdd)
.map(account => {
if (account._group) {
return {group: account};
} else {
return {account};
}
});
}
_computeEntryHidden(maxCount, accountsRecord, readonly) {

View File

@ -197,11 +197,13 @@ limitations under the License.
return suggestion._account_id === accountId;
};
element._getSuggestions().then(suggestions => {
assert.deepEqual(suggestions,
[{name: originalSuggestions[0].email,
value: originalSuggestions[0]._account_id}]);
}).then(done);
element._getSuggestions()
.then(suggestions => {
assert.deepEqual(suggestions,
[{name: originalSuggestions[0].email,
value: originalSuggestions[0]._account_id}]);
})
.then(done);
});
});

Some files were not shown because too many files have changed in this diff Show More