diff --git a/chrome/content/zotero/xpcom/recognizePDF.js b/chrome/content/zotero/xpcom/recognizePDF.js index 20f83acefbc..50317bf503f 100644 --- a/chrome/content/zotero/xpcom/recognizePDF.js +++ b/chrome/content/zotero/xpcom/recognizePDF.js @@ -577,6 +577,7 @@ Zotero.RecognizePDF = new function () { Zotero.debug(translatedItems); if (translatedItems.length) { let newItem = new Zotero.Item; + newItem.libraryID = libraryID; // Convert tags to automatic. For other items this is done automatically in // translate.js for other items, but for ISBNs we just get the data // (libraryID=false) and do the saving manually. @@ -591,7 +592,6 @@ Zotero.RecognizePDF = new function () { return tag; }); newItem.fromJSON(translatedItems[0]); - newItem.libraryID = libraryID; if (!newItem.abstractNote && res.abstract) { newItem.setField('abstractNote', res.abstract); } @@ -608,7 +608,6 @@ Zotero.RecognizePDF = new function () { } if (res.title) { - let type = 'journalArticle'; if (res.type === 'book-chapter') { @@ -616,6 +615,7 @@ Zotero.RecognizePDF = new function () { } let newItem = new Zotero.Item(type); + newItem.libraryID = libraryID; newItem.setField('title', res.title); let creators = []; diff --git a/test/tests/data/recognizePDF_test_DOI.pdf b/test/tests/data/recognizePDF_test_DOI.pdf index 324e83ceee7..28d78b5ca9e 100644 Binary files a/test/tests/data/recognizePDF_test_DOI.pdf and b/test/tests/data/recognizePDF_test_DOI.pdf differ diff --git a/test/tests/data/recognizePDF_test_GS.pdf b/test/tests/data/recognizePDF_test_GS.pdf deleted file mode 100644 index 28d78b5ca9e..00000000000 Binary files a/test/tests/data/recognizePDF_test_GS.pdf and /dev/null differ diff --git a/test/tests/data/recognizePDF_test_title.pdf b/test/tests/data/recognizePDF_test_title.pdf new file mode 100644 index 00000000000..1e19b739f6e Binary files /dev/null and b/test/tests/data/recognizePDF_test_title.pdf differ diff --git a/test/tests/recognizePDFTest.js b/test/tests/recognizePDFTest.js index d72cb9f3ded..5911a9ad31e 100644 --- a/test/tests/recognizePDFTest.js +++ b/test/tests/recognizePDFTest.js @@ -28,11 +28,11 @@ describe("PDF Recognition", function() { } }); - it("should recognize a PDF", async function () { + it("should recognize a PDF by DOI", async function () { this.timeout(30000); // Import the PDF var testdir = getTestDataDirectory(); - testdir.append("recognizePDF_test_GS.pdf"); + testdir.append("recognizePDF_test_DOI.pdf"); var attachment = await Zotero.Attachments.importFromFile({ file: testdir }); @@ -65,7 +65,7 @@ describe("PDF Recognition", function() { this.timeout(30000); // Import the PDF var testdir = getTestDataDirectory(); - testdir.append("recognizePDF_test_GS.pdf"); + testdir.append("recognizePDF_test_DOI.pdf"); var collection = await createDataObject('collection'); var attachment = await Zotero.Attachments.importFromFile({ file: testdir, @@ -89,4 +89,94 @@ describe("PDF Recognition", function() { assert.isTrue(collection.hasItem(item.id)); }); + + it("should recognize PDF by DOI and put new item in same collection in group library", async function () { + this.timeout(30000); + var testdir = getTestDataDirectory(); + testdir.append("recognizePDF_test_DOI.pdf"); + var group = await getGroup(); + var collection = await createDataObject('collection', { libraryID: group.libraryID }); + var attachment = await Zotero.Attachments.importFromFile({ + libraryID: group.libraryID, + 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)); + }); + + it.skip("should recognize PDF by ISBN and put new item in same collection in group library", async function () { + this.timeout(30000); + var testdir = getTestDataDirectory(); + testdir.append("recognizePDF_test_ISBN.pdf"); + var group = await getGroup(); + var collection = await createDataObject('collection', { libraryID: group.libraryID }); + var attachment = await Zotero.Attachments.importFromFile({ + libraryID: group.libraryID, + 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)); + }); + + it("should recognize PDF by title and put new item in same collection in group library", async function () { + this.timeout(30000); + var testdir = getTestDataDirectory(); + testdir.append("recognizePDF_test_title.pdf"); + var group = await getGroup(); + var collection = await createDataObject('collection', { libraryID: group.libraryID }); + var attachment = await Zotero.Attachments.importFromFile({ + libraryID: group.libraryID, + 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