Return a Zotero.Item from all Zotero.Attachments methods

These previously returned an itemID, but now that new saved items can be edited
without a refetch, they should just return the new item.

(Possible I missed a few spots where these are called.)
This commit is contained in:
Dan Stillman 2015-05-29 05:31:54 -04:00
parent 5a2ec43de1
commit 2154673dd3
7 changed files with 43 additions and 54 deletions

View file

@ -27,16 +27,15 @@ describe("Zotero.Attachments", function() {
var parentItemID = yield item.saveTx();
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile({
var item = yield Zotero.Attachments.importFromFile({
file: tmpFile,
parentItemID: 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);
yield Zotero.Items.erase(item.id);
});
it("should create a top-level attachment from a PNG file", function* () {
@ -45,15 +44,14 @@ describe("Zotero.Attachments", function() {
var contents = yield Zotero.File.getBinaryContentsAsync(file);
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile({
var item = yield Zotero.Attachments.importFromFile({
file: file
});
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);
yield Zotero.Items.erase(item.id);
});
it("should create a top-level attachment from a PNG file in a collection", function* () {
@ -64,16 +62,15 @@ describe("Zotero.Attachments", function() {
var collection = yield createDataObject('collection');
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile({
var item = yield Zotero.Attachments.importFromFile({
file: file,
collections: [collection.id]
});
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);
yield Zotero.Items.erase(item.id);
});
it("should create a child attachment from a PNG file", function* () {
@ -86,16 +83,15 @@ describe("Zotero.Attachments", function() {
var parentItemID = yield item.saveTx();
// Create attachment and compare content
var itemID = yield Zotero.Attachments.importFromFile({
var item = yield Zotero.Attachments.importFromFile({
file: file,
parentItemID: 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);
yield Zotero.Items.erase(item.id);
});
})

View file

@ -236,7 +236,7 @@ describe("Zotero.CollectionTreeView", function() {
});
var file = getTestDataDirectory();
file.append('test.png');
var attachmentID = yield Zotero.Attachments.importFromFile({
yield Zotero.Attachments.importFromFile({
file: file,
parentItemID: item.id
});

View file

@ -24,12 +24,12 @@ describe.skip("PDF Recognition", function() {
// Import the PDF
var testdir = getTestDataDirectory();
testdir.append("recognizePDF_test_DOI.pdf");
var id = yield Zotero.Attachments.importFromFile({
var item = yield Zotero.Attachments.importFromFile({
file: testdir
});
// Recognize the PDF
win.ZoteroPane.selectItem(id);
win.ZoteroPane.selectItem(item.id);
win.Zotero_RecognizePDF.recognizeSelected();
return waitForItemEvent("add").then(function(ids) {
@ -46,12 +46,12 @@ describe.skip("PDF Recognition", function() {
// Import the PDF
var testdir = getTestDataDirectory();
testdir.append("recognizePDF_test_GS.pdf");
var id = yield Zotero.Attachments.importFromFile({
var item = yield Zotero.Attachments.importFromFile({
file: testdir
});
// Recognize the PDF
win.ZoteroPane.selectItem(id);
win.ZoteroPane.selectItem(item.id);
win.Zotero_RecognizePDF.recognizeSelected();
return waitForItemEvent("add").then(function(ids) {