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:
@@ -212,7 +212,7 @@ limitations under the License.
|
|||||||
* Check whether there is no newer patch than the latest patch that was
|
* Check whether there is no newer patch than the latest patch that was
|
||||||
* available when this change was loaded.
|
* 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
|
* has been loaded, and false if a newer patch has been uploaded in the
|
||||||
* meantime. The promise is rejected on network error.
|
* meantime. The promise is rejected on network error.
|
||||||
*/
|
*/
|
||||||
@@ -226,7 +226,7 @@ limitations under the License.
|
|||||||
}
|
}
|
||||||
const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum(
|
const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum(
|
||||||
Gerrit.PatchSetBehavior.computeAllPatchSets(detail));
|
Gerrit.PatchSetBehavior.computeAllPatchSets(detail));
|
||||||
return actualLatest <= knownLatest;
|
return {isLatest: actualLatest <= knownLatest};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@@ -48,8 +48,8 @@ limitations under the License.
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
Gerrit.PatchSetBehavior.fetchIsLatestKnown(knownChange, mockRestApi)
|
Gerrit.PatchSetBehavior.fetchIsLatestKnown(knownChange, mockRestApi)
|
||||||
.then(isLatest => {
|
.then(result => {
|
||||||
assert.isTrue(isLatest);
|
assert.isTrue(result.isLatest);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -74,8 +74,8 @@ limitations under the License.
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
Gerrit.PatchSetBehavior.fetchIsLatestKnown(knownChange, mockRestApi)
|
Gerrit.PatchSetBehavior.fetchIsLatestKnown(knownChange, mockRestApi)
|
||||||
.then(isLatest => {
|
.then(result => {
|
||||||
assert.isFalse(isLatest);
|
assert.isFalse(result.isLatest);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1063,8 +1063,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
return this.fetchIsLatestKnown(this.change, this.$.restAPI)
|
return this.fetchIsLatestKnown(this.change, this.$.restAPI)
|
||||||
.then(isLatest => {
|
.then(result => {
|
||||||
if (!isLatest) {
|
if (!result.isLatest) {
|
||||||
this.fire('show-alert', {
|
this.fire('show-alert', {
|
||||||
message: 'Cannot set label: a newer patch has been ' +
|
message: 'Cannot set label: a newer patch has been ' +
|
||||||
'uploaded to this change.',
|
'uploaded to this change.',
|
||||||
|
@@ -242,7 +242,7 @@ limitations under the License.
|
|||||||
sandbox.stub(element.$.restAPI, 'getFromProjectLookup')
|
sandbox.stub(element.$.restAPI, 'getFromProjectLookup')
|
||||||
.returns(Promise.resolve('test'));
|
.returns(Promise.resolve('test'));
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown',
|
sandbox.stub(element, 'fetchIsLatestKnown',
|
||||||
() => { return Promise.resolve(true); });
|
() => { return Promise.resolve({isLatest: true}); });
|
||||||
element.change = {
|
element.change = {
|
||||||
revisions: {
|
revisions: {
|
||||||
rev1: {_number: 1},
|
rev1: {_number: 1},
|
||||||
@@ -1265,7 +1265,7 @@ limitations under the License.
|
|||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown')
|
sandbox.stub(element, 'fetchIsLatestKnown')
|
||||||
.returns(Promise.resolve(true));
|
.returns(Promise.resolve({isLatest: true}));
|
||||||
sendStub = sandbox.stub(element.$.restAPI, 'getChangeURLAndSend')
|
sendStub = sandbox.stub(element.$.restAPI, 'getChangeURLAndSend')
|
||||||
.returns(Promise.resolve({}));
|
.returns(Promise.resolve({}));
|
||||||
});
|
});
|
||||||
@@ -1294,7 +1294,7 @@ limitations under the License.
|
|||||||
suite('failure modes', () => {
|
suite('failure modes', () => {
|
||||||
test('non-latest', () => {
|
test('non-latest', () => {
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown')
|
sandbox.stub(element, 'fetchIsLatestKnown')
|
||||||
.returns(Promise.resolve(false));
|
.returns(Promise.resolve({isLatest: false}));
|
||||||
const sendStub = sandbox.stub(element.$.restAPI,
|
const sendStub = sandbox.stub(element.$.restAPI,
|
||||||
'getChangeURLAndSend');
|
'getChangeURLAndSend');
|
||||||
|
|
||||||
@@ -1308,7 +1308,7 @@ limitations under the License.
|
|||||||
|
|
||||||
test('send fails', () => {
|
test('send fails', () => {
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown')
|
sandbox.stub(element, 'fetchIsLatestKnown')
|
||||||
.returns(Promise.resolve(true));
|
.returns(Promise.resolve({isLatest: true}));
|
||||||
const sendStub = sandbox.stub(element.$.restAPI,
|
const sendStub = sandbox.stub(element.$.restAPI,
|
||||||
'getChangeURLAndSend',
|
'getChangeURLAndSend',
|
||||||
(num, method, patchNum, endpoint, payload, onErr) => {
|
(num, method, patchNum, endpoint, payload, onErr) => {
|
||||||
|
@@ -1242,8 +1242,8 @@
|
|||||||
|
|
||||||
this._updateCheckTimerHandle = this.async(() => {
|
this._updateCheckTimerHandle = this.async(() => {
|
||||||
this.fetchIsLatestKnown(this._change, this.$.restAPI)
|
this.fetchIsLatestKnown(this._change, this.$.restAPI)
|
||||||
.then(latest => {
|
.then(result => {
|
||||||
if (latest) {
|
if (result.isLatest) {
|
||||||
this._startUpdateCheckTimer();
|
this._startUpdateCheckTimer();
|
||||||
} else {
|
} else {
|
||||||
this._cancelUpdateCheckTimer();
|
this._cancelUpdateCheckTimer();
|
||||||
|
@@ -121,7 +121,7 @@ limitations under the License.
|
|||||||
test('A toggles overlay when logged in', done => {
|
test('A toggles overlay when logged in', done => {
|
||||||
sandbox.stub(element, '_getLoggedIn').returns(Promise.resolve(true));
|
sandbox.stub(element, '_getLoggedIn').returns(Promise.resolve(true));
|
||||||
sandbox.stub(element.$.replyDialog, 'fetchIsLatestKnown')
|
sandbox.stub(element.$.replyDialog, 'fetchIsLatestKnown')
|
||||||
.returns(Promise.resolve(true));
|
.returns(Promise.resolve({isLatest: true}));
|
||||||
element._change = {labels: {}};
|
element._change = {labels: {}};
|
||||||
const openSpy = sandbox.spy(element, '_openReplyDialog');
|
const openSpy = sandbox.spy(element, '_openReplyDialog');
|
||||||
|
|
||||||
@@ -968,7 +968,7 @@ limitations under the License.
|
|||||||
setup(() => {
|
setup(() => {
|
||||||
sandbox.stub(element.$.replyDialog, '_draftChanged');
|
sandbox.stub(element.$.replyDialog, '_draftChanged');
|
||||||
sandbox.stub(element.$.replyDialog, 'fetchIsLatestKnown',
|
sandbox.stub(element.$.replyDialog, 'fetchIsLatestKnown',
|
||||||
() => { return Promise.resolve(true); });
|
() => { return Promise.resolve({isLatest: true}); });
|
||||||
element._change = {labels: {}};
|
element._change = {labels: {}};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1019,7 +1019,7 @@ limitations under the License.
|
|||||||
suite('commit message expand/collapse', () => {
|
suite('commit message expand/collapse', () => {
|
||||||
setup(() => {
|
setup(() => {
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown',
|
sandbox.stub(element, 'fetchIsLatestKnown',
|
||||||
() => { return Promise.resolve(false); });
|
() => { return Promise.resolve({isLatest: false}); });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('commitCollapseToggle hidden for short commit message', () => {
|
test('commitCollapseToggle hidden for short commit message', () => {
|
||||||
@@ -1179,7 +1179,7 @@ limitations under the License.
|
|||||||
|
|
||||||
test('_startUpdateCheckTimer up-to-date', () => {
|
test('_startUpdateCheckTimer up-to-date', () => {
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown',
|
sandbox.stub(element, 'fetchIsLatestKnown',
|
||||||
() => { return Promise.resolve(true); });
|
() => { return Promise.resolve({isLatest: true}); });
|
||||||
|
|
||||||
element._serverConfig = {change: {update_delay: 12345}};
|
element._serverConfig = {change: {update_delay: 12345}};
|
||||||
|
|
||||||
@@ -1190,7 +1190,7 @@ limitations under the License.
|
|||||||
|
|
||||||
test('_startUpdateCheckTimer out-of-date shows an alert', done => {
|
test('_startUpdateCheckTimer out-of-date shows an alert', done => {
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown',
|
sandbox.stub(element, 'fetchIsLatestKnown',
|
||||||
() => { return Promise.resolve(false); });
|
() => { return Promise.resolve({isLatest: false}); });
|
||||||
element.addEventListener('show-alert', () => {
|
element.addEventListener('show-alert', () => {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
@@ -86,7 +86,8 @@ limitations under the License.
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
element.serverConfig = {note_db_enabled: true};
|
element.serverConfig = {note_db_enabled: true};
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown', () => Promise.resolve(true));
|
sandbox.stub(element, 'fetchIsLatestKnown')
|
||||||
|
.returns(Promise.resolve({isLatest: true}));
|
||||||
};
|
};
|
||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
|
@@ -238,8 +238,8 @@
|
|||||||
open(opt_focusTarget) {
|
open(opt_focusTarget) {
|
||||||
this.knownLatestState = LatestPatchState.CHECKING;
|
this.knownLatestState = LatestPatchState.CHECKING;
|
||||||
this.fetchIsLatestKnown(this.change, this.$.restAPI)
|
this.fetchIsLatestKnown(this.change, this.$.restAPI)
|
||||||
.then(isUpToDate => {
|
.then(result => {
|
||||||
this.knownLatestState = isUpToDate ?
|
this.knownLatestState = result.isLatest ?
|
||||||
LatestPatchState.LATEST : LatestPatchState.NOT_LATEST;
|
LatestPatchState.LATEST : LatestPatchState.NOT_LATEST;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -103,8 +103,8 @@ limitations under the License.
|
|||||||
eraseDraftCommentStub = sandbox.stub(element.$.storage,
|
eraseDraftCommentStub = sandbox.stub(element.$.storage,
|
||||||
'eraseDraftComment');
|
'eraseDraftComment');
|
||||||
|
|
||||||
sandbox.stub(element, 'fetchIsLatestKnown',
|
sandbox.stub(element, 'fetchIsLatestKnown')
|
||||||
() => { return Promise.resolve(true); });
|
.returns(Promise.resolve({isLatest: true}));
|
||||||
|
|
||||||
// Allow the elements created by dom-repeat to be stamped.
|
// Allow the elements created by dom-repeat to be stamped.
|
||||||
flushAsynchronousOperations();
|
flushAsynchronousOperations();
|
||||||
|
Reference in New Issue
Block a user