commit 4f9847da04b44fb3216a4fdbde05954af5985b55
parent a8d199967ee9f0ea58130a88eae5b3790e52eda5
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 2 Apr 2018 15:34:22 -0400
Save parent item to correct library when recognizing PDF without DOI
Diffstat:
5 files changed, 95 insertions(+), 5 deletions(-)
diff --git 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
Binary files differ.
diff --git a/test/tests/data/recognizePDF_test_GS.pdf b/test/tests/data/recognizePDF_test_GS.pdf
Binary files differ.
diff --git a/test/tests/data/recognizePDF_test_title.pdf b/test/tests/data/recognizePDF_test_title.pdf
Binary files differ.
diff --git 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