Merge "Centralize URL upgrading to within router"
This commit is contained in:
@@ -228,7 +228,7 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('submit change', done => {
|
test('submit change', done => {
|
||||||
sandbox.stub(element.$.restAPI, '_getFromProjectLookup')
|
sandbox.stub(element.$.restAPI, 'getFromProjectLookup')
|
||||||
.returns(Promise.resolve('test'));
|
.returns(Promise.resolve('test'));
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown',
|
sandbox.stub(element, 'fetchIsLatestKnown',
|
||||||
() => { return Promise.resolve(true); });
|
() => { return Promise.resolve(true); });
|
||||||
|
@@ -958,7 +958,6 @@
|
|||||||
if (!change) {
|
if (!change) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
this._upgradeUrl(change, this.params);
|
|
||||||
this._processEdit(change, edit);
|
this._processEdit(change, edit);
|
||||||
// Issue 4190: Coalesce missing topics to null.
|
// Issue 4190: Coalesce missing topics to null.
|
||||||
if (!change.topic) { change.topic = null; }
|
if (!change.topic) { change.topic = null; }
|
||||||
@@ -995,13 +994,6 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_upgradeUrl(change, params) {
|
|
||||||
const project = change.project;
|
|
||||||
if (!params.project || project !== params.project) {
|
|
||||||
Gerrit.Nav.upgradeUrl(Object.assign({}, params, {project}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_getComments() {
|
_getComments() {
|
||||||
return this.$.restAPI.getDiffComments(this._changeNum).then(comments => {
|
return this.$.restAPI.getDiffComments(this._changeNum).then(comments => {
|
||||||
this._comments = comments;
|
this._comments = comments;
|
||||||
|
@@ -835,7 +835,6 @@ limitations under the License.
|
|||||||
|
|
||||||
test('topic is coalesced to null', done => {
|
test('topic is coalesced to null', done => {
|
||||||
sandbox.stub(element, '_changeChanged');
|
sandbox.stub(element, '_changeChanged');
|
||||||
sandbox.stub(element, '_upgradeUrl');
|
|
||||||
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
id: '123456789',
|
id: '123456789',
|
||||||
@@ -853,7 +852,6 @@ limitations under the License.
|
|||||||
|
|
||||||
test('commit sha is populated from getChangeDetail', done => {
|
test('commit sha is populated from getChangeDetail', done => {
|
||||||
sandbox.stub(element, '_changeChanged');
|
sandbox.stub(element, '_changeChanged');
|
||||||
sandbox.stub(element, '_upgradeUrl');
|
|
||||||
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
id: '123456789',
|
id: '123456789',
|
||||||
@@ -871,7 +869,6 @@ limitations under the License.
|
|||||||
|
|
||||||
test('edit is added to change', () => {
|
test('edit is added to change', () => {
|
||||||
sandbox.stub(element, '_changeChanged');
|
sandbox.stub(element, '_changeChanged');
|
||||||
sandbox.stub(element, '_upgradeUrl');
|
|
||||||
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
sandbox.stub(element.$.restAPI, 'getChangeDetail', () => {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
id: '123456789',
|
id: '123456789',
|
||||||
@@ -1333,31 +1330,5 @@ limitations under the License.
|
|||||||
element._processEdit(mockChange = _.cloneDeep(change), edit);
|
element._processEdit(mockChange = _.cloneDeep(change), edit);
|
||||||
assert.equal(element._patchRange.patchNum, 'baz');
|
assert.equal(element._patchRange.patchNum, 'baz');
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('_upgradeUrl calls', () => {
|
|
||||||
let upgradeStub;
|
|
||||||
const mockChange = {project: 'test'};
|
|
||||||
|
|
||||||
setup(() => {
|
|
||||||
upgradeStub = sandbox.stub(window.Gerrit.Nav, 'upgradeUrl');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app.params.project undefined', () => {
|
|
||||||
element._upgradeUrl(mockChange, {});
|
|
||||||
assert.isTrue(upgradeStub.called);
|
|
||||||
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app.params.project differs from change.project', () => {
|
|
||||||
element._upgradeUrl(mockChange, {project: 'demo'});
|
|
||||||
assert.isTrue(upgradeStub.called);
|
|
||||||
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app.params.project === change.project', () => {
|
|
||||||
element._upgradeUrl(mockChange, {project: 'test'});
|
|
||||||
assert.isFalse(upgradeStub.called);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -67,6 +67,21 @@
|
|||||||
|
|
||||||
Gerrit.Nav.setup(url => { page.show(url); }, generateUrl, upgradeUrl);
|
Gerrit.Nav.setup(url => { page.show(url); }, generateUrl, upgradeUrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a set of params without a project, gets the project from the rest
|
||||||
|
* API project lookup and then sets the app params.
|
||||||
|
*
|
||||||
|
* @param {?Object} params
|
||||||
|
*/
|
||||||
|
const normalizeLegacyRouteParams = params => {
|
||||||
|
if (!params.changeNum) { return; }
|
||||||
|
|
||||||
|
restAPI.getFromProjectLookup(params.changeNum).then(project => {
|
||||||
|
params.project = project;
|
||||||
|
normalizePatchRangeParams(params);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
page((ctx, next) => {
|
page((ctx, next) => {
|
||||||
document.body.scrollTop = 0;
|
document.body.scrollTop = 0;
|
||||||
@@ -464,7 +479,6 @@
|
|||||||
};
|
};
|
||||||
normalizePatchRangeParams(params);
|
normalizePatchRangeParams(params);
|
||||||
app.params = params;
|
app.params = params;
|
||||||
upgradeUrl(params);
|
|
||||||
restAPI.setInProjectLookup(params.changeNum, params.project);
|
restAPI.setInProjectLookup(params.changeNum, params.project);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -478,8 +492,7 @@
|
|||||||
view: Gerrit.Nav.View.CHANGE,
|
view: Gerrit.Nav.View.CHANGE,
|
||||||
};
|
};
|
||||||
|
|
||||||
normalizePatchRangeParams(params);
|
normalizeLegacyRouteParams(params);
|
||||||
app.params = params;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Matches /c/<changeNum>/[<basePatchNum>..]<patchNum>/<path>.
|
// Matches /c/<changeNum>/[<basePatchNum>..]<patchNum>/<path>.
|
||||||
@@ -502,8 +515,7 @@
|
|||||||
view: Gerrit.Nav.View.DIFF,
|
view: Gerrit.Nav.View.DIFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
normalizePatchRangeParams(params);
|
normalizeLegacyRouteParams(params);
|
||||||
app.params = params;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
page(/^\/settings\/(agreements|new-agreement)/, loadUser, data => {
|
page(/^\/settings\/(agreements|new-agreement)/, loadUser, data => {
|
||||||
|
@@ -179,17 +179,9 @@
|
|||||||
_getChangeDetail(changeNum) {
|
_getChangeDetail(changeNum) {
|
||||||
return this.$.restAPI.getDiffChangeDetail(changeNum).then(change => {
|
return this.$.restAPI.getDiffChangeDetail(changeNum).then(change => {
|
||||||
this._change = change;
|
this._change = change;
|
||||||
this._upgradeUrl(change, this.params);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_upgradeUrl(change, params) {
|
|
||||||
const project = change.project;
|
|
||||||
if (!params.project || project !== params.project) {
|
|
||||||
Gerrit.Nav.upgradeUrl(Object.assign({}, params, {project}));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
_getChangeEdit(changeNum) {
|
_getChangeEdit(changeNum) {
|
||||||
return this.$.restAPI.getChangeEdit(this._changeNum);
|
return this.$.restAPI.getChangeEdit(this._changeNum);
|
||||||
},
|
},
|
||||||
|
@@ -463,7 +463,6 @@ limitations under the License.
|
|||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getDiffComments() { return Promise.resolve({}); },
|
getDiffComments() { return Promise.resolve({}); },
|
||||||
});
|
});
|
||||||
sandbox.stub(element, '_upgradeUrl');
|
|
||||||
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
||||||
() => Promise.resolve());
|
() => Promise.resolve());
|
||||||
sandbox.stub(element.$.diff, 'reload');
|
sandbox.stub(element.$.diff, 'reload');
|
||||||
@@ -509,7 +508,6 @@ limitations under the License.
|
|||||||
stub('gr-rest-api-interface', {
|
stub('gr-rest-api-interface', {
|
||||||
getDiffComments() { return Promise.resolve({}); },
|
getDiffComments() { return Promise.resolve({}); },
|
||||||
});
|
});
|
||||||
sandbox.stub(element, '_upgradeUrl');
|
|
||||||
sandbox.stub(element.$.diff, 'reload');
|
sandbox.stub(element.$.diff, 'reload');
|
||||||
sandbox.stub(element, '_loadHash');
|
sandbox.stub(element, '_loadHash');
|
||||||
|
|
||||||
@@ -732,32 +730,6 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('_upgradeUrl calls', () => {
|
|
||||||
let upgradeStub;
|
|
||||||
const mockChange = {project: 'test'};
|
|
||||||
|
|
||||||
setup(() => {
|
|
||||||
upgradeStub = sandbox.stub(window.Gerrit.Nav, 'upgradeUrl');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app.params.project undefined', () => {
|
|
||||||
element._upgradeUrl(mockChange, {});
|
|
||||||
assert.isTrue(upgradeStub.called);
|
|
||||||
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app.params.project differs from change.project', () => {
|
|
||||||
element._upgradeUrl(mockChange, {project: 'demo'});
|
|
||||||
assert.isTrue(upgradeStub.called);
|
|
||||||
assert.deepEqual(upgradeStub.lastCall.args[0], mockChange);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('app.params.project === change.project', () => {
|
|
||||||
element._upgradeUrl(mockChange, {project: 'test'});
|
|
||||||
assert.isFalse(upgradeStub.called);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('_computeEditLoaded', () => {
|
test('_computeEditLoaded', () => {
|
||||||
const callCompute = range => element._computeEditLoaded({base: range});
|
const callCompute = range => element._computeEditLoaded({base: range});
|
||||||
assert.isFalse(callCompute({}));
|
assert.isFalse(callCompute({}));
|
||||||
|
@@ -1556,7 +1556,7 @@
|
|||||||
// stack every time _changeBaseURL is called without a project.
|
// stack every time _changeBaseURL is called without a project.
|
||||||
const projectPromise = opt_project ?
|
const projectPromise = opt_project ?
|
||||||
Promise.resolve(opt_project) :
|
Promise.resolve(opt_project) :
|
||||||
this._getFromProjectLookup(changeNum);
|
this.getFromProjectLookup(changeNum);
|
||||||
return projectPromise.then(project => {
|
return projectPromise.then(project => {
|
||||||
let url = `/changes/${encodeURIComponent(project)}~${changeNum}`;
|
let url = `/changes/${encodeURIComponent(project)}~${changeNum}`;
|
||||||
if (opt_patchNum) {
|
if (opt_patchNum) {
|
||||||
@@ -1732,7 +1732,7 @@
|
|||||||
* @param {string|number} changeNum
|
* @param {string|number} changeNum
|
||||||
* @return {!Promise<string|undefined>}
|
* @return {!Promise<string|undefined>}
|
||||||
*/
|
*/
|
||||||
_getFromProjectLookup(changeNum) {
|
getFromProjectLookup(changeNum) {
|
||||||
const project = this._projectLookup[changeNum];
|
const project = this._projectLookup[changeNum];
|
||||||
if (project) { return Promise.resolve(project); }
|
if (project) { return Promise.resolve(project); }
|
||||||
return this.getChange(changeNum).then(change => {
|
return this.getChange(changeNum).then(change => {
|
||||||
|
@@ -269,7 +269,7 @@ limitations under the License.
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('differing patch diff comments are properly grouped', done => {
|
test('differing patch diff comments are properly grouped', done => {
|
||||||
sandbox.stub(element, '_getFromProjectLookup')
|
sandbox.stub(element, 'getFromProjectLookup')
|
||||||
.returns(Promise.resolve('test'));
|
.returns(Promise.resolve('test'));
|
||||||
sandbox.stub(element, 'fetchJSON', url => {
|
sandbox.stub(element, 'fetchJSON', url => {
|
||||||
if (url === '/changes/test~42/revisions/1') {
|
if (url === '/changes/test~42/revisions/1') {
|
||||||
@@ -780,11 +780,11 @@ limitations under the License.
|
|||||||
assert.deepEqual(element._projectLookup, {test: 'project'});
|
assert.deepEqual(element._projectLookup, {test: 'project'});
|
||||||
});
|
});
|
||||||
|
|
||||||
suite('_getFromProjectLookup', () => {
|
suite('getFromProjectLookup', () => {
|
||||||
test('getChange fails', () => {
|
test('getChange fails', () => {
|
||||||
sandbox.stub(element, 'getChange')
|
sandbox.stub(element, 'getChange')
|
||||||
.returns(Promise.resolve());
|
.returns(Promise.resolve());
|
||||||
return element._getFromProjectLookup().then(val => {
|
return element.getFromProjectLookup().then(val => {
|
||||||
assert.strictEqual(val, undefined);
|
assert.strictEqual(val, undefined);
|
||||||
assert.deepEqual(element._projectLookup, {});
|
assert.deepEqual(element._projectLookup, {});
|
||||||
});
|
});
|
||||||
@@ -793,7 +793,7 @@ limitations under the License.
|
|||||||
test('getChange succeeds, no project', () => {
|
test('getChange succeeds, no project', () => {
|
||||||
sandbox.stub(element, 'getChange')
|
sandbox.stub(element, 'getChange')
|
||||||
.returns(Promise.resolve({}));
|
.returns(Promise.resolve({}));
|
||||||
return element._getFromProjectLookup().then(val => {
|
return element.getFromProjectLookup().then(val => {
|
||||||
assert.strictEqual(val, undefined);
|
assert.strictEqual(val, undefined);
|
||||||
assert.deepEqual(element._projectLookup, {});
|
assert.deepEqual(element._projectLookup, {});
|
||||||
});
|
});
|
||||||
@@ -802,7 +802,7 @@ limitations under the License.
|
|||||||
test('getChange succeeds with project', () => {
|
test('getChange succeeds with project', () => {
|
||||||
sandbox.stub(element, 'getChange')
|
sandbox.stub(element, 'getChange')
|
||||||
.returns(Promise.resolve({project: 'project'}));
|
.returns(Promise.resolve({project: 'project'}));
|
||||||
return element._getFromProjectLookup('test').then(val => {
|
return element.getFromProjectLookup('test').then(val => {
|
||||||
assert.equal(val, 'project');
|
assert.equal(val, 'project');
|
||||||
assert.deepEqual(element._projectLookup, {test: 'project'});
|
assert.deepEqual(element._projectLookup, {test: 'project'});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user