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([
|
|
|
|
loadZoteroPane().then(w => win = w),
|
|
|
|
installPDFTools(),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
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() {
|
|
|
|
for(let win of getWindows("chrome://zotero/content/pdfProgress.xul")) {
|
|
|
|
win.close();
|
|
|
|
}
|
|
|
|
});
|
2016-05-27 05:30:03 +00:00
|
|
|
|
2015-03-08 19:59:53 +00:00
|
|
|
after(function() {
|
|
|
|
win.close();
|
|
|
|
});
|
|
|
|
|
2016-05-27 05:30:03 +00:00
|
|
|
it("should recognize a PDF with a DOI within a collection", function* () {
|
2015-03-08 19:59:53 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
|
|
|
testdir.append("recognizePDF_test_DOI.pdf");
|
2016-05-27 05:30:03 +00:00
|
|
|
|
|
|
|
var col = yield createDataObject('collection');
|
|
|
|
yield waitForItemsLoad(win);
|
|
|
|
|
|
|
|
var attachment = yield Zotero.Attachments.importFromFile({
|
|
|
|
file: testdir,
|
|
|
|
collections: [col.id]
|
2015-05-23 08:25:47 +00:00
|
|
|
});
|
2015-03-08 19:59:53 +00:00
|
|
|
|
|
|
|
// Recognize the PDF
|
|
|
|
win.Zotero_RecognizePDF.recognizeSelected();
|
|
|
|
|
2016-05-27 05:30:03 +00:00
|
|
|
var ids = yield waitForItemEvent("add");
|
|
|
|
yield waitForNotifierEvent('add', 'collection-item')
|
|
|
|
|
|
|
|
var item = Zotero.Items.get(ids[0]);
|
|
|
|
assert.equal(item.getField("title"), "Shaping the Research Agenda");
|
|
|
|
assert.equal(item.getField("libraryCatalog"), "CrossRef");
|
|
|
|
assert.equal(attachment.parentID, item.id);
|
|
|
|
assert.isTrue(col.hasItem(item.id));
|
2015-03-08 19:59:53 +00:00
|
|
|
});
|
2015-03-08 20:20:57 +00:00
|
|
|
|
2015-05-23 08:25:47 +00:00
|
|
|
it("should recognize a PDF without a DOI", function* () {
|
2016-12-17 13:01:25 +00:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock
|
2015-03-31 04:52:38 +00:00
|
|
|
|
2015-03-08 20:20:57 +00:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
|
|
|
testdir.append("recognizePDF_test_GS.pdf");
|
2015-05-29 09:31:54 +00:00
|
|
|
var item = yield 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
|
|
|
|
win.Zotero_RecognizePDF.recognizeSelected();
|
|
|
|
|
2016-12-17 13:01:25 +00:00
|
|
|
var addedIDs = yield waitForItemEvent("add");
|
|
|
|
var modifiedIDs = yield waitForItemEvent("modify");
|
|
|
|
assert.lengthOf(addedIDs, 1);
|
|
|
|
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");
|
|
|
|
assert.equal(item.getField("libraryCatalog"), "Google Scholar");
|
2016-12-17 13:01:25 +00:00
|
|
|
assert.lengthOf(modifiedIDs, 2);
|
|
|
|
|
|
|
|
yield Zotero.Promise.delay(0);
|
|
|
|
|
|
|
|
var progressWindow = getWindows("chrome://zotero/content/pdfProgress.xul")[0];
|
|
|
|
assert.equal(
|
|
|
|
progressWindow.document.getElementById("label").value,
|
|
|
|
Zotero.getString("recognizePDF.complete.label")
|
|
|
|
);
|
2015-03-08 20:20:57 +00:00
|
|
|
});
|
2015-03-08 19:59:53 +00:00
|
|
|
});
|