diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js index fc8708460d..3445f4ec2d 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions.js @@ -274,6 +274,7 @@ if (type === ActionType.REVISION) { this._handleRevisionAction(key); } else if (key === ChangeActions.REVERT) { + this.$.confirmRevertDialog.populateRevertMessage(); this.$.confirmRevertDialog.message = this._modifyRevertMsg(); this._showActionDialog(this.$.confirmRevertDialog); } else if (key === ChangeActions.ABANDON) { diff --git a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html index 906f596603..80aaf3b444 100644 --- a/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html +++ b/polygerrit-ui/app/elements/change/gr-change-actions/gr-change-actions_test.html @@ -244,18 +244,25 @@ limitations under the License. var newRevertMsg = 'Modified revert msg'; var modifyRevertMsgStub = sinon.stub(element, '_modifyRevertMsg', function() { return newRevertMsg; }); + var populateRevertMsgStub = sinon.stub( + element.$.confirmRevertDialog, 'populateRevertMessage', + function() { return 'original msg'; }); flush(function() { var revertButton = element.$$('gr-button[data-action-key="revert"]'); MockInteractions.tap(revertButton); assert.equal(element.$.confirmRevertDialog.message, newRevertMsg); + populateRevertMsgStub.restore(); modifyRevertMsgStub.restore(); done(); }); }); test('works', function() { + var populateRevertMsgStub = sinon.stub( + element.$.confirmRevertDialog, 'populateRevertMessage', + function() { return 'original msg'; }); var revertButton = element.$$('gr-button[data-action-key="revert"]'); MockInteractions.tap(revertButton); @@ -276,6 +283,7 @@ limitations under the License. '/revert', action, false, { message: 'foo message', }]); + populateRevertMsgStub.restore(); }); }); }); diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js index d742150f36..b4baa265cf 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js +++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog.js @@ -32,15 +32,12 @@ properties: { branch: String, message: String, - commitInfo: { - type: Object, - observer: '_commitInfoChanged', - }, + commitInfo: Object, }, - _commitInfoChanged: function(commitInfo) { + populateRevertMessage: function() { // Figure out what the revert title should be. - var originalTitle = commitInfo.message.split('\n')[0]; + var originalTitle = this.commitInfo.message.split('\n')[0]; var revertTitle = 'Revert of ' + originalTitle; if (originalTitle.startsWith('Revert of ')) { revertTitle = 'Reland of ' + @@ -50,7 +47,7 @@ originalTitle.substring('Reland of '.length); } // Add '> ' in front of the original commit text. - var originalCommitText = commitInfo.message.replace(/^/gm, '> '); + var originalCommitText = this.commitInfo.message.replace(/^/gm, '> '); this.message = revertTitle + '\n\n' + 'Reason for revert: \n\n' + diff --git a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html index 5e51e8208f..1d53eefdb1 100644 --- a/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html +++ b/polygerrit-ui/app/elements/change/gr-confirm-revert-dialog/gr-confirm-revert-dialog_test.html @@ -39,9 +39,10 @@ limitations under the License. }); test('single line', function() { - assert(element.message == null); - element.commitInfo = { message: 'one line commit' }; - console.log(element.message); + assert.isNotOk(element.message); + element.commitInfo = {message: 'one line commit'}; + assert.isNotOk(element.message); + element.populateRevertMessage(); var expected = 'Revert of one line commit\n\n' + 'Reason for revert: \n\n' + 'Original issue\'s description:\n' + @@ -50,9 +51,10 @@ limitations under the License. }); test('multi line', function() { - assert(element.message == null); - element.commitInfo = { message: 'many lines\ncommit\n\nmessage\n' }; - console.log(element.message); + assert.isNotOk(element.message); + element.commitInfo = {message: 'many lines\ncommit\n\nmessage\n'}; + assert.isNotOk(element.message); + element.populateRevertMessage(); var expected = 'Revert of many lines\n\n' + 'Reason for revert: \n\n' + 'Original issue\'s description:\n' +