Merge "Report timing for updating diff comment drafts"
This commit is contained in:
commit
4bb38ccaa6
@ -19,6 +19,7 @@ limitations under the License.
|
||||
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
|
||||
<link rel="import" href="../../../bower_components/iron-autogrow-textarea/iron-autogrow-textarea.html">
|
||||
<link rel="import" href="../../../styles/shared-styles.html">
|
||||
<link rel="import" href="../../core/gr-reporting/gr-reporting.html">
|
||||
<link rel="import" href="../../plugins/gr-endpoint-decorator/gr-endpoint-decorator.html">
|
||||
<link rel="import" href="../../plugins/gr-endpoint-param/gr-endpoint-param.html">
|
||||
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
||||
@ -32,7 +33,6 @@ limitations under the License.
|
||||
<link rel="import" href="../../shared/gr-textarea/gr-textarea.html">
|
||||
<link rel="import" href="../../shared/gr-tooltip-content/gr-tooltip-content.html">
|
||||
<link rel="import" href="../gr-confirm-delete-comment-dialog/gr-confirm-delete-comment-dialog.html">
|
||||
|
||||
<script src="../../../scripts/rootElement.js"></script>
|
||||
|
||||
<dom-module id="gr-diff-comment">
|
||||
@ -387,6 +387,7 @@ limitations under the License.
|
||||
</template>
|
||||
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
|
||||
<gr-storage id="storage"></gr-storage>
|
||||
<gr-reporting id="reporting"></gr-reporting>
|
||||
</template>
|
||||
<script src="gr-diff-comment.js"></script>
|
||||
</dom-module>
|
||||
|
@ -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() {
|
||||
|
@ -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...');
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user