From 55e9a0ee3508b1c0099c92f15f8b540d2768d05e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 3 Feb 2017 01:17:08 -0500 Subject: [PATCH] Update empty state of parent collection when deleting subcollection --- chrome/content/zotero/xpcom/data/collection.js | 10 ++++++++++ test/tests/collectionTest.js | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/chrome/content/zotero/xpcom/data/collection.js b/chrome/content/zotero/xpcom/data/collection.js index ea27181a2..24ff83bd4 100644 --- a/chrome/content/zotero/xpcom/data/collection.js +++ b/chrome/content/zotero/xpcom/data/collection.js @@ -605,6 +605,16 @@ Zotero.Collection.prototype._eraseData = Zotero.Promise.coroutine(function* (env } } + // Update child collection cache of parent collection + if (this.parentKey) { + let parentCollectionID = this.ObjectsClass.getIDFromLibraryAndKey( + this.libraryID, this.parentKey + ); + Zotero.DB.addCurrentCallback("commit", function () { + this.ObjectsClass.unregisterChildCollection(parentCollectionID, this.id); + }.bind(this)); + } + var placeholders = collections.map(() => '?').join(); // Remove item associations for all descendent collections diff --git a/test/tests/collectionTest.js b/test/tests/collectionTest.js index 5b9a971fb..bc3c9211d 100644 --- a/test/tests/collectionTest.js +++ b/test/tests/collectionTest.js @@ -168,6 +168,17 @@ describe("Zotero.Collection", function() { var childCollections = collection1.getChildCollections(); assert.lengthOf(childCollections, 0); }) + + it("should not include collections that have been deleted", function* () { + var collection1 = yield createDataObject('collection'); + var collection2 = yield createDataObject('collection', { parentID: collection1.id }); + yield collection1.saveTx(); + + yield collection2.eraseTx() + + var childCollections = collection1.getChildCollections(); + assert.lengthOf(childCollections, 0); + }) }) describe("#getChildItems()", function () {