From ef5f8be920ef57431aa2cdfa531f43083388cdcc Mon Sep 17 00:00:00 2001 From: abaevbog Date: Sat, 2 Aug 2025 00:50:54 -0500 Subject: [PATCH] fix subcollection not being copied to library root (#5464) Fixes: #5463 --- chrome/content/zotero/collectionTree.jsx | 5 ++--- test/tests/zoteroPaneTest.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/collectionTree.jsx b/chrome/content/zotero/collectionTree.jsx index 8b3a4c004a..854e7cf9b5 100644 --- a/chrome/content/zotero/collectionTree.jsx +++ b/chrome/content/zotero/collectionTree.jsx @@ -1971,9 +1971,8 @@ var CollectionTree = class CollectionTree extends LibraryTree { if (desc.type == 'collection') { var c = await Zotero.Collections.getAsync(desc.id); let newCollection = c.clone(targetLibraryID); - if (parentID) { - newCollection.parentID = parentID; - } + // set the parent collection if provided or null if copying to root library + newCollection.parentID = parentID || null; var collectionID = await newCollection.save(); // Record link only if copying to a different library diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js index f66cd88c1a..600fa04f6e 100644 --- a/test/tests/zoteroPaneTest.js +++ b/test/tests/zoteroPaneTest.js @@ -1958,6 +1958,29 @@ describe("ZoteroPane", function() { // Menu of the library with linked sub-collection should be disabled assert.equal(groupMenu.disabled, true); }); + + it("should copy subcollection to library root", async function () { + let collectionParent = await createDataObject('collection'); + let collectionChild = await createDataObject('collection', { parentID: collectionParent.id }); + let libraryDestination = Zotero.Libraries.get(collectionChild.libraryID); + + let item = await createDataObject('item', { collections: [collectionChild.id] }); + + await zp.collectionsView.selectByID("C" + collectionChild.id); + + await zp.copyCollection(libraryDestination); + let data = await waitForNotifierEvent("add", "collection"); + let collectionID = data.ids[0]; + let newCollection = Zotero.Collections.get(collectionID); + + // Copied collection has the same name as the original + assert.equal(newCollection.name, collectionChild.name); + // Copied collections contain the same item + let items = newCollection.getDescendents(false, 'item').map(item => item.id); + assert.sameMembers(items, [item.id]); + // Copied collection is a top-level collection + assert.notOk(newCollection.parentID); + }); }); describe("#moveCollection", function () { it("should move collection into another collection of the same library", async function () {