Don't try to load access page when there is no project

The prject access page tried to reload itself when the project changed.
However, this also occured when swithcing to a different admin view
and there is no corresponding project (ex: groups). In that case, the
admin view should not be reloaded, so return early.

Bug: Issue 7129
Change-Id: I9c0837c1d7677287b3d3ea9970ee3a804a1bece7
This commit is contained in:
Becky Siegel
2017-08-31 10:52:20 -07:00
parent b1fad26e6f
commit edd3f89e0b
2 changed files with 46 additions and 1 deletions

View File

@@ -41,7 +41,12 @@
Gerrit.URLEncodingBehavior,
],
/**
* @param {string} project
* @return {!Promise}
*/
_projectChanged(project) {
if (!project) { return Promise.resolve(); }
const promises = [];
if (!this._sections) {
this._sections = [];

View File

@@ -78,7 +78,7 @@ limitations under the License.
},
};
const accessStub = sandbox.stub(element.$.restAPI,
'getProjectAccessRights') .returns(Promise.resolve(accessRes));
'getProjectAccessRights').returns(Promise.resolve(accessRes));
const capabilitiesStub = sandbox.stub(element.$.restAPI,
'getCapabilities').returns(Promise.resolve(capabilitiesRes));
const projectStub = sandbox.stub(element.$.restAPI, 'getProject').returns(
@@ -97,6 +97,46 @@ limitations under the License.
});
});
test('_projectChanged when project changes to undefined returns', done => {
const capabilitiesRes = {
accessDatabase: {
id: 'accessDatabase',
name: 'Access Database',
},
};
const accessRes = {
local: {
GLOBAL_CAPABILITIES: {
permissions: {
accessDatabase: {
rules: {
123: {},
},
},
},
},
},
};
const projectRes = {
labels: {
'Code-Review': {},
},
};
const accessStub = sandbox.stub(element.$.restAPI,
'getProjectAccessRights').returns(Promise.resolve(accessRes));
const capabilitiesStub = sandbox.stub(element.$.restAPI,
'getCapabilities').returns(Promise.resolve(capabilitiesRes));
const projectStub = sandbox.stub(element.$.restAPI, 'getProject').returns(
Promise.resolve(projectRes));
element._projectChanged().then(() => {
assert.isFalse(accessStub.called);
assert.isFalse(capabilitiesStub.called);
assert.isFalse(projectStub.called);
done();
});
});
test('_computeParentHref', () => {
const projectName = 'test-project';
assert.equal(element._computeParentHref(projectName),