1aa7b90258
This breaks gr-diff-view into three components: + gr-diff-view: manages keyboard shortcuts and fetching change information. + gr-diff: fetches diff, comment, and draft data. Normalizes it for use in rendering via gr-diff-side. + gr-diff-side: renders the normalized model constructed in gr-diff. Comments are not implemented using the new model for the sake of the reviewer's sanity. Feature: Issue 3648 Feature: Issue 3663 Change-Id: I60b8a61ef4349d0b7e45b105bb704aa1c07cd358
269 lines
7.5 KiB
HTML
269 lines
7.5 KiB
HTML
<!DOCTYPE html>
|
||
<!--
|
||
Copyright (C) 2015 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-diff</title>
|
||
|
||
<script src="../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
|
||
<script src="../../bower_components/web-component-tester/browser.js"></script>
|
||
<script src="../scripts/changes.js"></script>
|
||
<script src="../scripts/fake-app.js"></script>
|
||
<script src="../scripts/util.js"></script>
|
||
|
||
<link rel="import" href="../../bower_components/iron-test-helpers/iron-test-helpers.html">
|
||
<link rel="import" href="../elements/gr-diff.html">
|
||
|
||
<test-fixture id="basic">
|
||
<template>
|
||
<gr-diff auto></gr-diff>
|
||
</template>
|
||
</test-fixture>
|
||
|
||
<script>
|
||
suite('gr-diff tests', function() {
|
||
var element;
|
||
var server;
|
||
|
||
setup(function() {
|
||
element = fixture('basic');
|
||
element.changeNum = 42;
|
||
element.path = 'sieve.go';
|
||
|
||
server = sinon.fakeServer.create();
|
||
server.respondWith(
|
||
'GET',
|
||
/\/changes\/42\/revisions\/(1|2)\/files\/sieve\.go\/diff(.*)/,
|
||
[
|
||
200,
|
||
{ 'Content-Type': 'application/json' },
|
||
')]}\'\n' +
|
||
JSON.stringify({
|
||
change_type: 'MODIFIED',
|
||
content: [
|
||
{ab: ['doin some codez and stuffs']},
|
||
]
|
||
}),
|
||
]
|
||
);
|
||
server.respondWith(
|
||
'GET',
|
||
'/changes/42/revisions/1/comments',
|
||
[
|
||
200,
|
||
{ 'Content-Type': 'application/json' },
|
||
')]}\'\n' +
|
||
JSON.stringify({
|
||
'/COMMIT_MSG': [],
|
||
'sieve.go': [
|
||
{
|
||
author: {
|
||
_account_id: 1000000,
|
||
name: 'Andrew Bonventre',
|
||
email: 'andybons@gmail.com',
|
||
},
|
||
id: '9af53d3f_5f2b8b82',
|
||
line: 1,
|
||
message: 'this isn’t quite right',
|
||
updated: '2015-12-10 02:50:21.627000000',
|
||
},
|
||
{
|
||
author: {
|
||
_account_id: 1000000,
|
||
name: 'Andrew Bonventre',
|
||
email: 'andybons@gmail.com',
|
||
},
|
||
id: '9af53d3f_bf1cd76b',
|
||
line: 1,
|
||
side: 'PARENT',
|
||
message: 'how did this work in the first place?',
|
||
updated: '2015-12-10 00:08:42.255000000',
|
||
},
|
||
],
|
||
}),
|
||
]
|
||
);
|
||
server.respondWith(
|
||
'GET',
|
||
'/changes/42/revisions/2/comments',
|
||
[
|
||
200,
|
||
{ 'Content-Type': 'application/json' },
|
||
')]}\'\n' +
|
||
JSON.stringify({
|
||
'/COMMIT_MSG': [],
|
||
'sieve.go': [
|
||
{
|
||
author: {
|
||
_account_id: 1010008,
|
||
name: 'Dave Borowitz',
|
||
email: 'dborowitz@google.com',
|
||
},
|
||
id: '001a2067_f30f3048',
|
||
line: 17,
|
||
message: 'What on earth are you thinking, here?',
|
||
updated: '2015-12-12 02:51:37.973000000',
|
||
},
|
||
{
|
||
author: {
|
||
_account_id: 1010008,
|
||
name: 'Dave Borowitz',
|
||
email: 'dborowitz@google.com',
|
||
},
|
||
id: '001a2067_f6b1b1c8',
|
||
in_reply_to: '9af53d3f_bf1cd76b',
|
||
line: 1,
|
||
side: 'PARENT',
|
||
message: 'Yeah not sure how this worked either?',
|
||
updated: '2015-12-12 02:51:37.973000000',
|
||
},
|
||
{
|
||
author: {
|
||
_account_id: 1000000,
|
||
name: 'Andrew Bonventre',
|
||
email: 'andybons@gmail.com',
|
||
},
|
||
id: 'a0407443_30dfe8fb',
|
||
in_reply_to: '001a2067_f30f3048',
|
||
line: 17,
|
||
message: '¯\\_(ツ)_/¯',
|
||
updated: '2015-12-12 18:50:21.627000000',
|
||
},
|
||
],
|
||
}),
|
||
]
|
||
);
|
||
});
|
||
|
||
teardown(function() {
|
||
server.restore();
|
||
});
|
||
|
||
test('comments with parent', function(done) {
|
||
element.patchRange = {
|
||
basePatchNum: 'PARENT',
|
||
patchNum: 1,
|
||
};
|
||
|
||
server.respond();
|
||
|
||
element._diffRequestsPromise.then(function() {
|
||
assert.equal(element._baseComments.length, 1);
|
||
assert.equal(element._comments.length, 1);
|
||
assert.equal(element._baseDrafts.length, 0);
|
||
assert.equal(element._drafts.length, 0);
|
||
done();
|
||
});
|
||
});
|
||
|
||
test('comments between two patches', function(done) {
|
||
element.patchRange = {
|
||
basePatchNum: 1,
|
||
patchNum: 2,
|
||
};
|
||
|
||
server.respond();
|
||
|
||
element._diffRequestsPromise.then(function() {
|
||
assert.equal(element._baseComments.length, 1);
|
||
assert.equal(element._comments.length, 2);
|
||
assert.equal(element._baseDrafts.length, 0);
|
||
assert.equal(element._drafts.length, 0);
|
||
done();
|
||
});
|
||
});
|
||
|
||
test('intraline normalization', function() {
|
||
// The content and highlights are in the format returned by the Gerrit
|
||
// REST API.
|
||
var content = [
|
||
' <section class="summary">',
|
||
' <gr-linked-text content="' +
|
||
'[[_computeCurrentRevisionMessage(change)]]"></gr-linked-text>',
|
||
' </section>',
|
||
];
|
||
var highlights = [
|
||
[31, 34], [42, 26]
|
||
];
|
||
var results = element._normalizeIntralineHighlights(content, highlights);
|
||
assert.deepEqual(results, [
|
||
{
|
||
contentIndex: 0,
|
||
startIndex: 31,
|
||
},
|
||
{
|
||
contentIndex: 1,
|
||
startIndex: 0,
|
||
endIndex: 33,
|
||
},
|
||
{
|
||
contentIndex: 1,
|
||
startIndex: 75,
|
||
},
|
||
{
|
||
contentIndex: 2,
|
||
startIndex: 0,
|
||
endIndex: 6,
|
||
}
|
||
]);
|
||
|
||
content = [
|
||
' this._path = value.path;',
|
||
'',
|
||
' // When navigating away from the page, there is a possibility that the',
|
||
' // patch number is no longer a part of the URL (say when navigating to',
|
||
' // the top-level change info view) and therefore undefined in `params`.',
|
||
' if (!this._patchRange.patchNum) {',
|
||
];
|
||
highlights = [
|
||
[14, 17],
|
||
[11, 70],
|
||
[12, 67],
|
||
[12, 67],
|
||
[14, 29],
|
||
];
|
||
results = element._normalizeIntralineHighlights(content, highlights);
|
||
assert.deepEqual(results, [
|
||
{
|
||
contentIndex: 0,
|
||
startIndex: 14,
|
||
endIndex: 31,
|
||
},
|
||
{
|
||
contentIndex: 2,
|
||
startIndex: 8,
|
||
endIndex: 78,
|
||
},
|
||
{
|
||
contentIndex: 3,
|
||
startIndex: 11,
|
||
endIndex: 78,
|
||
},
|
||
{
|
||
contentIndex: 4,
|
||
startIndex: 11,
|
||
endIndex: 78,
|
||
},
|
||
{
|
||
contentIndex: 5,
|
||
startIndex: 12,
|
||
endIndex: 41,
|
||
}
|
||
]);
|
||
});
|
||
});
|
||
</script>
|