www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 20ece48a57753e76a9dea6cf95150a3d32de0392
parent ea1486f62f00bd5969031b7bbc5f09123233a3d4
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon, 21 Mar 2016 01:30:16 -0400

Fix saving of single files to library root via save button

Diffstat:
Mchrome/content/zotero/xpcom/attachments.js | 4+---
Mchrome/content/zotero/zoteroPane.js | 2+-
Mtest/content/support.js | 4+++-
Mtest/tests/browserTest.js | 39+++++++++++++++++++++++++++++++++++++++
4 files changed, 44 insertions(+), 5 deletions(-)

diff --git 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 @@ -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 @@ -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 @@ -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();