diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html index 79b23ca815..88ec7209f0 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.html @@ -19,6 +19,7 @@ limitations under the License. + @@ -32,7 +33,6 @@ limitations under the License. - @@ -387,6 +387,7 @@ limitations under the License. + diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js index 861201194d..b2b6b735a7 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment.js @@ -27,6 +27,10 @@ const SAVING_PROGRESS_MESSAGE = 'Saving draft...'; const DiSCARDING_PROGRESS_MESSAGE = 'Discarding draft...'; + const REPORT_CREATE_DRAFT = 'CreateDraftComment'; + const REPORT_UPDATE_DRAFT = 'UpdateDraftComment'; + const REPORT_DISCARD_DRAFT = 'DiscardDraftComment'; + Polymer({ is: 'gr-diff-comment', @@ -450,9 +454,12 @@ // Ignore saves started while already saving. if (this.disabled) { return; } - + const timingLabel = this.comment.id ? + REPORT_UPDATE_DRAFT : REPORT_CREATE_DRAFT; + this.$.reporting.time(timingLabel); this.set('comment.__editing', false); - this.save(); + return this.save() + .then(() => { this.$.reporting.timeEnd(timingLabel); }); }, _handleCancel(e) { @@ -485,8 +492,10 @@ _handleConfirmDiscard(e) { e.preventDefault(); + this.$.reporting.time(REPORT_DISCARD_DRAFT); this._closeConfirmDiscardOverlay(); - this._discardDraft(); + return this._discardDraft() + .then(() => { this.$.reporting.timeEnd(REPORT_DISCARD_DRAFT); }); }, _discardDraft() { diff --git a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html index 5b4343063c..c7ca782b35 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-comment/gr-diff-comment_test.html @@ -279,6 +279,45 @@ limitations under the License. }); }); }); + + suite('draft update reporting', () => { + let timeEndStub; + let mockEvent; + + setup(() => { + mockEvent = {preventDefault() {}}; + sandbox.stub(element, 'save') + .returns(Promise.resolve({})); + sandbox.stub(element, '_discardDraft') + .returns(Promise.resolve({})); + timeEndStub = sandbox.stub(element.$.reporting, 'timeEnd'); + }); + + test('create', () => { + element.comment = {}; + return element._handleSave(mockEvent).then(() => { + assert.isTrue(timeEndStub.calledOnce); + assert.equal(timeEndStub.lastCall.args[0], 'CreateDraftComment'); + }); + }); + + test('update', () => { + element.comment = {id: 'abc_123'}; + return element._handleSave(mockEvent).then(() => { + assert.isTrue(timeEndStub.calledOnce); + assert.equal(timeEndStub.lastCall.args[0], 'UpdateDraftComment'); + }); + }); + + test('discard', () => { + element.comment = {id: 'abc_123'}; + sandbox.stub(element, '_closeConfirmDiscardOverlay'); + return element._handleConfirmDiscard(mockEvent).then(() => { + assert.isTrue(timeEndStub.calledOnce); + assert.equal(timeEndStub.lastCall.args[0], 'DiscardDraftComment'); + }); + }); + }); }); suite('gr-diff-comment draft tests', () => { @@ -578,6 +617,7 @@ limitations under the License. assert.isTrue(stub.called); stub.restore(); done(); + return Promise.resolve(); }); element._messageText = 'is that the horse from horsing around??'; element.editing = true; @@ -654,7 +694,7 @@ limitations under the License. }); test('draft prevent save when disabled', () => { - const saveStub = sandbox.stub(element, 'save'); + const saveStub = sandbox.stub(element, 'save').returns(Promise.resolve()); element.showActions = true; element.draft = true; MockInteractions.tap(element.$.header); @@ -751,7 +791,7 @@ limitations under the License. }); test('saving', () => { - element._saveDraft(); + element._saveDraft({}); assert.equal(element._savingMessage, 'Saving draft...'); });