Skip to content

Commit

Permalink
Save parent item to correct library when recognizing PDF without DOI
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Apr 2, 2018
1 parent a8d1999 commit 4f9847d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 5 deletions.
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/recognizePDF.js
Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -608,14 +608,14 @@ Zotero.RecognizePDF = new function () {
}

if (res.title) {

let type = 'journalArticle';

if (res.type === 'book-chapter') {
type = 'bookSection';
}

let newItem = new Zotero.Item(type);
newItem.libraryID = libraryID;
newItem.setField('title', res.title);

let creators = [];
Expand Down
Binary file modified test/tests/data/recognizePDF_test_DOI.pdf
Binary file not shown.
Binary file removed test/tests/data/recognizePDF_test_GS.pdf
Binary file not shown.
Binary file added test/tests/data/recognizePDF_test_title.pdf
Binary file not shown.
96 changes: 93 additions & 3 deletions test/tests/recognizePDFTest.js
Expand Up @@ -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
});
Expand Down Expand Up @@ -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,
Expand All @@ -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));
});
});

0 comments on commit 4f9847d

Please sign in to comment.