mirror of
https://github.com/zotero/zotero.git
synced 2026-10-03 02:21:49 +00:00
Throw from removed selection methods in pre-release builds
The shims from 5697ee0af7 keep old plugins working for users, but
beta/dev/source builds should still throw to get the attention of
developers and (hopefully breakage-tolerant) beta users.
This commit is contained in:
parent
0e00c1ce51
commit
e56fad828d
2 changed files with 27 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
});
|
||||
});
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue