Fix saving of single files to library root via save button

This commit is contained in:
Dan Stillman 2016-03-21 01:30:16 -04:00
parent ea1486f62f
commit 20ece48a57
4 changed files with 44 additions and 5 deletions

View file

@ -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) {

View file

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