Merge "Add optional file link to gr-comment-thread"

This commit is contained in:
Becky Siegel
2018-02-28 18:09:41 +00:00
committed by Gerrit Code Review
3 changed files with 73 additions and 7 deletions

View File

@@ -15,20 +15,16 @@ limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/gr-path-list-behavior/gr-path-list-behavior.html">
<link rel="import" href="../../../styles/shared-styles.html">
<link rel="import" href="../../core/gr-navigation/gr-navigation.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<link rel="import" href="../../shared/gr-storage/gr-storage.html">
<link rel="import" href="../gr-diff-comment/gr-diff-comment.html">
<link rel="import" href="../../../styles/shared-styles.html">
<dom-module id="gr-diff-comment-thread">
<template>
<style include="shared-styles">
:host {
border: 1px solid #bbb;
display: block;
margin-bottom: 1px;
white-space: normal;
}
gr-button {
margin-left: .5em;
--gr-button-color: #212121;
@@ -39,6 +35,10 @@ limitations under the License.
}
#container {
background-color: #fcfad6;
border: 1px solid #bbb;
display: block;
margin-bottom: 1px;
white-space: normal;
}
#container.unresolved {
background-color: #fcfaa6;
@@ -52,7 +52,22 @@ limitations under the License.
margin: auto 0;
padding: .5em .7em;
}
.pathInfo {
display: flex;
align-items: baseline;
}
.descriptionText {
margin-left: .5rem;
font-size: var(--font-size-small);
font-style: italic;
}
</style>
<template is="dom-if" if="[[showFilePath]]">
<div class="pathInfo">
<a href$="[[_getDiffUrlForComment(projectName, changeNum, path, patchNum)]]">[[_computeDisplayPath(path)]]</a>
<span class="descriptionText">Patchset [[patchNum]]</span>
</div>
</template>
<div id="container" class$="[[_computeHostClass(unresolved)]]">
<template id="commentList" is="dom-repeat" items="[[_orderedComments]]"
as="comment">

View File

@@ -58,6 +58,16 @@
value: null,
},
rootId: String,
/**
* If this is true, the comment thread also needs to have the change and
* line properties property set
*/
showFilePath: {
type: Boolean,
value: false,
},
/** Necessary only if showFilePath is true */
lineNum: Number,
unresolved: {
type: Boolean,
notify: true,
@@ -71,6 +81,7 @@
behaviors: [
Gerrit.KeyboardShortcutBehavior,
Gerrit.PathListBehavior,
],
listeners: {
@@ -117,6 +128,17 @@
this.push('comments', draft);
},
_getDiffUrlForComment(projectName, changeNum, path, patchNum) {
return Gerrit.Nav.getUrlForDiffById(changeNum,
projectName, path, patchNum,
null, this.lineNum);
},
_computeDisplayPath(path) {
const lineString = this.lineNum ? `#${this.lineNum}` : '';
return this.computeDisplayPath(path) + lineString;
},
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
},

View File

@@ -170,6 +170,35 @@ limitations under the License.
done();
});
});
test('optionally show file path', () => {
// Path info doesn't exist when showFilePath is false. Because it's in a
// dom-if it is not yet in the dom.
assert.isNotOk(element.$$('.pathInfo'));
sandbox.stub(Gerrit.Nav, 'getUrlForDiffById');
element.changeNum = 123;
element.projectName = 'test project';
element.path = 'path/to/file';
element.patchNum = 3;
element.lineNum = 5;
element.showFilePath = true;
flushAsynchronousOperations();
assert.isOk(element.$$('.pathInfo'));
assert.notEqual(getComputedStyle(element.$$('.pathInfo')).display,
'none');
assert.isTrue(Gerrit.Nav.getUrlForDiffById.lastCall.calledWithExactly(
element.changeNum, element.projectName, element.path,
element.patchNum, null, element.lineNum));
});
test('_computeDisplayPath', () => {
const path = 'path/to/file';
assert.equal(element._computeDisplayPath(path), 'path/to/file');
element.lineNum = 5;
assert.equal(element._computeDisplayPath(path), 'path/to/file#5');
});
});
suite('comment action tests', () => {