Merge "Enable message hyperlinking for hidden messages"

This commit is contained in:
Wyatt Allen 2017-03-08 23:24:18 +00:00 committed by Gerrit Code Review
commit 4a77478ddb
2 changed files with 42 additions and 5 deletions

View File

@ -70,7 +70,24 @@
scrollToMessage: function(messageID) {
var el = this.$$('[data-message-id="' + messageID + '"]');
if (!el) { return; }
// If the message is hidden, expand the hidden messages back to that
// point.
if (!el) {
for (var index = 0; index < this._processedMessages.length; index++) {
if (this._processedMessages[index].id === messageID) {
break;
}
}
if (index === this._processedMessages.length) { return; }
var newMessages = this._processedMessages.slice(index,
-this._visibleMessages.length);
// Add newMessages to the beginning of _visibleMessages.
this.splice.apply(this, ['_visibleMessages', 0, 0].concat(newMessages));
// Allow the dom-repeat to stamp.
Polymer.dom.flush();
el = this.$$('[data-message-id="' + messageID + '"]');
}
el.set('message.expanded', true);
var top = el.offsetTop;

View File

@ -56,6 +56,7 @@ limitations under the License.
suite('gr-messages-list tests', function() {
var element;
var messages;
var sandbox;
var getMessages = function() {
return Polymer.dom(element.root).querySelectorAll('gr-message');
@ -66,12 +67,17 @@ limitations under the License.
getConfig: function() { return Promise.resolve({}); },
getLoggedIn: function() { return Promise.resolve(false); },
});
sandbox = sinon.sandbox.create();
element = fixture('basic');
messages = _.times(3, randomMessage);
element.messages = messages;
flushAsynchronousOperations();
});
teardown(function() {
sandbox.restore();
});
test('show some old messages', function() {
assert.isTrue(element.$.messageControlsContainer.hasAttribute('hidden'));
element.messages = _.times(26, randomMessage);
@ -224,8 +230,8 @@ limitations under the License.
allMessageEls[i].set('message.expanded', false);
}
var scrollToStub = sinon.stub(window, 'scrollTo');
var highlightStub = sinon.stub(element, '_highlightEl');
var scrollToStub = sandbox.stub(window, 'scrollTo');
var highlightStub = sandbox.stub(element, '_highlightEl');
element.scrollToMessage('invalid');
@ -241,9 +247,23 @@ limitations under the License.
assert.isTrue(scrollToStub.calledOnce);
assert.isTrue(highlightStub.calledOnce);
});
scrollToStub.restore();
highlightStub.restore();
test('scroll to message offscreen', function() {
var scrollToStub = sandbox.stub(window, 'scrollTo');
var highlightStub = sandbox.stub(element, '_highlightEl');
element.messages = _.times(25, randomMessage);
flushAsynchronousOperations();
assert.isFalse(scrollToStub.called);
assert.isFalse(highlightStub.called);
var messageID = element.messages[1].id;
element.scrollToMessage(messageID);
assert.isTrue(scrollToStub.calledOnce);
assert.isTrue(highlightStub.calledOnce);
assert.equal(element._visibleMessages.length, 24);
assert.isTrue(
element.$$('[data-message-id="' + messageID + '"]')._expanded);
});
test('messages', function() {