Always return promise from Zotero.Attachments._postProcessFile()
This commit is contained in:
parent
1179d4c142
commit
0471a393eb
|
@ -1327,7 +1327,7 @@ Zotero.Attachments = new function(){
|
||||||
*
|
*
|
||||||
* @return {Promise}
|
* @return {Promise}
|
||||||
*/
|
*/
|
||||||
function _postProcessFile(itemID, file, contentType){
|
var _postProcessFile = Zotero.Promise.coroutine(function* (itemID, file, contentType) {
|
||||||
// Don't try to process if MIME type is unknown
|
// Don't try to process if MIME type is unknown
|
||||||
if (!contentType) {
|
if (!contentType) {
|
||||||
return;
|
return;
|
||||||
|
@ -1387,7 +1387,7 @@ Zotero.Attachments = new function(){
|
||||||
browser.loadURI(url);
|
browser.loadURI(url);
|
||||||
|
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if a given document is an instance of PDFJS
|
* Determines if a given document is an instance of PDFJS
|
||||||
|
|
58
test/tests/attachmentsTest.js
Normal file
58
test/tests/attachmentsTest.js
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
describe("Zotero.Attachments", function() {
|
||||||
|
var win;
|
||||||
|
|
||||||
|
before(function () {
|
||||||
|
// Hidden browser, which requires a browser window, needed for charset detection
|
||||||
|
// (until we figure out a better way)
|
||||||
|
if (!Zotero.isStandalone) {
|
||||||
|
return loadBrowserWindow().then(window => win = window);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
after(function () {
|
||||||
|
if (win) {
|
||||||
|
win.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#importFromFile()", function () {
|
||||||
|
it("should create a child attachment from a text file", function* () {
|
||||||
|
// Create test file
|
||||||
|
var contents = "Test";
|
||||||
|
var tmpFile = Zotero.getTempDirectory();
|
||||||
|
tmpFile.append('test.txt');
|
||||||
|
yield Zotero.File.putContentsAsync(tmpFile, contents);
|
||||||
|
|
||||||
|
// Create parent item
|
||||||
|
var item = new Zotero.Item('book');
|
||||||
|
var parentItemID = yield item.save();
|
||||||
|
|
||||||
|
// Create attachment and compare content
|
||||||
|
var itemID = yield Zotero.Attachments.importFromFile(tmpFile, parentItemID);
|
||||||
|
var item = yield Zotero.Items.getAsync(itemID);
|
||||||
|
var storedFile = item.getFile();
|
||||||
|
assert.equal((yield Zotero.File.getContentsAsync(storedFile)), contents);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
yield Zotero.Items.erase(itemID);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should create a child attachment from a PNG file", function* () {
|
||||||
|
var file = getTestDataDirectory();
|
||||||
|
file.append('test.png');
|
||||||
|
var contents = yield Zotero.File.getBinaryContentsAsync(file);
|
||||||
|
|
||||||
|
// Create parent item
|
||||||
|
var item = new Zotero.Item('book');
|
||||||
|
var parentItemID = yield item.save();
|
||||||
|
|
||||||
|
// Create attachment and compare content
|
||||||
|
var itemID = yield Zotero.Attachments.importFromFile(file, parentItemID);
|
||||||
|
var item = yield Zotero.Items.getAsync(itemID);
|
||||||
|
var storedFile = item.getFile();
|
||||||
|
assert.equal((yield Zotero.File.getBinaryContentsAsync(storedFile)), contents);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
yield Zotero.Items.erase(itemID);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user