Collapse all comments but draft when showing threads in the reply dialog
Change-Id: I2d5d826fded70c8682ca989c14907609e8beb60a
This commit is contained in:
@@ -820,7 +820,7 @@ class GrChangeView extends mixinBehaviors( [
|
||||
// in the comment thread view.
|
||||
this._reloadDrafts().then(() => {
|
||||
this._commentThreads = this._changeComments.getAllThreadsForChange()
|
||||
.map(c => Object.assign({}, c));
|
||||
.map(thread => { return {...thread}; });
|
||||
flush();
|
||||
});
|
||||
}
|
||||
@@ -1725,11 +1725,19 @@ class GrChangeView extends mixinBehaviors( [
|
||||
|
||||
_recomputeComments(comments) {
|
||||
this._changeComments = comments;
|
||||
this._diffDrafts = Object.assign({}, this._changeComments.drafts);
|
||||
this._diffDrafts = {...this._changeComments.drafts};
|
||||
this._commentThreads = this._changeComments.getAllThreadsForChange()
|
||||
.map(c => Object.assign({}, c));
|
||||
.map(thread => { return {...thread}; });
|
||||
this._draftCommentThreads = this._commentThreads
|
||||
.filter(c => c.comments[c.comments.length - 1].__draft);
|
||||
.filter(thread => thread.comments[thread.comments.length - 1].__draft)
|
||||
.map(thread => {
|
||||
const copiedThread = {...thread};
|
||||
// Make a hardcopy of all comments and collapse all but last one
|
||||
const commentsInThread = copiedThread.comments = thread.comments
|
||||
.map(comment => { return {...comment, collapsed: true}; });
|
||||
commentsInThread[commentsInThread.length - 1].collapsed = false;
|
||||
return copiedThread;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -76,6 +76,7 @@ suite('gr-change-view tests', () => {
|
||||
|
||||
const ROBOT_COMMENTS_LIMIT = 10;
|
||||
|
||||
// TODO: should have a mock service to generate VALID fake data
|
||||
const THREADS = [
|
||||
{
|
||||
comments: [
|
||||
@@ -88,7 +89,7 @@ suite('gr-change-view tests', () => {
|
||||
},
|
||||
patch_set: 2,
|
||||
robot_id: 'rb1',
|
||||
id: 'ecf9fa_fe1a5f62',
|
||||
id: 'ecf0b9fa_fe1a5f62',
|
||||
line: 5,
|
||||
updated: '2018-02-08 18:49:18.000000000',
|
||||
message: 'test',
|
||||
@@ -102,7 +103,7 @@ suite('gr-change-view tests', () => {
|
||||
username: 'user',
|
||||
},
|
||||
patch_set: 4,
|
||||
id: 'ecf0b9fa_fe1a5f62',
|
||||
id: 'ecf0b9fa_fe1a5f62_1',
|
||||
line: 5,
|
||||
updated: '2018-02-08 18:49:18.000000000',
|
||||
message: 'test',
|
||||
@@ -714,6 +715,56 @@ suite('gr-change-view tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
suite('_recomputeComments', () => {
|
||||
setup(() => {
|
||||
// Fake computeDraftCount as its required for ChangeComments,
|
||||
// see gr-comment-api#reloadDrafts.
|
||||
sandbox.stub(element.$.commentAPI, 'reloadDrafts')
|
||||
.returns(Promise.resolve({
|
||||
drafts: {},
|
||||
getAllThreadsForChange: () => THREADS,
|
||||
computeDraftCount: () => 0,
|
||||
}));
|
||||
});
|
||||
|
||||
test('draft threads should be a new copy with correct states', done => {
|
||||
element.$.fileList.dispatchEvent(
|
||||
new CustomEvent('reload-drafts', {
|
||||
detail: {
|
||||
resolve: () => {
|
||||
assert.equal(element._draftCommentThreads.length, 2);
|
||||
assert.equal(
|
||||
element._draftCommentThreads[0].rootId,
|
||||
THREADS[0].rootId
|
||||
);
|
||||
assert.notEqual(
|
||||
element._draftCommentThreads[0].comments,
|
||||
THREADS[0].comments
|
||||
);
|
||||
assert.notEqual(
|
||||
element._draftCommentThreads[0].comments[0],
|
||||
THREADS[0].comments[0]
|
||||
);
|
||||
assert.isTrue(
|
||||
element._draftCommentThreads[0]
|
||||
.comments
|
||||
.slice(0, 2)
|
||||
.every(c => c.collapsed === true)
|
||||
);
|
||||
|
||||
assert.isTrue(
|
||||
element._draftCommentThreads[0]
|
||||
.comments[2]
|
||||
.collapsed === false
|
||||
);
|
||||
done();
|
||||
},
|
||||
},
|
||||
composed: true, bubbles: true,
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
test('diff comments modified', () => {
|
||||
sandbox.spy(element, '_handleReloadCommentThreads');
|
||||
return element._reloadComments().then(() => {
|
||||
|
||||
Reference in New Issue
Block a user