Clear sync error and start sync after logging in in prefs ()

Also fixes an existing error due to an argumentless call to
Zotero.Sync.Runner.updateIcons() in ZoteroPane.
This commit is contained in:
Abe Jellinek 2022-10-16 15:47:54 -04:00 committed by GitHub
parent f9a0622c30
commit c1bb910d1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions
chrome/content/zotero
test/tests

View file

@ -182,6 +182,17 @@ Zotero_Preferences.Sync = {
Zotero.Sync.Runner.deleteAPIKey();
return;
}
// It shouldn't be possible for a sync to be in progress if the user wasn't logged in,
// but check to be sure
if (!Zotero.Sync.Runner.syncInProgress) {
// Clear any displayed sync errors
Zotero.Sync.Runner.updateIcons([]);
}
window.addEventListener('beforeunload', () => {
Zotero.Sync.Runner.setSyncTimeout(1);
});
this.displayFields(json.username);
}),

View file

@ -203,7 +203,7 @@ var ZoteroPane = new function()
if (index == 0) {
Zotero.Sync.Server.sync({
onSuccess: function () {
Zotero.Sync.Runner.updateIcons();
Zotero.Sync.Runner.updateIcons([]);
ps.alert(
null,

View file

@ -99,6 +99,21 @@ describe("Sync Preferences", function () {
assert.equal(doc.getElementById('sync-unauthorized').getAttribute('hidden'), 'true');
});
it("should clear sync errors from the toolbar after logging in", async function () {
let win = await loadZoteroPane();
after(function () {
win.close();
});
let syncError = win.document.getElementById('zotero-tb-sync-error');
Zotero.Sync.Runner.updateIcons(new Error("a sync error"));
assert.isFalse(syncError.hidden);
getAPIKeyFromCredentialsStub.resolves(apiResponse);
await setCredentials("Username", "correctPassword");
assert.isTrue(syncError.hidden);
});
})
})
})