From 773a93f55d77f4cb91161480b666ca9cfdacba4a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 7 Oct 2017 05:05:34 -0400 Subject: [PATCH] Fix item selection that requires switching to library root Broken in c7639f328fa --- chrome/content/zotero/xpcom/collectionTreeView.js | 9 ++++----- test/tests/collectionTreeViewTest.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index fb98fd651..759519856 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -1180,10 +1180,9 @@ Zotero.CollectionTreeView.prototype.selectItem = Zotero.Promise.coroutine(functi yield this.selectLibrary(item.libraryID); } - var itemTreeView = this.itemTreeView; - yield itemTreeView.waitForLoad(); + yield this.itemTreeView.waitForLoad(); - var selected = yield itemTreeView.selectItem(itemID, expand); + var selected = yield this.itemTreeView.selectItem(itemID, expand); if (selected) { return true; } @@ -1197,9 +1196,9 @@ Zotero.CollectionTreeView.prototype.selectItem = Zotero.Promise.coroutine(functi yield this.selectLibrary(item.libraryID); } - yield itemTreeView.waitForLoad(); + yield this.itemTreeView.waitForLoad(); - return itemTreeView.selectItem(itemID, expand); + return this.itemTreeView.selectItem(itemID, expand); }); diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js index 6b71d99c9..0d89e8167 100644 --- a/test/tests/collectionTreeViewTest.js +++ b/test/tests/collectionTreeViewTest.js @@ -481,8 +481,18 @@ describe("Zotero.CollectionTreeView", function() { yield win.ZoteroPane.deleteSelectedCollection(); assert.isFalse(cv.getRowIndexByID(id)) }) - - }) + }); + + describe("#selectItem()", function () { + it("should switch to library root if item isn't in collection", async function () { + var item = await createDataObject('item'); + var collection = await createDataObject('collection'); + await cv.selectItem(item.id); + await waitForItemsLoad(win); + assert.equal(cv.selection.currentIndex, 0); + assert.sameMembers(zp.itemsView.getSelectedItems(), [item]); + }); + }); describe("#drop()", function () { /**