Fix test breakage after 5ff2a59f87

And remove all instances of `publicationsLibraryID`
This commit is contained in:
Dan Stillman 2017-04-13 00:13:27 -04:00
parent 5ff2a59f87
commit 6d18b46165
8 changed files with 41 additions and 142 deletions

View File

@ -70,6 +70,7 @@ var ZoteroAdvancedSearch = new function() {
isLibrary: function () { return false; },
isCollection: function () { return false; },
isSearch: function () { return true; },
isPublications: () => false,
isFeed: () => false,
isShare: function () { return false; },
isTrash: function () { return false; }

View File

@ -630,7 +630,10 @@ var Zotero_Browser = new function() {
}
if (!Zotero.isConnector) {
if (libraryID === Zotero.Libraries.publicationsLibraryID) {
if (ZoteroPane.collectionsView
&& ZoteroPane.collectionsView
&& ZoteroPane.collectionsView.selectedTreeRow
&& ZoteroPane.collectionsView.selectedTreeRow.isPublications()) {
Zotero_Browser.progress.Translation.cannotAddToPublications();
return;
}

View File

@ -123,7 +123,7 @@ Zotero.URI = new function () {
* @return {Zotero.Library|false}
*/
this.getPathLibrary = function (path) {
let matches = path.match(/^\/\/?users\/(\d+)(\/publications)?/);
let matches = path.match(/^\/\/?users\/(\d+));
if (matches) {
let userID = matches[1];
let currentUserID = Zotero.Users.getCurrentUserID();
@ -132,9 +132,6 @@ Zotero.URI = new function () {
+ `(${userID} != ${currentUserID})`);
return false;
}
if (matches[2]) {
return Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
}
return Zotero.Libraries.userLibrary;
}
matches = path.match(/^\/groups\/(\d+)/);
@ -365,9 +362,7 @@ Zotero.URI = new function () {
let library;
if (uriParts[1] == 'users') {
let type = uriParts[4];
if (type == 'publications') {
library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
} else if (!type) {
if (!type) {
// Handles local and synced libraries
library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
} else {

View File

@ -190,7 +190,7 @@ describe("Zotero_Browser", function () {
yield deferred.promise;
yield loadZoteroPane(win);
yield selectLibrary(win, Zotero.Libraries.publicationsLibraryID);
yield win.ZoteroPane.collectionsView.selectByID("P" + Zotero.Libraries.userLibraryID);
var promise = waitForDialog(function (dialog) {
assert.include(
@ -212,7 +212,7 @@ describe("Zotero_Browser", function () {
yield deferred.promise;
yield loadZoteroPane(win);
yield selectLibrary(win, Zotero.Libraries.publicationsLibraryID);
yield win.ZoteroPane.collectionsView.selectByID("P" + Zotero.Libraries.userLibraryID);
var promise = waitForDialog(function (dialog) {
assert.include(

View File

@ -5,7 +5,6 @@ describe("Zotero.Libraries", function() {
before(function* () {
builtInLibraries = [
Zotero.Libraries.userLibraryID,
Zotero.Libraries.publicationsLibraryID
];
group = yield createGroup({ name: groupName });
@ -16,11 +15,6 @@ describe("Zotero.Libraries", function() {
assert(Number.isInteger(Zotero.Libraries.userLibraryID), ".userLibraryID is an integer");
assert.isAbove(Zotero.Libraries.userLibraryID, 0);
});
it("should provide publications library ID as .publicationsLibraryID", function() {
assert.isDefined(Zotero.Libraries.publicationsLibraryID);
assert(Number.isInteger(Zotero.Libraries.publicationsLibraryID), ".publicationsLibraryID is an integer");
assert.isAbove(Zotero.Libraries.publicationsLibraryID, 0);
});
describe("#getAll()", function() {
it("should return an array of Zotero.Library instances", function() {
@ -43,7 +37,6 @@ describe("Zotero.Libraries", function() {
// Check sort
assert.equal(ids[0], Zotero.Libraries.userLibraryID);
assert.equal(ids[1], Zotero.Libraries.publicationsLibraryID);
var last = "";
var collation = Zotero.getLocaleCollation();
@ -76,7 +69,6 @@ describe("Zotero.Libraries", function() {
describe("#getName()", function() {
it("should return correct library name for built-in libraries", function() {
assert.equal(Zotero.Libraries.getName(Zotero.Libraries.userLibraryID), Zotero.getString('pane.collections.library'), "user library name is correct");
assert.equal(Zotero.Libraries.getName(Zotero.Libraries.publicationsLibraryID), Zotero.getString('pane.collections.publications'), "publications library name is correct");
});
it("should return correct name for a group library", function() {
assert.equal(Zotero.Libraries.getName(group.libraryID), groupName);
@ -88,7 +80,6 @@ describe("Zotero.Libraries", function() {
describe("#getType()", function() {
it("should return correct library type for built-in libraries", function() {
assert.equal(Zotero.Libraries.getType(Zotero.Libraries.userLibraryID), 'user', "user library type is correct");
assert.equal(Zotero.Libraries.getType(Zotero.Libraries.publicationsLibraryID), 'publications', "publications library type is correct");
});
it("should return correct library type for a group library", function() {
assert.equal(Zotero.Libraries.getType(group.libraryID), 'group');
@ -101,9 +92,6 @@ describe("Zotero.Libraries", function() {
it("should always return true for user library", function() {
assert.isTrue(Zotero.Libraries.isEditable(Zotero.Libraries.userLibraryID));
});
it("should always return true for publications library", function() {
assert.isTrue(Zotero.Libraries.isEditable(Zotero.Libraries.publicationsLibraryID));
});
it("should return correct state for a group library", function* () {
group.editable = true;
yield group.saveTx();
@ -209,7 +197,6 @@ describe("Zotero.Libraries", function() {
describe("#hasTrash()", function() {
it("should return true for all library types", function() {
assert.isTrue(Zotero.Libraries.hasTrash(Zotero.Libraries.userLibraryID));
assert.isTrue(Zotero.Libraries.hasTrash(Zotero.Libraries.publicationsLibraryID));
assert.isTrue(Zotero.Libraries.hasTrash(group.libraryID));
});
it("should throw for invalid library ID", function() {

View File

@ -92,12 +92,9 @@ describe("Zotero.Library", function() {
assert.equal((yield Zotero.DB.valueQueryAsync("SELECT filesEditable FROM libraries WHERE libraryID=?", library.libraryID)), 0)
});
it("should not be settable for user and publications libraries", function* () {
it("should not be settable for user libraries", function* () {
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
assert.throws(function() {library.editable = false}, /^Cannot change _libraryEditable for user library$/, "does not allow setting user library as not editable");
library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
assert.throws(function() {library.editable = false}, /^Cannot change _libraryEditable for publications library$/, "does not allow setting publications library as not editable");
});
});
@ -106,10 +103,6 @@ describe("Zotero.Library", function() {
assert.isTrue(Zotero.Libraries.userLibrary.filesEditable);
});
it("should always return true for publications library", function() {
assert.isTrue(Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID).filesEditable);
});
it("should return files editable status", function() {
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
assert.isTrue(library.filesEditable, 'user library is files editable');
@ -127,12 +120,9 @@ describe("Zotero.Library", function() {
assert.isFalse(Zotero.Libraries.isFilesEditable(library.libraryID), "sets files editable in cache to false");
});
it("should not be settable for user and publications libraries", function* () {
it("should not be settable for user libraries", function* () {
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
assert.throws(function() {library.filesEditable = false}, /^Cannot change _libraryFilesEditable for user library$/, "does not allow setting user library as not files editable");
library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
assert.throws(function() {library.filesEditable = false}, /^Cannot change _libraryFilesEditable for publications library$/, "does not allow setting publications library as not files editable");
});
});
@ -153,12 +143,9 @@ describe("Zotero.Library", function() {
assert.equal((yield Zotero.DB.valueQueryAsync("SELECT archived FROM libraries WHERE libraryID=?", library.libraryID)), 0)
});
it("should not be settable for user and publications libraries", function* () {
it("should not be settable for user libraries", function* () {
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
assert.throws(() => library.archived = true, /^Cannot change _libraryArchived for user library$/, "does not allow setting user library as archived");
library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
assert.throws(() => library.archived = true, /^Cannot change _libraryArchived for publications library$/, "does not allow setting publications library as archived");
});
it("should only be settable on read-only library", function* () {
@ -231,9 +218,6 @@ describe("Zotero.Library", function() {
it("should not allow erasing permanent libraries", function* () {
let library = Zotero.Libraries.get(Zotero.Libraries.userLibraryID);
yield assert.isRejected(library.eraseTx(), /^Error: Cannot erase library of type 'user'$/, "does not allow erasing user library");
library = Zotero.Libraries.get(Zotero.Libraries.publicationsLibraryID);
yield assert.isRejected(library.eraseTx(), /^Error: Cannot erase library of type 'publications'$/, "does not allow erasing publications library");
});
it("should not allow erasing unsaved libraries", function* () {

View File

@ -649,7 +649,7 @@ describe("Zotero.Sync.Data.Local", function() {
})
it("should roll back partial object changes on error", function* () {
var libraryID = Zotero.Libraries.publicationsLibraryID;
var libraryID = Zotero.Libraries.userLibraryID;
var key1 = "AAAAAAAA";
var key2 = "BBBBBBBB";
var json = [
@ -669,9 +669,8 @@ describe("Zotero.Sync.Data.Local", function() {
data: {
key: key2,
version: 1,
itemType: "journalArticle",
title: "Test B",
deleted: true // Not allowed in My Publications
itemType: "invalidType",
title: "Test B"
}
}
];
@ -693,7 +692,7 @@ describe("Zotero.Sync.Data.Local", function() {
before(function* () {
lib1 = Zotero.Libraries.userLibraryID;
lib2 = Zotero.Libraries.publicationsLibraryID;
lib2 = (yield getGroup()).libraryID;
});
beforeEach(function* () {

View File

@ -5,7 +5,7 @@ describe("Zotero.Sync.Runner", function () {
var apiKey = Zotero.Utilities.randomString(24);
var baseURL = "http://local.zotero/";
var userLibraryID, publicationsLibraryID, runner, caller, server, stub, spy;
var userLibraryID, runner, caller, server, stub, spy;
var responses = {
keyInfo: {
@ -120,7 +120,6 @@ describe("Zotero.Sync.Runner", function () {
});
userLibraryID = Zotero.Libraries.userLibraryID;
publicationsLibraryID = Zotero.Libraries.publicationsLibraryID;
Zotero.HTTP.mock = sinon.FakeXMLHttpRequest;
server = sinon.fakeServer.create();
@ -200,10 +199,10 @@ describe("Zotero.Sync.Runner", function () {
var libraries = yield runner.checkLibraries(
runner.getAPIClient({ apiKey }), false, responses.keyInfo.fullAccess.json
);
assert.lengthOf(libraries, 4);
assert.lengthOf(libraries, 3);
assert.sameMembers(
libraries,
[userLibraryID, publicationsLibraryID, group1.libraryID, group2.libraryID]
[userLibraryID, group1.libraryID, group2.libraryID]
);
})
@ -234,10 +233,10 @@ describe("Zotero.Sync.Runner", function () {
runner.getAPIClient({ apiKey }),
false,
responses.keyInfo.fullAccess.json,
[userLibraryID, publicationsLibraryID]
[userLibraryID]
);
assert.lengthOf(libraries, 2);
assert.sameMembers(libraries, [userLibraryID, publicationsLibraryID]);
assert.lengthOf(libraries, 1);
assert.sameMembers(libraries, [userLibraryID]);
var libraries = yield runner.checkLibraries(
runner.getAPIClient({ apiKey }),
@ -318,8 +317,8 @@ describe("Zotero.Sync.Runner", function () {
responses.keyInfo.fullAccess.json
);
assert.lengthOf(libraries, 3);
assert.sameMembers(libraries, [userLibraryID, publicationsLibraryID, syncedGroup.libraryID]);
assert.lengthOf(libraries, 2);
assert.sameMembers(libraries, [userLibraryID, syncedGroup.libraryID]);
});
it("should unarchive library if available remotely", function* () {
@ -346,10 +345,10 @@ describe("Zotero.Sync.Runner", function () {
responses.keyInfo.fullAccess.json
);
assert.lengthOf(libraries, 4);
assert.lengthOf(libraries, 3);
assert.sameMembers(
libraries,
[userLibraryID, publicationsLibraryID, syncedGroup.libraryID, archivedGroup.libraryID]
[userLibraryID, syncedGroup.libraryID, archivedGroup.libraryID]
);
assert.isFalse(archivedGroup.archived);
});
@ -370,11 +369,11 @@ describe("Zotero.Sync.Runner", function () {
runner.getAPIClient({ apiKey }),
false,
responses.keyInfo.fullAccess.json,
[userLibraryID, publicationsLibraryID, group.libraryID]
[userLibraryID, group.libraryID]
);
assert.lengthOf(libraries, 3);
assert.sameMembers(libraries, [userLibraryID, publicationsLibraryID, group.libraryID]);
assert.lengthOf(libraries, 2);
assert.sameMembers(libraries, [userLibraryID, group.libraryID]);
});
it("should update outdated group metadata", function* () {
@ -405,10 +404,10 @@ describe("Zotero.Sync.Runner", function () {
assert.ok(stub.calledTwice);
stub.restore();
assert.lengthOf(libraries, 4);
assert.lengthOf(libraries, 3);
assert.sameMembers(
libraries,
[userLibraryID, publicationsLibraryID, group1.libraryID, group2.libraryID]
[userLibraryID, group1.libraryID, group2.libraryID]
);
assert.equal(group1.name, groupData1.json.data.name);
@ -474,7 +473,7 @@ describe("Zotero.Sync.Runner", function () {
var libraries = yield runner.checkLibraries(
runner.getAPIClient({ apiKey }), false, responses.keyInfo.fullAccess.json
);
assert.lengthOf(libraries, 4);
assert.lengthOf(libraries, 3);
var groupData1 = responses.groups.ownerGroup;
var group1 = Zotero.Groups.get(groupData1.json.id);
var groupData2 = responses.groups.memberGroup;
@ -483,7 +482,7 @@ describe("Zotero.Sync.Runner", function () {
assert.ok(group2);
assert.sameMembers(
libraries,
[userLibraryID, publicationsLibraryID, group1.libraryID, group2.libraryID]
[userLibraryID, group1.libraryID, group2.libraryID]
);
assert.equal(group1.name, groupData1.json.data.name);
assert.isTrue(group1.editable);
@ -505,8 +504,8 @@ describe("Zotero.Sync.Runner", function () {
var libraries = yield runner.checkLibraries(
runner.getAPIClient({ apiKey }), false, responses.keyInfo.fullAccess.json
);
assert.lengthOf(libraries, 3);
assert.sameMembers(libraries, [userLibraryID, publicationsLibraryID, group2.libraryID]);
assert.lengthOf(libraries, 2);
assert.sameMembers(libraries, [userLibraryID, group2.libraryID]);
assert.isFalse(Zotero.Groups.exists(groupData1.json.id));
assert.isTrue(Zotero.Groups.exists(groupData2.json.id));
})
@ -541,8 +540,8 @@ describe("Zotero.Sync.Runner", function () {
runner.getAPIClient({ apiKey }), false, responses.keyInfo.fullAccess.json
);
assert.equal(called, 2);
assert.lengthOf(libraries, 2);
assert.sameMembers(libraries, [userLibraryID, publicationsLibraryID]);
assert.lengthOf(libraries, 1);
assert.sameMembers(libraries, [userLibraryID]);
// Groups should still exist but be read-only and archived
[group1, group2].forEach((group) => {
assert.isTrue(Zotero.Groups.exists(group.id));
@ -698,43 +697,6 @@ describe("Zotero.Sync.Runner", function () {
},
json: []
});
// My Publications
setResponse({
method: "GET",
url: "users/1/publications/settings",
status: 200,
headers: {
"Last-Modified-Version": 10
},
json: []
});
setResponse({
method: "GET",
url: "users/1/publications/items/top?format=versions&includeTrashed=1",
status: 200,
headers: {
"Last-Modified-Version": 10
},
json: []
});
setResponse({
method: "GET",
url: "users/1/publications/items?format=versions&includeTrashed=1",
status: 200,
headers: {
"Last-Modified-Version": 10
},
json: []
});
setResponse({
method: "GET",
url: "users/1/publications/deleted?since=0",
status: 200,
headers: {
"Last-Modified-Version": 10
},
json: []
});
// Group library 1
setResponse({
method: "GET",
@ -855,15 +817,6 @@ describe("Zotero.Sync.Runner", function () {
},
json: {}
});
setResponse({
method: "GET",
url: "users/1/publications/fulltext?format=versions",
status: 200,
headers: {
"Last-Modified-Version": 10
},
json: {}
});
setResponse({
method: "GET",
url: "groups/1623562/fulltext?format=versions",
@ -892,10 +845,6 @@ describe("Zotero.Sync.Runner", function () {
Zotero.Libraries.getVersion(userLibraryID),
5
);
assert.equal(
Zotero.Libraries.getVersion(publicationsLibraryID),
10
);
assert.equal(
Zotero.Libraries.getVersion(Zotero.Groups.getLibraryIDFromGroupID(1623562)),
15
@ -952,7 +901,7 @@ describe("Zotero.Sync.Runner", function () {
onError: e => { throw e },
});
assert.equal(stub.callCount, 4);
assert.equal(stub.callCount, 3);
stub.restore();
});
})
@ -1035,9 +984,9 @@ describe("Zotero.Sync.Runner", function () {
});
it("should show the sync error icon on error", function* () {
let pubLib = Zotero.Libraries.get(publicationsLibraryID);
pubLib.libraryVersion = 5;
yield pubLib.save();
let library = Zotero.Libraries.userLibrary;
library.libraryVersion = 5;
yield library.save();
setResponse('keyInfo.fullAccess');
setResponse('userGroups.groupVersionsEmpty');
@ -1053,25 +1002,6 @@ describe("Zotero.Sync.Runner", function () {
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?format=versions",
status: 200,
headers: {
"Last-Modified-Version": 5
},
json: {}
});
spy = sinon.spy(runner, "updateIcons");
yield runner.sync();