Fix diff cursor side for chunks on first or last line of file

I missed this in
https://gerrit-review.googlesource.com/c/gerrit/+/294386, so the cursor
can currently remain invisible opposite an addition or deletion.

Change-Id: Id1a79f6a34ee98ecf3d6410cfb50039742e1bc60
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
index 05915b0..035c1a3 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor.ts
@@ -290,6 +290,8 @@
     this.$.cursorManager.moveToStart();
     if (this.diffRow && !this._isFirstRowOfChunk(this.diffRow)) {
       this.moveToNextChunk(true);
+    } else {
+      this._fixSide();
     }
   }
 
@@ -297,6 +299,8 @@
     this.$.cursorManager.moveToEnd();
     if (this.diffRow && !this._isFirstRowOfChunk(this.diffRow)) {
       this.moveToPreviousChunk();
+    } else {
+      this._fixSide();
     }
   }
 
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.js b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.js
index d462f51..ba81829 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff-cursor/gr-diff-cursor_test.js
@@ -87,12 +87,12 @@
       meta_a: {
         name: 'lorem-ipsum.txt',
         content_type: 'text/plain',
-        lines: 4,
+        lines: 3,
       },
       meta_b: {
         name: 'lorem-ipsum.txt',
         content_type: 'text/plain',
-        lines: 4,
+        lines: 3,
       },
       intraline_status: 'OK',
       change_type: 'MODIFIED',
@@ -103,9 +103,9 @@
         '+++ b/lorem-ipsum.txt',
       ],
       content: [
-        {a: ['old line 1'], b: ['new line 1']},
-        {ab: ['unchanged line 2']},
-        {a: ['old line 3'], b: ['new line 3']},
+        {b: ['new line 1']},
+        {ab: ['unchanged line']},
+        {a: ['old line 2']},
         {ab: ['more unchanged lines']},
       ],
     };
@@ -124,12 +124,15 @@
     // Verify it works on fresh diff.
     cursorElement.moveToFirstChunk();
     assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 0);
+    assert.equal(cursorElement.side, 'right');
 
     // Verify it works from other cursor positions.
-    cursorElement.moveToLastChunk();
-    assert.notEqual(chunks.indexOf(cursorElement.diffRow.parentElement), 0);
+    cursorElement.moveToNextChunk();
+    assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 1);
+    assert.equal(cursorElement.side, 'left');
     cursorElement.moveToFirstChunk();
     assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 0);
+    assert.equal(cursorElement.side, 'right');
   });
 
   test('moveToLastChunk', async () => {
@@ -137,12 +140,12 @@
       meta_a: {
         name: 'lorem-ipsum.txt',
         content_type: 'text/plain',
-        lines: 4,
+        lines: 3,
       },
       meta_b: {
         name: 'lorem-ipsum.txt',
         content_type: 'text/plain',
-        lines: 4,
+        lines: 3,
       },
       intraline_status: 'OK',
       change_type: 'MODIFIED',
@@ -153,10 +156,10 @@
         '+++ b/lorem-ipsum.txt',
       ],
       content: [
-        {ab: ['unchanged line 1']},
-        {a: ['old line 2'], b: ['new line 2']},
-        {ab: ['more unchanged line 3']},
-        {a: ['old line 4'], b: ['new line 4']},
+        {ab: ['unchanged line']},
+        {a: ['old line 2']},
+        {ab: ['more unchanged lines']},
+        {b: ['new line 3']},
       ],
     };
 
@@ -171,12 +174,15 @@
     // Verify it works on fresh diff.
     cursorElement.moveToLastChunk();
     assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 1);
+    assert.equal(cursorElement.side, 'right');
 
     // Verify it works from other cursor positions.
-    cursorElement.moveToFirstChunk();
-    assert.notEqual(chunks.indexOf(cursorElement.diffRow.parentElement), 1);
+    cursorElement.moveToPreviousChunk();
+    assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 0);
+    assert.equal(cursorElement.side, 'left');
     cursorElement.moveToLastChunk();
     assert.equal(chunks.indexOf(cursorElement.diffRow.parentElement), 1);
+    assert.equal(cursorElement.side, 'right');
   });
 
   test('cursor scroll behavior', () => {