2016-12-17 13:01:25 +00:00
|
|
|
describe("PDF Recognition", function() {
|
2015-03-08 19:59:53 +00:00
|
|
|
var win;
|
2016-05-27 05:30:03 +00:00
|
|
|
|
|
|
|
before(function* () {
|
2015-03-08 19:59:53 +00:00
|
|
|
this.timeout(60000);
|
2016-05-27 05:30:03 +00:00
|
|
|
// Load Zotero pane and install PDF tools
|
|
|
|
yield Zotero.Promise.all([
|
2018-01-15 17:09:38 +00:00
|
|
|
loadZoteroPane().then(w => win = w)
|
2016-05-27 05:30:03 +00:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function* () {
|
|
|
|
yield selectLibrary(win);
|
2015-03-08 19:59:53 +00:00
|
|
|
});
|
2016-05-27 05:30:03 +00:00
|
|
|
|
2015-03-08 22:40:29 +00:00
|
|
|
afterEach(function() {
|
2022-05-24 19:52:38 +00:00
|
|
|
for(let win of getWindows("chrome://zotero/content/progressQueueDialog.xhtml")) {
|
2015-03-08 22:40:29 +00:00
|
|
|
win.close();
|
|
|
|
}
|
2018-10-05 05:56:46 +00:00
|
|
|
Zotero.ProgressQueues.get('recognize').cancel();
|
2019-03-27 10:35:58 +00:00
|
|
|
Zotero.RecognizePDF.recognizeStub = null;
|
|
|
|
Zotero.Prefs.clear('autoRenameFiles.linked');
|
2015-03-08 22:40:29 +00:00
|
|
|
});
|
2016-05-27 05:30:03 +00:00
|
|
|
|
2015-03-08 19:59:53 +00:00
|
|
|
after(function() {
|
2016-12-21 10:28:48 +00:00
|
|
|
if (win) {
|
|
|
|
win.close();
|
|
|
|
}
|
2015-03-08 19:59:53 +00:00
|
|
|
});
|
2018-05-04 05:16:04 +00:00
|
|
|
|
2019-03-27 10:35:58 +00:00
|
|
|
it("should recognize a PDF by DOI and rename the file", async function () {
|
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
2018-05-04 07:14:26 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
|
|
|
testdir.append("recognizePDF_test_DOI.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.equal(item.getField("title"), "Shaping the Research Agenda");
|
2019-05-26 10:45:46 +00:00
|
|
|
assert.equal(item.getField("libraryCatalog"), "DOI.org (Crossref)");
|
2018-05-04 07:14:26 +00:00
|
|
|
assert.lengthOf(modifiedIDs, 2);
|
|
|
|
|
|
|
|
// Wait for status to show as complete
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2018-10-05 05:56:46 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
2018-05-04 07:14:26 +00:00
|
|
|
while (progressWindow.document.getElementById("label").value != completeStr) {
|
|
|
|
await Zotero.Promise.delay(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The file should have been renamed
|
|
|
|
assert.equal(
|
|
|
|
attachment.attachmentFilename,
|
|
|
|
Zotero.Attachments.getFileBaseNameFromItem(item) + '.pdf'
|
|
|
|
);
|
|
|
|
});
|
2018-05-04 05:16:04 +00:00
|
|
|
|
|
|
|
it("should recognize a PDF by arXiv ID", async function () {
|
2019-03-27 10:35:58 +00:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
2015-03-08 20:20:57 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
2018-05-04 05:16:04 +00:00
|
|
|
testdir.append("recognizePDF_test_arXiv.pdf");
|
2018-02-27 06:40:07 +00:00
|
|
|
var attachment = await Zotero.Attachments.importFromFile({
|
2015-05-23 08:25:47 +00:00
|
|
|
file: testdir
|
|
|
|
});
|
2016-05-27 05:30:03 +00:00
|
|
|
|
2015-03-08 20:20:57 +00:00
|
|
|
// Recognize the PDF
|
2018-01-20 08:45:00 +00:00
|
|
|
win.ZoteroPane.recognizeSelected();
|
|
|
|
|
2018-02-27 06:40:07 +00:00
|
|
|
var addedIDs = await waitForItemEvent("add");
|
|
|
|
var modifiedIDs = await waitForItemEvent("modify");
|
2018-05-04 05:16:04 +00:00
|
|
|
// Item and note
|
|
|
|
assert.lengthOf(addedIDs, 2);
|
2016-12-17 13:01:25 +00:00
|
|
|
var item = Zotero.Items.get(addedIDs[0]);
|
2016-05-27 05:30:03 +00:00
|
|
|
assert.equal(item.getField("title"), "Scaling study of an improved fermion action on quenched lattices");
|
2018-05-04 05:16:04 +00:00
|
|
|
assert.lengthOf(modifiedIDs, 1);
|
2016-12-17 13:01:25 +00:00
|
|
|
|
2018-02-27 06:40:07 +00:00
|
|
|
// Wait for status to show as complete
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2018-10-05 05:56:46 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
2018-02-27 06:40:07 +00:00
|
|
|
while (progressWindow.document.getElementById("label").value != completeStr) {
|
|
|
|
await Zotero.Promise.delay(20);
|
|
|
|
}
|
2015-03-08 20:20:57 +00:00
|
|
|
});
|
2018-02-28 22:34:06 +00:00
|
|
|
|
|
|
|
it("should put new item in same collection", async function () {
|
2019-03-27 10:35:58 +00:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
2018-02-28 22:34:06 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
2018-05-04 05:16:04 +00:00
|
|
|
testdir.append("recognizePDF_test_arXiv.pdf");
|
2018-02-28 22:34:06 +00:00
|
|
|
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");
|
2018-05-04 05:16:04 +00:00
|
|
|
// Item and note
|
|
|
|
assert.lengthOf(addedIDs, 2);
|
2018-02-28 22:34:06 +00:00
|
|
|
var item = Zotero.Items.get(addedIDs[0]);
|
2018-05-04 05:16:04 +00:00
|
|
|
assert.lengthOf(modifiedIDs, 1);
|
2018-02-28 22:34:06 +00:00
|
|
|
|
|
|
|
// Wait for status to show as complete
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2018-10-05 05:56:46 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
2018-02-28 22:34:06 +00:00
|
|
|
while (progressWindow.document.getElementById("label").value != completeStr) {
|
|
|
|
await Zotero.Promise.delay(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.isTrue(collection.hasItem(item.id));
|
|
|
|
});
|
2018-04-02 19:34:22 +00:00
|
|
|
|
2018-05-04 05:16:04 +00:00
|
|
|
it("should recognize PDF by arXiv ID and put new item in same collection in group library", async function () {
|
2019-03-27 10:35:58 +00:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
2018-04-02 19:34:22 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
var testdir = getTestDataDirectory();
|
2018-05-04 05:16:04 +00:00
|
|
|
testdir.append("recognizePDF_test_arXiv.pdf");
|
2018-04-02 19:34:22 +00:00
|
|
|
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");
|
2018-05-04 05:16:04 +00:00
|
|
|
// Item and note
|
|
|
|
assert.lengthOf(addedIDs, 2);
|
2018-04-02 19:34:22 +00:00
|
|
|
var item = Zotero.Items.get(addedIDs[0]);
|
2018-05-04 05:16:04 +00:00
|
|
|
assert.lengthOf(modifiedIDs, 1);
|
2018-04-02 19:34:22 +00:00
|
|
|
|
|
|
|
// Wait for status to show as complete
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2018-10-05 05:56:46 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
2018-04-02 19:34:22 +00:00
|
|
|
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 () {
|
2019-03-27 10:35:58 +00:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
2018-04-02 19:34:22 +00:00
|
|
|
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
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2018-10-05 05:56:46 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
2018-04-02 19:34:22 +00:00
|
|
|
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 () {
|
2019-03-27 10:35:58 +00:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
2018-04-02 19:34:22 +00:00
|
|
|
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
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2018-10-05 05:56:46 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
2018-04-02 19:34:22 +00:00
|
|
|
while (progressWindow.document.getElementById("label").value != completeStr) {
|
|
|
|
await Zotero.Promise.delay(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.isTrue(collection.hasItem(item.id));
|
|
|
|
});
|
2019-03-27 10:35:58 +00:00
|
|
|
|
|
|
|
it("should rename a linked file attachment using parent metadata if no existing file attachments and pref enabled", async function () {
|
|
|
|
Zotero.Prefs.set('autoRenameFiles.linked', true);
|
|
|
|
var itemTitle = Zotero.Utilities.randomString();;
|
|
|
|
Zotero.RecognizePDF.recognizeStub = async function () {
|
|
|
|
return createDataObject('item', { title: itemTitle });
|
|
|
|
};
|
|
|
|
|
|
|
|
// Link to the PDF
|
|
|
|
var tempDir = await getTempDirectory();
|
|
|
|
var tempFile = OS.Path.join(tempDir, 'test.pdf');
|
|
|
|
await OS.File.copy(OS.Path.join(getTestDataDirectory().path, 'test.pdf'), tempFile);
|
|
|
|
var attachment = await Zotero.Attachments.linkFromFile({
|
|
|
|
file: tempFile
|
|
|
|
});
|
|
|
|
|
|
|
|
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.equal(item.getField("title"), itemTitle);
|
|
|
|
assert.lengthOf(modifiedIDs, 2);
|
|
|
|
|
|
|
|
// Wait for status to show as complete
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2019-03-27 10:35:58 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
|
|
|
while (progressWindow.document.getElementById("label").value != completeStr) {
|
|
|
|
await Zotero.Promise.delay(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The file should have been renamed
|
|
|
|
assert.equal(
|
|
|
|
attachment.attachmentFilename,
|
|
|
|
Zotero.Attachments.getFileBaseNameFromItem(item) + '.pdf'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("shouldn't rename a linked file attachment using parent metadata if pref disabled", async function () {
|
|
|
|
Zotero.Prefs.set('autoRenameFiles.linked', false);
|
|
|
|
var itemTitle = Zotero.Utilities.randomString();;
|
|
|
|
Zotero.RecognizePDF.recognizeStub = async function () {
|
|
|
|
return createDataObject('item', { title: itemTitle });
|
|
|
|
};
|
|
|
|
|
|
|
|
// Link to the PDF
|
|
|
|
var tempDir = await getTempDirectory();
|
|
|
|
var tempFile = OS.Path.join(tempDir, 'test.pdf');
|
|
|
|
await OS.File.copy(OS.Path.join(getTestDataDirectory().path, 'test.pdf'), tempFile);
|
|
|
|
var attachment = await Zotero.Attachments.linkFromFile({
|
|
|
|
file: tempFile
|
|
|
|
});
|
|
|
|
|
|
|
|
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.equal(item.getField("title"), itemTitle);
|
|
|
|
assert.lengthOf(modifiedIDs, 2);
|
|
|
|
|
|
|
|
// Wait for status to show as complete
|
2022-05-24 19:52:38 +00:00
|
|
|
var progressWindow = getWindows("chrome://zotero/content/progressQueueDialog.xhtml")[0];
|
2019-03-27 10:35:58 +00:00
|
|
|
var completeStr = Zotero.getString("general.finished");
|
|
|
|
while (progressWindow.document.getElementById("label").value != completeStr) {
|
|
|
|
await Zotero.Promise.delay(20);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The file should not have been renamed
|
|
|
|
assert.equal(attachment.attachmentFilename, 'test.pdf');
|
|
|
|
});
|
2015-03-08 19:59:53 +00:00
|
|
|
});
|