2016-12-17 08:01:25 -05:00
|
|
|
describe("PDF Recognition", function() {
|
2015-03-08 15:59:53 -04:00
|
|
|
var win;
|
2016-05-27 01:30:03 -04:00
|
|
|
|
|
|
|
before(function* () {
|
2016-12-18 09:18:57 -05:00
|
|
|
if (Zotero.automatedTest) this.skip(); // TODO: Mock services
|
|
|
|
|
2015-03-08 15:59:53 -04:00
|
|
|
this.timeout(60000);
|
2016-05-27 01:30:03 -04: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 15:59:53 -04:00
|
|
|
});
|
2016-05-27 01:30:03 -04:00
|
|
|
|
2015-03-08 18:40:29 -04:00
|
|
|
afterEach(function() {
|
|
|
|
for(let win of getWindows("chrome://zotero/content/pdfProgress.xul")) {
|
|
|
|
win.close();
|
|
|
|
}
|
|
|
|
});
|
2016-05-27 01:30:03 -04:00
|
|
|
|
2015-03-08 15:59:53 -04:00
|
|
|
after(function() {
|
2016-12-21 05:28:48 -05:00
|
|
|
if (win) {
|
|
|
|
win.close();
|
|
|
|
}
|
2015-03-08 15:59:53 -04:00
|
|
|
});
|
|
|
|
|
2016-05-27 01:30:03 -04:00
|
|
|
it("should recognize a PDF with a DOI within a collection", function* () {
|
2015-03-08 15:59:53 -04:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
|
|
|
testdir.append("recognizePDF_test_DOI.pdf");
|
2016-05-27 01:30:03 -04:00
|
|
|
|
|
|
|
var col = yield createDataObject('collection');
|
|
|
|
yield waitForItemsLoad(win);
|
|
|
|
|
|
|
|
var attachment = yield Zotero.Attachments.importFromFile({
|
|
|
|
file: testdir,
|
|
|
|
collections: [col.id]
|
2015-05-23 04:25:47 -04:00
|
|
|
});
|
2015-03-08 15:59:53 -04:00
|
|
|
|
|
|
|
// Recognize the PDF
|
|
|
|
win.Zotero_RecognizePDF.recognizeSelected();
|
|
|
|
|
2016-05-27 01:30:03 -04: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 15:59:53 -04:00
|
|
|
});
|
2015-03-08 16:20:57 -04:00
|
|
|
|
2015-05-23 04:25:47 -04:00
|
|
|
it("should recognize a PDF without a DOI", function* () {
|
2015-03-08 16:20:57 -04:00
|
|
|
this.timeout(30000);
|
|
|
|
// Import the PDF
|
|
|
|
var testdir = getTestDataDirectory();
|
|
|
|
testdir.append("recognizePDF_test_GS.pdf");
|
2015-05-29 05:31:54 -04:00
|
|
|
var item = yield Zotero.Attachments.importFromFile({
|
2015-05-23 04:25:47 -04:00
|
|
|
file: testdir
|
|
|
|
});
|
2016-05-27 01:30:03 -04:00
|
|
|
|
2015-03-08 16:20:57 -04:00
|
|
|
// Recognize the PDF
|
|
|
|
win.Zotero_RecognizePDF.recognizeSelected();
|
|
|
|
|
2016-12-17 08:01:25 -05: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 01:30:03 -04: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 08:01:25 -05: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 16:20:57 -04:00
|
|
|
});
|
2015-03-08 15:59:53 -04:00
|
|
|
});
|