Skip to content

Commit

Permalink
Fix test breakage after 5ff2a59
Browse files Browse the repository at this point in the history
And remove all instances of `publicationsLibraryID`
  • Loading branch information
dstillman committed Apr 13, 2017
1 parent 5ff2a59 commit 6d18b46
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 142 deletions.
1 change: 1 addition & 0 deletions chrome/content/zotero/advancedSearch.js
Expand Up @@ -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; }
Expand Down
5 changes: 4 additions & 1 deletion chrome/content/zotero/browser.js
Expand Up @@ -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;
}
Expand Down
9 changes: 2 additions & 7 deletions chrome/content/zotero/xpcom/uri.js
Expand Up @@ -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();
Expand All @@ -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+)/);
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test/tests/browserTest.js
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
13 changes: 0 additions & 13 deletions test/tests/librariesTest.js
Expand Up @@ -5,7 +5,6 @@ describe("Zotero.Libraries", function() {
before(function* () {
builtInLibraries = [
Zotero.Libraries.userLibraryID,
Zotero.Libraries.publicationsLibraryID
];

group = yield createGroup({ name: groupName });
Expand All @@ -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() {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down
22 changes: 3 additions & 19 deletions test/tests/libraryTest.js
Expand Up @@ -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");
});
});

Expand All @@ -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');
Expand All @@ -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");
});
});

Expand All @@ -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* () {
Expand Down Expand Up @@ -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* () {
Expand Down
9 changes: 4 additions & 5 deletions test/tests/syncLocalTest.js
Expand Up @@ -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 = [
Expand All @@ -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"
}
}
];
Expand All @@ -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* () {
Expand Down

0 comments on commit 6d18b46

Please sign in to comment.