diff --git a/polygerrit-ui/app/elements/gr-change-list.html b/polygerrit-ui/app/elements/gr-change-list.html index 8c0b796967..a966ea8ed4 100644 --- a/polygerrit-ui/app/elements/gr-change-list.html +++ b/polygerrit-ui/app/elements/gr-change-list.html @@ -58,8 +58,7 @@ limitations under the License.
[[_groupTitle(groupIndex)]]
@@ -118,10 +117,6 @@ limitations under the License. 'j k o enter': '_handleKey', }, - _isSelected: function(groupIndex, index) { - return index == this.selectedIndex; - }, - _changesChanged: function(changes) { this.groups = [changes]; }, @@ -139,6 +134,13 @@ limitations under the License. } } } + + // Allow for the elements to render before resetting the selectedIndex. + this.async(function() { + // Setting the property would have no effect if the index is 0 (e.g. + // at element init) so call the observer directly. + this._selectedIndexChanged(0); + }.bind(this), 1); }, _groupTitle: function(groupIndex) { diff --git a/polygerrit-ui/app/test/gr-change-list-test.html b/polygerrit-ui/app/test/gr-change-list-test.html index d713368659..3bcf4b59a0 100644 --- a/polygerrit-ui/app/test/gr-change-list-test.html +++ b/polygerrit-ui/app/test/gr-change-list-test.html @@ -48,7 +48,7 @@ limitations under the License. element = fixture('basic'); }); - test('keyboard shortcuts', function() { + test('keyboard shortcuts', function(done) { element.changes = [ {_number: 0}, {_number: 1}, @@ -60,28 +60,32 @@ limitations under the License. assert.equal(elementItems.length, 3); assert.equal(element.selectedIndex, 0); - MockInteractions.pressAndReleaseKeyOn(element, 74); // 'j' - assert.equal(element.selectedIndex, 1); - MockInteractions.pressAndReleaseKeyOn(element, 74); // 'j' + element.async(function() { + assert.isTrue(elementItems[0].selected); + MockInteractions.pressAndReleaseKeyOn(element, 74); // 'j' + assert.equal(element.selectedIndex, 1); + MockInteractions.pressAndReleaseKeyOn(element, 74); // 'j' - var showStub = sinon.stub(page, 'show'); - assert.equal(element.selectedIndex, 2); - MockInteractions.pressAndReleaseKeyOn(element, 13); // 'enter' - assert(showStub.lastCall.calledWithExactly('/c/2/'), - 'Should navigate to /c/2/'); + var showStub = sinon.stub(page, 'show'); + assert.equal(element.selectedIndex, 2); + MockInteractions.pressAndReleaseKeyOn(element, 13); // 'enter' + assert(showStub.lastCall.calledWithExactly('/c/2/'), + 'Should navigate to /c/2/'); - MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' - assert.equal(element.selectedIndex, 1); - MockInteractions.pressAndReleaseKeyOn(element, 13); // 'enter' - assert(showStub.lastCall.calledWithExactly('/c/1/'), - 'Should navigate to /c/1/'); + MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' + assert.equal(element.selectedIndex, 1); + MockInteractions.pressAndReleaseKeyOn(element, 13); // 'enter' + assert(showStub.lastCall.calledWithExactly('/c/1/'), + 'Should navigate to /c/1/'); - MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' - MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' - MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' - assert.equal(element.selectedIndex, 0); + MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' + MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' + MockInteractions.pressAndReleaseKeyOn(element, 75); // 'k' + assert.equal(element.selectedIndex, 0); - showStub.restore(); + showStub.restore(); + done() + }, 1); }); });