Show comment counts in diff file dropdown

Change-Id: Ia976d7357754075b0118a85842d662f03464e7cd
This commit is contained in:
Becky Siegel
2017-11-09 11:53:33 -08:00
parent 4ac7872bad
commit 5946f954f4
2 changed files with 54 additions and 2 deletions

View File

@@ -79,7 +79,8 @@
// element for selected a file to view. // element for selected a file to view.
_formattedFiles: { _formattedFiles: {
type: Array, type: Array,
computed: '_formatFilesForDropdown(_fileList)', computed: '_formatFilesForDropdown(_fileList, _patchRange.patchNum, ' +
'_changeComments)',
}, },
// An sorted array of files, as returned by the rest API. // An sorted array of files, as returned by the rest API.
_fileList: { _fileList: {
@@ -641,7 +642,7 @@
return this._getChangePath(change, patchRangeRecord.base, revisions); return this._getChangePath(change, patchRangeRecord.base, revisions);
}, },
_formatFilesForDropdown(fileList) { _formatFilesForDropdown(fileList, patchNum, changeComments) {
if (!fileList) { return; } if (!fileList) { return; }
const dropdownContent = []; const dropdownContent = [];
for (const path of fileList) { for (const path of fileList) {
@@ -649,11 +650,29 @@
text: this.computeDisplayPath(path), text: this.computeDisplayPath(path),
mobileText: this.computeTruncatedPath(path), mobileText: this.computeTruncatedPath(path),
value: path, value: path,
bottomText: this._computeCommentString(changeComments, patchNum,
path),
}); });
} }
return dropdownContent; return dropdownContent;
}, },
_computeCommentString(changeComments, patchNum, path) {
const unresolvedCount = changeComments.computeUnresolvedNum(patchNum,
path);
const commentCount = changeComments.computeCommentCount(patchNum, path);
const commentString = GrCountStringFormatter.computePluralString(
commentCount, 'comment');
const unresolvedString = GrCountStringFormatter.computeString(
unresolvedCount, 'unresolved');
return commentString +
// Add a space if both comments and unresolved
(commentString && unresolvedString ? ', ' : '') +
// Add parentheses around unresolved if it exists.
(unresolvedString ? `${unresolvedString}` : '');
},
_computePrefsButtonHidden(prefs, loggedIn) { _computePrefsButtonHidden(prefs, loggedIn) {
return !loggedIn || !prefs; return !loggedIn || !prefs;
}, },

View File

@@ -315,6 +315,34 @@ limitations under the License.
assert.isTrue(overlayOpenStub.called); assert.isTrue(overlayOpenStub.called);
}); });
test('_computeCommentString', done => {
loadCommentSpy = sandbox.spy(element.$.commentAPI, 'loadAll');
const path = '/test';
element.$.commentAPI.loadAll().then(comments => {
const commentCountStub =
sandbox.stub(comments, 'computeCommentCount');
const unresolvedCountStub =
sandbox.stub(comments, 'computeUnresolvedNum');
commentCountStub.withArgs(1, path).returns(0);
commentCountStub.withArgs(2, path).returns(1);
commentCountStub.withArgs(3, path).returns(2);
commentCountStub.withArgs(4, path).returns(0);
unresolvedCountStub.withArgs(1, path).returns(1);
unresolvedCountStub.withArgs(2, path).returns(0);
unresolvedCountStub.withArgs(3, path).returns(2);
unresolvedCountStub.withArgs(4, path).returns(0);
assert.equal(element._computeCommentString(comments, 1, path),
'1 unresolved');
assert.equal(element._computeCommentString(comments, 2, path),
'1 comment');
assert.equal(element._computeCommentString(comments, 3, path),
'2 comments, 2 unresolved');
assert.equal(element._computeCommentString(comments, 4, path), '');
done();
});
});
suite('url params', () => { suite('url params', () => {
setup(() => { setup(() => {
sandbox.stub(Gerrit.Nav, 'getUrlForDiff', (c, p, pn, bpn) => { sandbox.stub(Gerrit.Nav, 'getUrlForDiff', (c, p, pn, bpn) => {
@@ -340,24 +368,29 @@ limitations under the License.
text: 'chell.go', text: 'chell.go',
mobileText: 'chell.go', mobileText: 'chell.go',
value: 'chell.go', value: 'chell.go',
bottomText: '',
}, { }, {
text: 'glados.txt', text: 'glados.txt',
mobileText: 'glados.txt', mobileText: 'glados.txt',
value: 'glados.txt', value: 'glados.txt',
bottomText: '',
}, { }, {
text: 'wheatley.md', text: 'wheatley.md',
mobileText: 'wheatley.md', mobileText: 'wheatley.md',
value: 'wheatley.md', value: 'wheatley.md',
bottomText: '',
}, },
{ {
text: 'Commit message', text: 'Commit message',
mobileText: 'Commit message', mobileText: 'Commit message',
value: '/COMMIT_MSG', value: '/COMMIT_MSG',
bottomText: '',
}, },
{ {
text: 'Merge list', text: 'Merge list',
mobileText: 'Merge list', mobileText: 'Merge list',
value: '/MERGE_LIST', value: '/MERGE_LIST',
bottomText: '',
}, },
]; ];