diff --git a/chrome/content/zotero/xpcom/recognizePDF.js b/chrome/content/zotero/xpcom/recognizePDF.js index cca865faf..079e50529 100644 --- a/chrome/content/zotero/xpcom/recognizePDF.js +++ b/chrome/content/zotero/xpcom/recognizePDF.js @@ -256,8 +256,8 @@ Zotero.RecognizePDF = new function () { let collections = attachment.getCollections(); await Zotero.DB.executeTransaction(async function () { if (collections.length) { - for (let collection of collections) { - parentItem.addToCollection(collection.id); + for (let collectionID of collections) { + parentItem.addToCollection(collectionID); } await parentItem.save(); } diff --git a/test/tests/recognizePDFTest.js b/test/tests/recognizePDFTest.js index 4a6632698..d72cb9f3d 100644 --- a/test/tests/recognizePDFTest.js +++ b/test/tests/recognizePDFTest.js @@ -60,4 +60,33 @@ describe("PDF Recognition", function() { Zotero.Attachments.getFileBaseNameFromItem(item) + '.pdf' ); }); + + it("should put new item in same collection", async function () { + this.timeout(30000); + // Import the PDF + var testdir = getTestDataDirectory(); + testdir.append("recognizePDF_test_GS.pdf"); + var collection = await createDataObject('collection'); + var attachment = await Zotero.Attachments.importFromFile({ + file: testdir, + collections: [collection.id] + }); + + win.ZoteroPane.recognizeSelected(); + + var addedIDs = await waitForItemEvent("add"); + var modifiedIDs = await waitForItemEvent("modify"); + assert.lengthOf(addedIDs, 1); + var item = Zotero.Items.get(addedIDs[0]); + assert.lengthOf(modifiedIDs, 2); + + // Wait for status to show as complete + var progressWindow = getWindows("chrome://zotero/content/recognizePDFDialog.xul")[0]; + var completeStr = Zotero.getString("recognizePDF.complete.label"); + while (progressWindow.document.getElementById("label").value != completeStr) { + await Zotero.Promise.delay(20); + } + + assert.isTrue(collection.hasItem(item.id)); + }); }); \ No newline at end of file