From 6d18b461654adfb55b4568a222ac422c4bcda121 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 13 Apr 2017 00:13:27 -0400 Subject: [PATCH] Fix test breakage after 5ff2a59f87 And remove all instances of `publicationsLibraryID` --- chrome/content/zotero/advancedSearch.js | 1 + chrome/content/zotero/browser.js | 5 +- chrome/content/zotero/xpcom/uri.js | 9 +- test/tests/browserTest.js | 4 +- test/tests/librariesTest.js | 13 --- test/tests/libraryTest.js | 22 +---- test/tests/syncLocalTest.js | 9 +- test/tests/syncRunnerTest.js | 120 +++++------------------- 8 files changed, 41 insertions(+), 142 deletions(-) diff --git a/chrome/content/zotero/advancedSearch.js b/chrome/content/zotero/advancedSearch.js index 62d9a3878..78f73ddd2 100644 --- a/chrome/content/zotero/advancedSearch.js +++ b/chrome/content/zotero/advancedSearch.js @@ -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; } diff --git a/chrome/content/zotero/browser.js b/chrome/content/zotero/browser.js index 20acf816f..a2ac94f8a 100644 --- a/chrome/content/zotero/browser.js +++ b/chrome/content/zotero/browser.js @@ -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; } diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js index a430dd2bf..dac3b17bc 100644 --- a/chrome/content/zotero/xpcom/uri.js +++ b/chrome/content/zotero/xpcom/uri.js @@ -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 { diff --git a/test/tests/browserTest.js b/test/tests/browserTest.js index 183ba5dcc..c36fa72a2 100644 --- a/test/tests/browserTest.js +++ b/test/tests/browserTest.js @@ -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( diff --git a/test/tests/librariesTest.js b/test/tests/librariesTest.js index d0783daaa..b55cf18ae 100644 --- a/test/tests/librariesTest.js +++ b/test/tests/librariesTest.js @@ -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() { diff --git a/test/tests/libraryTest.js b/test/tests/libraryTest.js index 5e3e2af43..9cc89af64 100644 --- a/test/tests/libraryTest.js +++ b/test/tests/libraryTest.js @@ -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* () { diff --git a/test/tests/syncLocalTest.js b/test/tests/syncLocalTest.js index d2b6ccc4d..cfade8e6d 100644 --- a/test/tests/syncLocalTest.js +++ b/test/tests/syncLocalTest.js @@ -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* () { diff --git a/test/tests/syncRunnerTest.js b/test/tests/syncRunnerTest.js index ba81335af..7071f14ba 100644 --- a/test/tests/syncRunnerTest.js +++ b/test/tests/syncRunnerTest.js @@ -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();