diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 2881f4605a..aafaa99742 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -634,7 +634,7 @@ Zotero.Attachments = new function(){ attachmentItem.attachmentLinkMode = Zotero.Attachments.LINK_MODE_IMPORTED_URL; attachmentItem.attachmentCharset = 'utf-8'; // WPD will output UTF-8 attachmentItem.attachmentContentType = contentType; - if (collections) { + if (collections && collections.length) { attachmentItem.setCollections(collections); } var itemID = yield attachmentItem.save(); @@ -861,11 +861,9 @@ Zotero.Attachments = new function(){ this.createTemporaryStorageDirectory = Zotero.Promise.coroutine(function* () { var tmpDir = Zotero.getStorageDirectory(); tmpDir.append("tmp-" + Zotero.Utilities.randomString(6)); - Zotero.debug("RANDOM IS " + tmpDir.leafName); yield OS.File.makeDir(tmpDir.path, { unixMode: 0755 }); - Zotero.debug("MADE DIRECTORY at " + tmpDir.path); return tmpDir; }); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 5bef9a5adc..ead6cb1456 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -3405,7 +3405,7 @@ var ZoteroPane = new function() let item = yield Zotero.Attachments.importFromDocument({ libraryID: libraryID, document: doc, - collections: [collectionID] + collections: collectionID ? [collectionID] : [] }); yield this.selectItem(item.id); diff --git a/test/content/support.js b/test/content/support.js index d9d9ddb35b..3ca4e01938 100644 --- a/test/content/support.js +++ b/test/content/support.js @@ -42,7 +42,9 @@ function loadBrowserWindow() { } /** - * Loads a Zotero pane in a new window and selects My Library. Returns the containing window. + * Opens the Zotero pane and selects My Library. Returns the containing window. + * + * @param {Window} [win] - Existing window to use; if not specified, a new window is opened */ var loadZoteroPane = Zotero.Promise.coroutine(function* (win) { if (!win) { diff --git a/test/tests/browserTest.js b/test/tests/browserTest.js index 7e409db08d..683e2782e2 100644 --- a/test/tests/browserTest.js +++ b/test/tests/browserTest.js @@ -55,6 +55,45 @@ describe("Zotero_Browser", function () { assert.isTrue(collection.hasItem(items[0].id)); }) + it("should save PDF to library root", function* () { + var uri = OS.Path.join(getTestDataDirectory().path, "test.pdf"); + var deferred = Zotero.Promise.defer(); + win.addEventListener('pageshow', () => deferred.resolve()); + win.loadURI(uri); + yield deferred.promise; + + yield loadZoteroPane(win); + + var promise = waitForItemEvent('add'); + yield win.Zotero_Browser.scrapeThisPage(); + var ids = yield promise; + var items = Zotero.Items.get(ids); + assert.lengthOf(items, 1); + assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'attachment'); + assert.equal(items[0].getField('title'), 'test.pdf'); + assert.equal(items[0].attachmentContentType, 'application/pdf'); + assert.equal(Zotero.Attachments.linkModeToName(items[0].attachmentLinkMode), 'imported_url'); + }); + + it("should save PDF to current collection", function* () { + var uri = OS.Path.join(getTestDataDirectory().path, "test.pdf"); + var deferred = Zotero.Promise.defer(); + win.addEventListener('pageshow', () => deferred.resolve()); + win.loadURI(uri); + yield deferred.promise; + + yield loadZoteroPane(win); + var collection = yield createDataObject('collection'); + + var promise = waitForItemEvent('add'); + yield win.Zotero_Browser.scrapeThisPage(); + var ids = yield promise; + var items = Zotero.Items.get(ids); + assert.lengthOf(items, 1); + assert.equal(Zotero.ItemTypes.getName(items[0].itemTypeID), 'attachment'); + assert.isTrue(collection.hasItem(items[0].id)); + }); + it("shouldn't save webpage to My Publications", function* () { var uri = OS.Path.join(getTestDataDirectory().path, "snapshot", "index.html"); var deferred = Zotero.Promise.defer();