Handle cursor positions that don't yield addresses

The gr-diff-cursor#getAddress method returns null when it has no
position or no address corresponds to it's position. However, the
gr-diff-view#_onLineSelected method did not account for this case and
attempted to use null addresses to construct URLs when moving the cursor
to a "File" line of a diff.

With this change, the diff view neither uses line number nor the diff
side when constructing URLs if the cursor does not yield an address.

Change-Id: I628658295bca1f49e0c2d3484e2e0d01e71bcd91
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
index 30f1d58..3bb373f 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js
@@ -734,10 +734,11 @@
       this.$.cursor.moveToLineNumber(detail.number, detail.side);
       if (!this._change) { return; }
       const cursorAddress = this.$.cursor.getAddress();
+      const number = cursorAddress ? cursorAddress.number : undefined;
+      const leftSide = cursorAddress ? cursorAddress.leftSide : undefined;
       const url = Gerrit.Nav.getUrlForDiffById(this._changeNum,
           this._change.project, this._path, this._patchRange.patchNum,
-          this._patchRange.basePatchNum, cursorAddress.number,
-          cursorAddress.leftSide);
+          this._patchRange.basePatchNum, number, leftSide);
       history.replaceState(null, '', url);
     },
 
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
index aad5681..68c2e52 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html
@@ -659,6 +659,20 @@
       assert.isTrue(getUrlStub.called);
     });
 
+    test('_onLineSelected w/o line address', () => {
+      const getUrlStub = sandbox.stub(Gerrit.Nav, 'getUrlForDiffById');
+      sandbox.stub(history, 'replaceState');
+      sandbox.stub(element.$.cursor, 'moveToLineNumber');
+      sandbox.stub(element.$.cursor, 'getAddress').returns(null);
+      element._changeNum = 321;
+      element._change = {_number: 321, project: 'foo/bar'};
+      element._patchRange = {basePatchNum: '3', patchNum: '5'};
+      element._onLineSelected({}, {number: 123, side: 'right'});
+      assert.isTrue(getUrlStub.calledOnce);
+      assert.isUndefined(getUrlStub.lastCall.args[5]);
+      assert.isUndefined(getUrlStub.lastCall.args[6]);
+    });
+
     test('_getDiffViewMode', () => {
       // No user prefs or change view state set.
       assert.equal(element._getDiffViewMode(), 'SIDE_BY_SIDE');