From afee1d16ad54e70548545bde7577dbaa673def95 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 25 Mar 2016 02:23:45 -0400 Subject: [PATCH] Fix saving an item with a child note into a collection --- .../xpcom/translation/translate_item.js | 2 +- test/tests/browserTest.js | 23 +++++++++++++++++++ test/tests/data/book_and_child_note.ris | 5 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/tests/data/book_and_child_note.ris diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index c8fe1f17e0..a505aad287 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -600,7 +600,7 @@ Zotero.Translate.ItemSaver.prototype = { } else { myNote.setNote(note); } - if (this._collections) { + if (!parentID && this._collections) { myNote.setCollections(this._collections); } yield myNote.save(); diff --git a/test/tests/browserTest.js b/test/tests/browserTest.js index 683e2782e2..d65d1db603 100644 --- a/test/tests/browserTest.js +++ b/test/tests/browserTest.js @@ -55,6 +55,29 @@ describe("Zotero_Browser", function () { assert.isTrue(collection.hasItem(items[0].id)); }) + it("should save book with child note to current collection", function* () { + var uri = OS.Path.join( + getTestDataDirectory().path, "book_and_child_note.ris" + ); + var deferred = Zotero.Promise.defer(); + win.addEventListener('pageshow', () => deferred.resolve()); + win.loadURI(uri); + yield deferred.promise; + + yield loadZoteroPane(win); + var collection = yield createDataObject('collection'); + + var promise = waitForItemEvent('add'); + yield win.Zotero_Browser.scrapeThisPage(); + + var ids = yield promise; + var items = Zotero.Items.get(ids); + assert.lengthOf(items, 2); + assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'book'); + assert.isTrue(collection.hasItem(items[0].id)); + assert.equal(Zotero.ItemTypes.getName(items[1].itemTypeID), 'note'); + }); + it("should save PDF to library root", function* () { var uri = OS.Path.join(getTestDataDirectory().path, "test.pdf"); var deferred = Zotero.Promise.defer(); diff --git a/test/tests/data/book_and_child_note.ris b/test/tests/data/book_and_child_note.ris new file mode 100644 index 0000000000..90d6c12ca5 --- /dev/null +++ b/test/tests/data/book_and_child_note.ris @@ -0,0 +1,5 @@ +TY - BOOK +TI - Parent +N1 -

Child

+ER - +