Merge "Distinguish change and diff pages when reporting location changes"

This commit is contained in:
viktard
2018-04-20 16:28:02 +00:00
committed by Gerrit Code Review
2 changed files with 24 additions and 1 deletions

View File

@@ -640,13 +640,24 @@
return;
}
page(pattern, this._loadUserMiddleware.bind(this), data => {
this.$.reporting.locationChanged(handlerName);
this.$.reporting.locationChanged(this._getPageName(handlerName, data));
const promise = opt_authRedirect ?
this._redirectIfNotLoggedIn(data) : Promise.resolve();
promise.then(() => { this[handlerName](data); });
});
},
_getPageName(handlerName, ctx) {
switch (handlerName) {
case '_handleChangeOrDiffRoute': {
const isDiffView = ctx.params[8];
return isDiffView ? Gerrit.Nav.View.DIFF : Gerrit.Nav.View.CHANGE;
}
default:
return handlerName;
}
},
_startRouter() {
const base = this.getBaseUrl();
if (base) {

View File

@@ -1320,6 +1320,12 @@ limitations under the License.
assert.isTrue(normalizeRangeStub.called);
});
test('gr-reporting recognizes change page', () => {
const ctx = makeParams(null, '');
assert.equal(element._getPageName('_handleChangeOrDiffRoute', ctx),
Gerrit.Nav.View.CHANGE);
});
test('diff view', () => {
normalizeRangeStub.returns(false);
sandbox.stub(element, '_generateUrl').returns('foo');
@@ -1337,6 +1343,12 @@ limitations under the License.
assert.isFalse(redirectStub.called);
assert.isTrue(normalizeRangeStub.called);
});
test('gr-reporting recognizes diff page', () => {
const ctx = makeParams('foo/bar/baz', 'b44');
assert.equal(element._getPageName('_handleChangeOrDiffRoute', ctx),
Gerrit.Nav.View.DIFF);
});
});
test('_handleDiffEditRoute', () => {