Skip to content

Commit

Permalink
Fix PDF recognition within collection (broken by f8b41c9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dstillman committed Mar 1, 2018
1 parent f99038f commit 3cc92fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions chrome/content/zotero/xpcom/recognizePDF.js
Expand Up @@ -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();
}
Expand Down
29 changes: 29 additions & 0 deletions test/tests/recognizePDFTest.js
Expand Up @@ -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));
});
});

0 comments on commit 3cc92fe

Please sign in to comment.