Automatically retrieve metadata when saving PDFs
Applies to dragging to the collections pane or the items pane, adding via New Item menu, or saving via the connector server If the renaming pref is enabled, the PDF is renamed after recognition. Can be disabled in the preferences Closes #917
This commit is contained in:
parent
081793f72f
commit
97661539dc
12 changed files with 192 additions and 32 deletions
|
@ -305,17 +305,36 @@ describe("Connector Server", function () {
|
|||
assert.equal(item.getField('title'), 'Title');
|
||||
});
|
||||
|
||||
it("should save a PDF to the current selected collection", function* () {
|
||||
var collection = yield createDataObject('collection');
|
||||
yield waitForItemsLoad(win);
|
||||
it("should save a PDF to the current selected collection and retrieve metadata", async function () {
|
||||
var collection = await createDataObject('collection');
|
||||
await waitForItemsLoad(win);
|
||||
|
||||
var file = getTestDataDirectory();
|
||||
file.append('test.pdf');
|
||||
httpd.registerFile("/test.pdf", file);
|
||||
|
||||
var ids;
|
||||
var promise = waitForItemEvent('add');
|
||||
yield Zotero.HTTP.request(
|
||||
var recognizerPromise = waitForRecognizer();
|
||||
|
||||
var origRequest = Zotero.HTTP.request.bind(Zotero.HTTP);
|
||||
var called = 0;
|
||||
var stub = sinon.stub(Zotero.HTTP, 'request').callsFake(function (method, url, options) {
|
||||
// Forward saveSnapshot request
|
||||
if (url.endsWith('saveSnapshot')) {
|
||||
return origRequest(...arguments);
|
||||
}
|
||||
|
||||
// Fake recognizer response
|
||||
return Zotero.Promise.resolve({
|
||||
getResponseHeader: () => {},
|
||||
responseText: JSON.stringify({
|
||||
title: 'Test',
|
||||
authors: []
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
await Zotero.HTTP.request(
|
||||
'POST',
|
||||
connectorServerPath + "/connector/saveSnapshot",
|
||||
{
|
||||
|
@ -329,13 +348,20 @@ describe("Connector Server", function () {
|
|||
}
|
||||
);
|
||||
|
||||
var ids = yield promise;
|
||||
var ids = await promise;
|
||||
|
||||
assert.lengthOf(ids, 1);
|
||||
var item = Zotero.Items.get(ids[0]);
|
||||
assert.isTrue(item.isImportedAttachment());
|
||||
assert.equal(item.attachmentContentType, 'application/pdf');
|
||||
assert.isTrue(collection.hasItem(item.id));
|
||||
|
||||
var progressWindow = await recognizerPromise;
|
||||
progressWindow.close();
|
||||
Zotero.RecognizePDF.cancel();
|
||||
assert.isFalse(item.isTopLevelItem());
|
||||
|
||||
stub.restore();
|
||||
});
|
||||
|
||||
it("should respond with 500 if a read-only library is selected", function* () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue