diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index 2901e08bf2..9dc6b2c114 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -1412,13 +1412,17 @@ var CollectionTree = class CollectionTree extends LibraryTree { * rows are selected, where the items list can span collections or libraries and acting * on one row's value isn't safe * + * Pre-release builds throw regardless of the selection, so that plugin developers see + * the failure. + * * Also used by the ZoteroPane methods that wrap these, which pass their own names. * * @param {String} name * @param {String} replacement */ _requireSingleSelection(name, replacement) { - if (this.selection.count > 1) { + if (this.selection.count > 1 + || Zotero.isBetaBuild || Zotero.isDevBuild || Zotero.isSourceBuild) { throw new Error(`${name} was removed -- use ${replacement}`); } Zotero.Plugins.warnRemovedAPICall(name, replacement); diff --git a/test/tests/collectionTreeTest.js b/test/tests/collectionTreeTest.js index 95be9bcc97..669df1f3fc 100644 --- a/test/tests/collectionTreeTest.js +++ b/test/tests/collectionTreeTest.js @@ -2175,6 +2175,19 @@ describe("Zotero.CollectionTree", function () { }) describe("removed single-selection methods", function () { + var buildFlags = ['isBetaBuild', 'isDevBuild', 'isSourceBuild']; + var savedBuildFlags; + + beforeEach(function () { + savedBuildFlags = buildFlags.map(flag => Zotero[flag]); + // Tests run in a source build, where these methods always throw + buildFlags.forEach(flag => Zotero[flag] = false); + }); + + afterEach(function () { + buildFlags.forEach((flag, i) => Zotero[flag] = savedBuildFlags[i]); + }); + it("should return the selected row when focus is on a different row", async function () { var collection1 = await createDataObject('collection'); var collection2 = await createDataObject('collection'); @@ -2199,5 +2212,14 @@ describe("Zotero.CollectionTree", function () { assert.throws(() => cv.getSelectedCollection()); assert.throws(() => zp.getSelectedLibraryID()); }); + + it("should throw in pre-release builds with a single row selected", async function () { + Zotero.isBetaBuild = true; + var collection = await createDataObject('collection'); + cv.selection.select(cv.getRowIndexByID(collection.treeViewID)); + + assert.throws(() => cv.getSelectedCollection()); + assert.throws(() => zp.getSelectedCollection()); + }); }); })