Fix display of sync error icon on error

This commit is contained in:
Dan Stillman 2016-02-25 04:51:55 -05:00
parent aab4fca3ad
commit 6ac35c75c1
2 changed files with 42 additions and 24 deletions

View File

@ -160,7 +160,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
options.onError(e); options.onError(e);
} }
else { else {
this.addError.bind(this); this.addError(e);
} }
}.bind(this), }.bind(this),
background: _background, background: _background,
@ -488,12 +488,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
Zotero.debug("Sync failed for library " + libraryID); Zotero.debug("Sync failed for library " + libraryID);
Zotero.logError(e); Zotero.logError(e);
this.checkError(e); this.checkError(e);
if (options.onError) { options.onError(e);
options.onError(e);
}
else {
this.addError(e);
}
if (stopOnError || e.fatal) { if (stopOnError || e.fatal) {
Zotero.debug("Stopping on error", 1); Zotero.debug("Stopping on error", 1);
options.caller.stop(); options.caller.stop();
@ -548,12 +543,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
Zotero.debug("File sync failed for library " + libraryID); Zotero.debug("File sync failed for library " + libraryID);
Zotero.logError(e); Zotero.logError(e);
this.checkError(e); this.checkError(e);
if (options.onError) { options.onError(e);
options.onError(e);
}
else {
this.addError(e);
}
if (stopOnError || e.fatal) { if (stopOnError || e.fatal) {
options.caller.stop(); options.caller.stop();
break; break;
@ -583,12 +573,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
Zotero.debug("Full-text sync failed for library " + libraryID); Zotero.debug("Full-text sync failed for library " + libraryID);
Zotero.logError(e); Zotero.logError(e);
this.checkError(e); this.checkError(e);
if (options.onError) { options.onError(e);
options.onError(e);
}
else {
this.addError(e);
}
if (stopOnError || e.fatal) { if (stopOnError || e.fatal) {
options.caller.stop(); options.caller.stop();
break; break;

View File

@ -137,11 +137,9 @@ describe("Zotero.Sync.Runner", function () {
// //
// Tests // Tests
// //
let win;
before(function* () { before(function* () {
userLibraryID = Zotero.Libraries.userLibraryID; userLibraryID = Zotero.Libraries.userLibraryID;
publicationsLibraryID = Zotero.Libraries.publicationsLibraryID; publicationsLibraryID = Zotero.Libraries.publicationsLibraryID;
win = yield loadBrowserWindow();
}) })
beforeEach(function* () { beforeEach(function* () {
Zotero.HTTP.mock = sinon.FakeXMLHttpRequest; Zotero.HTTP.mock = sinon.FakeXMLHttpRequest;
@ -160,9 +158,6 @@ describe("Zotero.Sync.Runner", function () {
}) })
after(function () { after(function () {
Zotero.HTTP.mock = null; Zotero.HTTP.mock = null;
if (win) {
win.close();
}
}) })
describe("#checkAccess()", function () { describe("#checkAccess()", function () {
@ -409,6 +404,8 @@ describe("Zotero.Sync.Runner", function () {
}) })
describe("#sync()", function () { describe("#sync()", function () {
var spy;
before(function* () { before(function* () {
yield resetDB({ yield resetDB({
thisArg: this, thisArg: this,
@ -418,6 +415,12 @@ describe("Zotero.Sync.Runner", function () {
yield Zotero.Libraries.init(); yield Zotero.Libraries.init();
}) })
afterEach(function () {
if (spy) {
spy.restore();
}
});
it("should perform a sync across all libraries and update library versions", function* () { it("should perform a sync across all libraries and update library versions", function* () {
yield Zotero.Users.setCurrentUserID(1); yield Zotero.Users.setCurrentUserID(1);
yield Zotero.Users.setCurrentUsername("A"); yield Zotero.Users.setCurrentUsername("A");
@ -693,6 +696,36 @@ describe("Zotero.Sync.Runner", function () {
assert.isAbove(lastSyncTime, new Date().getTime() - 1000); assert.isAbove(lastSyncTime, new Date().getTime() - 1000);
assert.isBelow(lastSyncTime, new Date().getTime()); assert.isBelow(lastSyncTime, new Date().getTime());
}) })
it("should show the sync error icon on error", function* () {
yield Zotero.Users.setCurrentUserID(1);
yield Zotero.Users.setCurrentUsername("A");
setResponse('keyInfo.fullAccess');
setResponse('userGroups.groupVersionsEmpty');
// My Library
setResponse({
method: "GET",
url: "users/1/settings",
status: 200,
headers: {
"Last-Modified-Version": 5
},
json: {
INVALID: true // TODO: Find a cleaner error
}
});
spy = sinon.spy(runner, "updateIcons");
yield runner.sync();
assert.isTrue(spy.calledTwice);
assert.isArray(spy.args[1][0]);
assert.lengthOf(spy.args[1][0], 1);
// Not an instance of Error for some reason
var error = spy.args[1][0][0];
assert.equal(Object.getPrototypeOf(error).constructor.name, "Error");
});
}) })
describe("#createAPIKeyFromCredentials()", function() { describe("#createAPIKeyFromCredentials()", function() {