Merge "Check for response.ok before redirect for applyfix"

This commit is contained in:
Tao Zhou
2020-03-03 08:44:05 +00:00
committed by Gerrit Code Review
2 changed files with 29 additions and 7 deletions

View File

@@ -181,11 +181,17 @@
return;
}
this._isApplyFixLoading = true;
return this.$.restAPI.applyFixSuggestion(this.changeNum, this._patchNum,
this._currentFix.fix_id).then(res => {
Gerrit.Nav.navigateToChange(this.change, 'edit', this._patchNum);
this._close();
});
return this.$.restAPI
.applyFixSuggestion(
this.changeNum, this._patchNum, this._currentFix.fix_id
)
.then(res => {
if (res && res.ok) {
Gerrit.Nav.navigateToChange(this.change, 'edit', this._patchNum);
this._close();
}
this._isApplyFixLoading = false;
});
},
getFixDescription(currentFix) {

View File

@@ -153,10 +153,10 @@ limitations under the License.
});
});
test('apply fix button should call apply' +
test('apply fix button should call apply ' +
'and navigate to change view', done => {
sandbox.stub(element.$.restAPI, 'applyFixSuggestion')
.returns(Promise.resolve());
.returns(Promise.resolve({ok: true}));
sandbox.stub(Gerrit.Nav, 'navigateToChange');
element._currentFix = {fix_id: '123'};
@@ -175,6 +175,22 @@ limitations under the License.
});
});
test('should not navigate to change view if incorect reponse', done => {
sandbox.stub(element.$.restAPI, 'applyFixSuggestion')
.returns(Promise.resolve({}));
sandbox.stub(Gerrit.Nav, 'navigateToChange');
element._currentFix = {fix_id: '123'};
element._handleApplyFix().then(() => {
assert.isTrue(element.$.restAPI.applyFixSuggestion
.calledWithExactly('1', 2, '123'));
assert.isTrue(Gerrit.Nav.navigateToChange.notCalled);
assert.equal(element._isApplyFixLoading, false);
done();
});
});
test('select fix forward and back of multiple suggested fixes', done => {
sandbox.stub(element.$.restAPI, 'getRobotCommentFixPreview')
.returns(Promise.resolve({