Fix Zotero.Attachments.linkFromDocument()
This commit is contained in:
parent
e137a05201
commit
ad0d6765d7
|
@ -510,28 +510,23 @@ Zotero.Attachments = new function(){
|
||||||
var title = document.title; // TODO: don't use Mozilla-generated title for images, etc.
|
var title = document.title; // TODO: don't use Mozilla-generated title for images, etc.
|
||||||
var contentType = document.contentType;
|
var contentType = document.contentType;
|
||||||
|
|
||||||
var item = yield Zotero.DB.executeTransaction(function* () {
|
var item = yield _addToDB({
|
||||||
return _addToDB({
|
url,
|
||||||
url: url,
|
title,
|
||||||
title: title,
|
|
||||||
linkMode: this.LINK_MODE_LINKED_URL,
|
linkMode: this.LINK_MODE_LINKED_URL,
|
||||||
contentType: contentType,
|
contentType,
|
||||||
charset: document.characterSet,
|
charset: document.characterSet,
|
||||||
parentItemID: parentItemID,
|
parentItemID,
|
||||||
collections: collections
|
collections
|
||||||
});
|
});
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
// Run the indexer asynchronously
|
|
||||||
setTimeout(function () {
|
|
||||||
if (Zotero.Fulltext.isCachedMIMEType(contentType)) {
|
if (Zotero.Fulltext.isCachedMIMEType(contentType)) {
|
||||||
// No file, so no point running the PDF indexer
|
// No file, so no point running the PDF indexer
|
||||||
//Zotero.Fulltext.indexItems([itemID]);
|
//Zotero.Fulltext.indexItems([itemID]);
|
||||||
}
|
}
|
||||||
else if (Zotero.MIME.isTextType(document.contentType)) {
|
else if (Zotero.MIME.isTextType(document.contentType)) {
|
||||||
Zotero.Fulltext.indexDocument(document, item.id);
|
yield Zotero.Fulltext.indexDocument(document, item.id);
|
||||||
}
|
}
|
||||||
}, 50);
|
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
|
|
|
@ -112,6 +112,32 @@ describe("Zotero.Attachments", function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("#linkFromDocument", function () {
|
||||||
|
it("should add a link attachment for the current webpage", function* () {
|
||||||
|
var item = yield createDataObject('item');
|
||||||
|
|
||||||
|
var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html");
|
||||||
|
var deferred = Zotero.Promise.defer();
|
||||||
|
win.addEventListener('pageshow', () => deferred.resolve());
|
||||||
|
win.loadURI(uri);
|
||||||
|
yield deferred.promise;
|
||||||
|
|
||||||
|
var file = getTestDataDirectory();
|
||||||
|
file.append('test.png');
|
||||||
|
var attachment = yield Zotero.Attachments.linkFromDocument({
|
||||||
|
document: win.content.document,
|
||||||
|
parentItemID: item.id
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.equal(attachment.getField('url'), "file://" + uri);
|
||||||
|
|
||||||
|
// Check indexing
|
||||||
|
var matches = yield Zotero.Fulltext.findTextInItems([attachment.id], 'works');
|
||||||
|
assert.lengthOf(matches, 1);
|
||||||
|
assert.propertyVal(matches[0], 'id', attachment.id);
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("#getTotalFileSize", function () {
|
describe("#getTotalFileSize", function () {
|
||||||
it("should return the size for a single-file attachment", function* () {
|
it("should return the size for a single-file attachment", function* () {
|
||||||
var file = getTestDataDirectory();
|
var file = getTestDataDirectory();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user