Fix draft comments not showing up on reply dialog

This was overlooked here:
https://gerrit-review.googlesource.com/c/gerrit/+/138190/19/polygerrit-ui/app/elements/change/gr-change-view/gr-change-view.js#b1070

As drafts were retrieved but not populated into _diffDrafts as expected
for the reply dialog. This change fixes the issue by setting diffDrafts
when all comments are loaded/reloaded.

Bug: Issue 7695
Change-Id: I9756e93d44dceb7c1fb8f66a6998fefd409ae9a0
This commit is contained in:
Becky Siegel
2017-11-08 10:36:47 -08:00
parent 4d641cc435
commit 26b9c4966a
3 changed files with 36 additions and 12 deletions

View File

@@ -259,7 +259,7 @@
});
this.addEventListener('comment-save', this._handleCommentSave.bind(this));
this.addEventListener('comment-refresh', this._getDiffDrafts.bind(this));
this.addEventListener('comment-refresh', this._reloadComments.bind(this));
this.addEventListener('comment-discard',
this._handleCommentDiscard.bind(this));
this.addEventListener('editable-content-save',
@@ -891,12 +891,6 @@
this.fire('page-error', {response});
},
_getDiffDrafts() {
return this.$.restAPI.getDiffDrafts(this._changeNum).then(drafts => {
this._diffDrafts = drafts;
});
},
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
},
@@ -1052,7 +1046,8 @@
_reloadComments() {
return this.$.commentAPI.loadAll(this._changeNum)
.then(comments => {
this._changeComments = this.$.commentAPI._changeComments;
this._changeComments = comments;
this._diffDrafts = Object.assign({}, this._changeComments.drafts);
});
},

View File

@@ -241,13 +241,41 @@ limitations under the License.
});
});
test('comments are reloaded when reload-comments fired', () => {
test('comments are reloaded when reload-comments fired', done => {
const reloadStub = sandbox.stub(element.$.commentAPI, 'loadAll')
.returns(Promise.resolve());
.returns(Promise.resolve({
drafts: {
'testfile.txt': [
{
patch_set: 5,
id: 'dd2982f5_c01c9e6a',
line: 1,
updated: '2017-11-08 18:47:45.000000000',
message: 'test',
unresolved: true,
},
],
},
}
));
element.$.fileList.fire('reload-comments', {
resolve: () => { return Promise.resolve(); },
resolve: () => {
assert.isTrue(reloadStub.called);
assert.deepEqual(element._diffDrafts, {
'testfile.txt': [
{
patch_set: 5,
id: 'dd2982f5_c01c9e6a',
line: 1,
updated: '2017-11-08 18:47:45.000000000',
message: 'test',
unresolved: true,
},
],
});
done();
},
});
assert.isTrue(reloadStub.called);
});
test('download tap calls _handleOpenDownloadDialog', () => {

View File

@@ -224,6 +224,7 @@
return Promise.all(promises).then(([comments, robotComments, drafts]) => {
this._changeComments = new ChangeComments(comments,
robotComments, drafts, changeNum);
return this._changeComments;
});
},
});