From fb01339c6bfb93ffcd285b289165148b2ffbe200 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 7 Jul 2021 01:31:20 -0400 Subject: [PATCH] Implement library.isGroup property, which was never properly implemented And since `Zotero.Libraries.isGroupLibrary()` just checked that property, that hasn't worked either since `isGroup` was added in 2015. There's no test for `.isGroup`, and the test for `isGroupLibrary()` used `if()` instead of `it()`, so it never actually ran. Also: - Remove old code block in search.js that called `isGroupLibrary()`. Since `isGroupLibrary()` didn't work, this block was unused, and its logic was previously added elsewhere. --- chrome/content/zotero/xpcom/data/library.js | 6 ++++++ chrome/content/zotero/xpcom/data/search.js | 6 ------ test/tests/librariesTest.js | 4 +++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/data/library.js b/chrome/content/zotero/xpcom/data/library.js index 5646abc738..70c67242af 100644 --- a/chrome/content/zotero/xpcom/data/library.js +++ b/chrome/content/zotero/xpcom/data/library.js @@ -147,6 +147,12 @@ Zotero.defineProperty(Zotero.Library.prototype, 'libraryTypeID', { } }); +Zotero.defineProperty(Zotero.Library.prototype, 'isGroup', { + get: function () { + return this.libraryType == 'group'; + } +}); + Zotero.defineProperty(Zotero.Library.prototype, 'libraryVersion', { get: function() { return this._get('_libraryVersion'); }, set: function(v) { return this._set('_libraryVersion', v); } diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js index c7ae8d738b..6414148c03 100644 --- a/chrome/content/zotero/xpcom/data/search.js +++ b/chrome/content/zotero/xpcom/data/search.js @@ -247,12 +247,6 @@ Zotero.Search.prototype._finalizeSave = Zotero.Promise.coroutine(function* (env) Zotero.Notifier.queue('modify', 'search', this.id, env.notifierData, env.options.notifierQueue); } - if (env.isNew && Zotero.Libraries.isGroupLibrary(this.libraryID)) { - var groupID = Zotero.Groups.getGroupIDFromLibraryID(this.libraryID); - var group = yield Zotero.Groups.get(groupID); - group.clearSearchCache(); - } - if (!env.skipCache) { yield this.reload(); // If new, there's no other data we don't have, so we can mark everything as loaded diff --git a/test/tests/librariesTest.js b/test/tests/librariesTest.js index ba2da772af..f27176967e 100644 --- a/test/tests/librariesTest.js +++ b/test/tests/librariesTest.js @@ -187,9 +187,11 @@ describe("Zotero.Libraries", function() { assert.isFalse(Zotero.Libraries.isGroupLibrary(id), "returns false for " + type + " library"); } }); - if("should return true for group library", function(){ + + it("should return true for group library", function () { assert.isTrue(Zotero.Libraries.isGroupLibrary(group.libraryID)); }) + it("should throw for invalid library ID", function() { assert.throws(Zotero.Libraries.isGroupLibrary.bind(Zotero.Libraries, -1), /^Invalid library ID /); });