Modify fetchIsLatestKnown to return object rather than boolean

To support additional pieces of update information, besides the latest
known patch, the fetchIsLatest method returns an object of a single
boolean rather than a boolean itself. Use sites and tests are updated.
This is in preparation for issue 7698.

Change-Id: Ibeb32fcedb36fc09aeabea23d2784f7e11fd0b53
This commit is contained in:
Wyatt Allen
2017-11-16 11:52:50 -08:00
parent 943579dcb9
commit dc554961aa
9 changed files with 25 additions and 24 deletions

View File

@@ -212,7 +212,7 @@ limitations under the License.
* Check whether there is no newer patch than the latest patch that was
* available when this change was loaded.
*
* @return {Promise<boolean>} A promise that yields true if the latest patch
* @return {Promise<!Object>} A promise that yields true if the latest patch
* has been loaded, and false if a newer patch has been uploaded in the
* meantime. The promise is rejected on network error.
*/
@@ -226,7 +226,7 @@ limitations under the License.
}
const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum(
Gerrit.PatchSetBehavior.computeAllPatchSets(detail));
return actualLatest <= knownLatest;
return {isLatest: actualLatest <= knownLatest};
});
},

View File

@@ -48,8 +48,8 @@ limitations under the License.
},
};
Gerrit.PatchSetBehavior.fetchIsLatestKnown(knownChange, mockRestApi)
.then(isLatest => {
assert.isTrue(isLatest);
.then(result => {
assert.isTrue(result.isLatest);
done();
});
});
@@ -74,8 +74,8 @@ limitations under the License.
},
};
Gerrit.PatchSetBehavior.fetchIsLatestKnown(knownChange, mockRestApi)
.then(isLatest => {
assert.isFalse(isLatest);
.then(result => {
assert.isFalse(result.isLatest);
done();
});
});

View File

@@ -1063,8 +1063,8 @@
};
return this.fetchIsLatestKnown(this.change, this.$.restAPI)
.then(isLatest => {
if (!isLatest) {
.then(result => {
if (!result.isLatest) {
this.fire('show-alert', {
message: 'Cannot set label: a newer patch has been ' +
'uploaded to this change.',

View File

@@ -242,7 +242,7 @@ limitations under the License.
sandbox.stub(element.$.restAPI, 'getFromProjectLookup')
.returns(Promise.resolve('test'));
sandbox.stub(element, 'fetchIsLatestKnown',
() => { return Promise.resolve(true); });
() => { return Promise.resolve({isLatest: true}); });
element.change = {
revisions: {
rev1: {_number: 1},
@@ -1265,7 +1265,7 @@ limitations under the License.
setup(() => {
sandbox.stub(element, 'fetchIsLatestKnown')
.returns(Promise.resolve(true));
.returns(Promise.resolve({isLatest: true}));
sendStub = sandbox.stub(element.$.restAPI, 'getChangeURLAndSend')
.returns(Promise.resolve({}));
});
@@ -1294,7 +1294,7 @@ limitations under the License.
suite('failure modes', () => {
test('non-latest', () => {
sandbox.stub(element, 'fetchIsLatestKnown')
.returns(Promise.resolve(false));
.returns(Promise.resolve({isLatest: false}));
const sendStub = sandbox.stub(element.$.restAPI,
'getChangeURLAndSend');
@@ -1308,7 +1308,7 @@ limitations under the License.
test('send fails', () => {
sandbox.stub(element, 'fetchIsLatestKnown')
.returns(Promise.resolve(true));
.returns(Promise.resolve({isLatest: true}));
const sendStub = sandbox.stub(element.$.restAPI,
'getChangeURLAndSend',
(num, method, patchNum, endpoint, payload, onErr) => {

View File

@@ -1242,8 +1242,8 @@
this._updateCheckTimerHandle = this.async(() => {
this.fetchIsLatestKnown(this._change, this.$.restAPI)
.then(latest => {
if (latest) {
.then(result => {
if (result.isLatest) {
this._startUpdateCheckTimer();
} else {
this._cancelUpdateCheckTimer();

View File

@@ -121,7 +121,7 @@ limitations under the License.
test('A toggles overlay when logged in', done => {
sandbox.stub(element, '_getLoggedIn').returns(Promise.resolve(true));
sandbox.stub(element.$.replyDialog, 'fetchIsLatestKnown')
.returns(Promise.resolve(true));
.returns(Promise.resolve({isLatest: true}));
element._change = {labels: {}};
const openSpy = sandbox.spy(element, '_openReplyDialog');
@@ -968,7 +968,7 @@ limitations under the License.
setup(() => {
sandbox.stub(element.$.replyDialog, '_draftChanged');
sandbox.stub(element.$.replyDialog, 'fetchIsLatestKnown',
() => { return Promise.resolve(true); });
() => { return Promise.resolve({isLatest: true}); });
element._change = {labels: {}};
});
@@ -1019,7 +1019,7 @@ limitations under the License.
suite('commit message expand/collapse', () => {
setup(() => {
sandbox.stub(element, 'fetchIsLatestKnown',
() => { return Promise.resolve(false); });
() => { return Promise.resolve({isLatest: false}); });
});
test('commitCollapseToggle hidden for short commit message', () => {
@@ -1179,7 +1179,7 @@ limitations under the License.
test('_startUpdateCheckTimer up-to-date', () => {
sandbox.stub(element, 'fetchIsLatestKnown',
() => { return Promise.resolve(true); });
() => { return Promise.resolve({isLatest: true}); });
element._serverConfig = {change: {update_delay: 12345}};
@@ -1190,7 +1190,7 @@ limitations under the License.
test('_startUpdateCheckTimer out-of-date shows an alert', done => {
sandbox.stub(element, 'fetchIsLatestKnown',
() => { return Promise.resolve(false); });
() => { return Promise.resolve({isLatest: false}); });
element.addEventListener('show-alert', () => {
done();
});

View File

@@ -86,7 +86,8 @@ limitations under the License.
],
};
element.serverConfig = {note_db_enabled: true};
sandbox.stub(element, 'fetchIsLatestKnown', () => Promise.resolve(true));
sandbox.stub(element, 'fetchIsLatestKnown')
.returns(Promise.resolve({isLatest: true}));
};
setup(() => {

View File

@@ -238,8 +238,8 @@
open(opt_focusTarget) {
this.knownLatestState = LatestPatchState.CHECKING;
this.fetchIsLatestKnown(this.change, this.$.restAPI)
.then(isUpToDate => {
this.knownLatestState = isUpToDate ?
.then(result => {
this.knownLatestState = result.isLatest ?
LatestPatchState.LATEST : LatestPatchState.NOT_LATEST;
});

View File

@@ -103,8 +103,8 @@ limitations under the License.
eraseDraftCommentStub = sandbox.stub(element.$.storage,
'eraseDraftComment');
sandbox.stub(element, 'fetchIsLatestKnown',
() => { return Promise.resolve(true); });
sandbox.stub(element, 'fetchIsLatestKnown')
.returns(Promise.resolve({isLatest: true}));
// Allow the elements created by dom-repeat to be stamped.
flushAsynchronousOperations();