208 lines
6.7 KiB
HTML
208 lines
6.7 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
Copyright (C) 2016 The Android Open Source Project
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
-->
|
|
|
|
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
|
|
<title>gr-messages-list</title>
|
|
|
|
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
|
|
<script src="../../../bower_components/web-component-tester/browser.js"></script>
|
|
|
|
<link rel="import" href="../../../bower_components/iron-test-helpers/iron-test-helpers.html">
|
|
<link rel="import" href="gr-messages-list.html">
|
|
|
|
<test-fixture id="basic">
|
|
<template>
|
|
<gr-messages-list></gr-messages-list>
|
|
</template>
|
|
</test-fixture>
|
|
|
|
<script>
|
|
suite('gr-messages-list tests', function() {
|
|
var element;
|
|
var messages;
|
|
|
|
var randomMessage = function(opt_params) {
|
|
var params = opt_params || {};
|
|
var author1 = {
|
|
_account_id: 1115495,
|
|
name: 'Andrew Bonventre',
|
|
email: 'andybons@chromium.org',
|
|
};
|
|
return {
|
|
id: params.id || Math.random().toString(),
|
|
date: params.date || '2016-01-12 20:28:33.038000',
|
|
message: params.message || Math.random().toString(),
|
|
_revision_number: params._revision_number || 1,
|
|
author: params.author || author1,
|
|
};
|
|
};
|
|
|
|
setup(function() {
|
|
stub('gr-rest-api-interface', {
|
|
getConfig: function() { return Promise.resolve({}); },
|
|
getLoggedIn: function() { return Promise.resolve(false); },
|
|
});
|
|
element = fixture('basic');
|
|
messages = _.times(3, randomMessage);
|
|
element.messages = messages;
|
|
flushAsynchronousOperations();
|
|
});
|
|
|
|
test('expand/collapse all', function() {
|
|
var allMessageEls =
|
|
Polymer.dom(element.root).querySelectorAll('gr-message');
|
|
for (var i = 0; i < allMessageEls.length; i++) {
|
|
allMessageEls[i].expanded = false;
|
|
}
|
|
MockInteractions.tap(allMessageEls[1]);
|
|
assert.isTrue(allMessageEls[1].expanded);
|
|
|
|
MockInteractions.tap(element.$$('.header gr-button'));
|
|
allMessageEls =
|
|
Polymer.dom(element.root).querySelectorAll('gr-message');
|
|
for (var i = 0; i < allMessageEls.length; i++) {
|
|
assert.isTrue(allMessageEls[i].expanded);
|
|
}
|
|
|
|
MockInteractions.tap(element.$$('.header gr-button'));
|
|
allMessageEls =
|
|
Polymer.dom(element.root).querySelectorAll('gr-message');
|
|
for (var i = 0; i < allMessageEls.length; i++) {
|
|
assert.isFalse(allMessageEls[i].expanded);
|
|
}
|
|
});
|
|
|
|
test('scroll to message', function() {
|
|
var allMessageEls =
|
|
Polymer.dom(element.root).querySelectorAll('gr-message');
|
|
for (var i = 0; i < allMessageEls.length; i++) {
|
|
allMessageEls[i].expanded = false;
|
|
}
|
|
|
|
var scrollToStub = sinon.stub(window, 'scrollTo');
|
|
var highlightStub = sinon.stub(element, '_highlightEl');
|
|
|
|
element.scrollToMessage('invalid');
|
|
|
|
for (var i = 0; i < allMessageEls.length; i++) {
|
|
assert.isFalse(allMessageEls[i].expanded,
|
|
'expected gr-message ' + i + ' to not be expanded');
|
|
}
|
|
|
|
var messageID = messages[1].id;
|
|
element.scrollToMessage(messageID);
|
|
assert.isTrue(
|
|
element.$$('[data-message-id="' + messageID + '"]').expanded);
|
|
|
|
assert.isTrue(scrollToStub.calledOnce);
|
|
assert.isTrue(highlightStub.calledOnce);
|
|
|
|
scrollToStub.restore();
|
|
highlightStub.restore();
|
|
});
|
|
|
|
test('messages', function() {
|
|
var author = {
|
|
_account_id: 42,
|
|
name: 'Marvin the Paranoid Android',
|
|
email: 'marvin@sirius.org',
|
|
};
|
|
var comments = {
|
|
file1: [
|
|
{
|
|
message: 'message text',
|
|
updated: '2016-09-27 00:18:03.000000000',
|
|
in_reply_to: '6505d749_f0bec0aa',
|
|
line: 62,
|
|
id: '6505d749_10ed44b2',
|
|
patch_set: 2,
|
|
author: {
|
|
email: 'some@email.com',
|
|
_account_id: 123,
|
|
},
|
|
},
|
|
{
|
|
message: 'message text',
|
|
updated: '2016-09-27 00:18:03.000000000',
|
|
in_reply_to: 'c5912363_6b820105',
|
|
line: 42,
|
|
id: '450a935e_0f1c05db',
|
|
patch_set: 2,
|
|
author: author,
|
|
},
|
|
{
|
|
message: 'message text',
|
|
updated: '2016-09-27 00:18:03.000000000',
|
|
in_reply_to: '6505d749_f0bec0aa',
|
|
line: 62,
|
|
id: '6505d749_10ed44b2',
|
|
patch_set: 2,
|
|
author: author,
|
|
},
|
|
],
|
|
file2: [
|
|
{
|
|
message: 'message text',
|
|
updated: '2016-09-27 00:18:03.000000000',
|
|
in_reply_to: 'c5912363_4b7d450a',
|
|
line: 132,
|
|
id: '450a935e_4f260d25',
|
|
patch_set: 2,
|
|
author: author,
|
|
},
|
|
]
|
|
};
|
|
var messages = [].concat(
|
|
randomMessage(),
|
|
{
|
|
_index: 5,
|
|
_revision_number: 4,
|
|
message: 'Uploaded patch set 4.',
|
|
date: '2016-09-28 13:36:33.000000000',
|
|
author: author,
|
|
id: '8c19ccc949c6d482b061be6a28e10782abf0e7af',
|
|
},
|
|
{
|
|
_index: 6,
|
|
_revision_number: 4,
|
|
message: 'Patch Set 4:\n\n(6 comments)',
|
|
date: '2016-09-28 13:36:33.000000000',
|
|
author: author,
|
|
id: 'e7bfdbc842f6b6d8064bc68e0f52b673f40c0ca5',
|
|
}
|
|
);
|
|
element.comments = comments;
|
|
element.messages = messages;
|
|
var isAuthor = function(author, message) {
|
|
return message.author._account_id === author._account_id;
|
|
};
|
|
var isMarvin = isAuthor.bind(null, author);
|
|
flushAsynchronousOperations();
|
|
var messageElements =
|
|
Polymer.dom(element.root).querySelectorAll('gr-message');
|
|
assert.equal(messageElements.length, messages.length);
|
|
assert.deepEqual(messageElements[1].message, messages[1]);
|
|
assert.deepEqual(messageElements[2].message, messages[2]);
|
|
assert.deepEqual(messageElements[1].comments.file1,
|
|
comments.file1.filter(isMarvin));
|
|
assert.deepEqual(messageElements[1].comments.file2,
|
|
comments.file2.filter(isMarvin));
|
|
assert.deepEqual(messageElements[2].comments, {});
|
|
});
|
|
});
|
|
</script>
|