Merge "Fix extra navigateToDiff call on swiching files"

This commit is contained in:
Tao Zhou
2019-08-06 16:17:25 +00:00
committed by Gerrit Code Review
2 changed files with 34 additions and 1 deletions

View File

@@ -597,11 +597,11 @@
this._initCursor(this.params); this._initCursor(this.params);
this._changeNum = value.changeNum; this._changeNum = value.changeNum;
this._path = value.path;
this._patchRange = { this._patchRange = {
patchNum: value.patchNum, patchNum: value.patchNum,
basePatchNum: value.basePatchNum || PARENT, basePatchNum: value.basePatchNum || PARENT,
}; };
this._path = value.path;
// NOTE: This may be called before attachment (e.g. while parentElement is // NOTE: This may be called before attachment (e.g. while parentElement is
// null). Fire title-change in an async so that, if attachment to the DOM // null). Fire title-change in an async so that, if attachment to the DOM

View File

@@ -1147,5 +1147,38 @@ limitations under the License.
1, 1,
]); ]);
}); });
test('File change should trigger navigateToDiff once', () => {
element._fileList = ['file1', 'file2', 'file3'];
sandbox.stub(element, '_getLineOfInterest');
sandbox.stub(element, '_initCursor');
sandbox.stub(Gerrit.Nav, 'navigateToDiff');
// Load file1
element._paramsChanged({
view: Gerrit.Nav.View.DIFF,
patchNum: 1,
changeNum: 101,
project: 'test-project',
path: 'file1',
});
assert.isTrue(Gerrit.Nav.navigateToDiff.notCalled);
// Switch to file2
element.$.dropdown.value = 'file2';
assert.isTrue(Gerrit.Nav.navigateToDiff.calledOnce);
// This is to mock the param change triggered by above navigate
element._paramsChanged({
view: Gerrit.Nav.View.DIFF,
patchNum: 1,
changeNum: 101,
project: 'test-project',
path: 'file2',
});
// No extra call
assert.isTrue(Gerrit.Nav.navigateToDiff.calledOnce);
});
}); });
</script> </script>