Close #931, [Async DB] Update long tag fixer

This commit is contained in:
Dan Stillman 2016-04-21 11:08:48 -04:00
parent e2cbfbd0fe
commit e7d27ee0f3
7 changed files with 349 additions and 162 deletions

View file

@ -670,58 +670,9 @@ describe("Zotero.Sync.Runner", function () {
assert.isAbove(lastSyncTime, new Date().getTime() - 1000);
assert.isBelow(lastSyncTime, new Date().getTime());
})
it("should show the sync error icon on error", function* () {
let pubLib = Zotero.Libraries.get(publicationsLibraryID);
pubLib.libraryVersion = 5;
yield pubLib.save();
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
}
});
// No publications changes
setResponse({
method: "GET",
url: "users/1/publications/settings?since=5",
status: 304,
headers: {
"Last-Modified-Version": 5
},
json: {}
});
setResponse({
method: "GET",
url: "users/1/publications/fulltext",
status: 200,
headers: {
"Last-Modified-Version": 5
},
json: {}
});
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() {
var data = {
name: "Automatic Zotero Client Key",
@ -785,5 +736,211 @@ describe("Zotero.Sync.Runner", function () {
yield runner.deleteAPIKey();
});
})
});
describe("Error Handling", function () {
var win;
afterEach(function () {
if (win) {
win.close();
}
});
it("should show the sync error icon on error", function* () {
let pubLib = Zotero.Libraries.get(publicationsLibraryID);
pubLib.libraryVersion = 5;
yield pubLib.save();
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
}
});
// No publications changes
setResponse({
method: "GET",
url: "users/1/publications/settings?since=5",
status: 304,
headers: {
"Last-Modified-Version": 5
},
json: {}
});
setResponse({
method: "GET",
url: "users/1/publications/fulltext",
status: 200,
headers: {
"Last-Modified-Version": 5
},
json: {}
});
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");
});
// TODO: Test multiple long tags and tags across libraries
describe("Long Tag Fixer", function () {
it("should split a tag", function* () {
win = yield loadZoteroPane();
var item = yield createDataObject('item');
var tag = "title;feeling;matter;drum;treatment;caring;earthy;shrill;unit;obedient;hover;healthy;cheap;clever;wren;wicked;clip;shoe;jittery;shape;clear;dime;increase;complete;level;milk;false;infamous;lamentable;measure;cuddly;tasteless;peace;top;pencil;caption;unusual;depressed;frantic";
item.addTag(tag, 1);
yield item.saveTx();
setResponse('keyInfo.fullAccess');
setResponse('userGroups.groupVersions');
setResponse('groups.ownerGroup');
setResponse('groups.memberGroup');
server.respond(function (req) {
if (req.method == "POST" && req.url == baseURL + "users/1/items") {
var json = JSON.parse(req.requestBody);
if (json[0].tags.length == 1) {
req.respond(
200,
{
"Last-Modified-Version": 5
},
JSON.stringify({
successful: {},
success: {},
unchanged: {},
failed: {
"0": {
code: 413,
message: "Tag 'title;feeling;matter;drum;treatment;caring;earthy;shrill;unit;obedient;hover…' is too long to sync",
data: {
tag
}
}
}
})
);
}
else {
let itemJSON = item.toResponseJSON();
itemJSON.version = 6;
itemJSON.data.version = 6;
req.respond(
200,
{
"Last-Modified-Version": 6
},
JSON.stringify({
successful: {
"0": itemJSON
},
success: {
"0": json[0].key
},
unchanged: {},
failed: {}
})
);
}
}
});
waitForDialog(null, 'accept', 'chrome://zotero/content/longTagFixer.xul');
yield runner.sync({ libraries: [Zotero.Libraries.userLibraryID] });
assert.isFalse(Zotero.Tags.getID(tag));
assert.isNumber(Zotero.Tags.getID('feeling'));
});
it("should delete a tag", function* () {
win = yield loadZoteroPane();
var item = yield createDataObject('item');
var tag = "title;feeling;matter;drum;treatment;caring;earthy;shrill;unit;obedient;hover;healthy;cheap;clever;wren;wicked;clip;shoe;jittery;shape;clear;dime;increase;complete;level;milk;false;infamous;lamentable;measure;cuddly;tasteless;peace;top;pencil;caption;unusual;depressed;frantic";
item.addTag(tag, 1);
yield item.saveTx();
setResponse('keyInfo.fullAccess');
setResponse('userGroups.groupVersions');
setResponse('groups.ownerGroup');
setResponse('groups.memberGroup');
server.respond(function (req) {
if (req.method == "POST" && req.url == baseURL + "users/1/items") {
var json = JSON.parse(req.requestBody);
if (json[0].tags.length == 1) {
req.respond(
200,
{
"Last-Modified-Version": 5
},
JSON.stringify({
successful: {},
success: {},
unchanged: {},
failed: {
"0": {
code: 413,
message: "Tag 'title;feeling;matter;drum;treatment;caring;earthy;shrill;unit;obedient;hover…' is too long to sync",
data: {
tag
}
}
}
})
);
}
else {
let itemJSON = item.toResponseJSON();
itemJSON.version = 6;
itemJSON.data.version = 6;
req.respond(
200,
{
"Last-Modified-Version": 6
},
JSON.stringify({
successful: {
"0": itemJSON
},
success: {
"0": json[0].key
},
unchanged: {},
failed: {}
})
);
}
}
});
waitForDialog(function (dialog) {
dialog.Zotero_Long_Tag_Fixer.switchMode(2);
}, 'accept', 'chrome://zotero/content/longTagFixer.xul');
yield runner.sync({ libraries: [Zotero.Libraries.userLibraryID] });
assert.isFalse(Zotero.Tags.getID(tag));
assert.isFalse(Zotero.Tags.getID('feeling'));
});
});
});
})