diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index d95bd20e1..f3022e78e 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -820,9 +820,9 @@ Zotero.CollectionTreeView.prototype.expandToCollection = Zotero.Promise.coroutin return true; } var path = []; - var parent; - while (parent = col.parentID) { - path.unshift(parent); + var parentID; + while (parentID = col.parentID) { + path.unshift(parentID); col = yield Zotero.Collections.getAsync(parentID); } for each(var id in path) { diff --git a/chrome/content/zotero/xpcom/libraryTreeView.js b/chrome/content/zotero/xpcom/libraryTreeView.js index 67cdb7e32..b8ad2d022 100644 --- a/chrome/content/zotero/xpcom/libraryTreeView.js +++ b/chrome/content/zotero/xpcom/libraryTreeView.js @@ -81,7 +81,7 @@ Zotero.LibraryTreeView.prototype = { * @param {String} - Row id * @return {Integer} */ - getRowByID: function (id) { + getRowIndexByID: function (id) { // FIXME: Should work for itemIDs too var type = id[0]; id = ('' + id).substr(1); diff --git a/test/tests/collectionTreeViewTest.js b/test/tests/collectionTreeViewTest.js index 25fe247a6..613bcb4f0 100644 --- a/test/tests/collectionTreeViewTest.js +++ b/test/tests/collectionTreeViewTest.js @@ -48,6 +48,27 @@ describe("Zotero.CollectionTreeView", function() { }) }) + describe("#expandToCollection()", function () { + it("should expand a collection to a subcollection", function* () { + var cv = collectionsView; + var collection1 = yield createDataObject('collection'); + var collection2 = createUnsavedDataObject('collection'); + collection2.parentID = collection1.id; + yield collection2.save({ + skipSelect: true + }); + var row = cv.getRowIndexByID("C" + collection1.id); + assert.isFalse(cv.isContainerOpen(row)); + + yield cv.expandToCollection(collection2.id); + + // Make sure parent row position hasn't changed + assert.equal(cv.getRowIndexByID("C" + collection1.id), row); + // Parent should have been opened + assert.isTrue(cv.isContainerOpen(row)); + }) + }) + describe("#selectByID()", function () { it("should select the trash", function* () { yield collectionsView.selectByID("T1"); @@ -60,7 +81,7 @@ describe("Zotero.CollectionTreeView", function() { describe("#selectWait()", function () { it("shouldn't hang if row is already selected", function* () { - var row = collectionsView.getRowByID("T" + Zotero.Libraries.userLibraryID); + var row = collectionsView.getRowIndexByID("T" + Zotero.Libraries.userLibraryID); collectionsView.selection.select(row); yield Zotero.Promise.delay(50); yield collectionsView.selectWait(row); @@ -175,7 +196,7 @@ describe("Zotero.CollectionTreeView", function() { var item = yield createDataObject('item', false, { skipSelect: true }); - var row = collectionsView.getRowByID("C" + collection.id); + var row = collectionsView.getRowIndexByID("C" + collection.id); // Add observer to wait for collection add var deferred = Zotero.Promise.defer(); @@ -241,7 +262,7 @@ describe("Zotero.CollectionTreeView", function() { parentItemID: item.id }); - var row = collectionsView.getRowByID("L" + group.libraryID); + var row = collectionsView.getRowIndexByID("L" + group.libraryID); // Simulate a drag and drop var stub = sinon.stub(Zotero.DragDrop, "getDragTarget");