daf4a8fe4d
While trying to get translation and citing working with asynchronously generated data, we realized that drag-and-drop support was going to be...problematic. Firefox only supports synchronous methods for providing drag data (unlike, it seems, the DataTransferItem interface supported by Chrome), which means that we'd need to preload all relevant data on item selection (bounded by export.quickCopy.dragLimit) and keep the translate/cite methods synchronous (or maintain two separate versions). What we're trying instead is doing what I said in #518 we weren't going to do: loading most object data on startup and leaving many more functions synchronous. Essentially, this takes the various load*() methods described in #518, moves them to startup, and makes them operate on entire libraries rather than individual objects. The obvious downside here (other than undoing much of the work of the last many months) is that it increases startup time, potentially quite a lot for larger libraries. On my laptop, with a 3,000-item library, this adds about 3 seconds to startup time. I haven't yet tested with larger libraries. But I'm hoping that we can optimize this further to reduce that delay. Among other things, this is loading data for all libraries, when it should be able to load data only for the library being viewed. But this is also fundamentally just doing some SELECT queries and storing the results, so it really shouldn't need to be that slow (though performance may be bounded a bit here by XPCOM overhead). If we can make this fast enough, it means that third-party plugins should be able to remain much closer to their current designs. (Some things, including saving, will still need to be made asynchronous.)
41 lines
No EOL
1.7 KiB
JavaScript
41 lines
No EOL
1.7 KiB
JavaScript
describe("Zotero_File_Interface", function() {
|
|
let win;
|
|
before(function* () {
|
|
win = yield loadZoteroPane();
|
|
yield OS.File.copy(OS.Path.join(getTestDataDirectory().path, "Test Import Translator.js"),
|
|
OS.Path.join(Zotero.getTranslatorsDirectory().path, "Test Import Translator.js"));
|
|
yield Zotero.Translators.reinit();
|
|
});
|
|
after(function () {
|
|
win.close();
|
|
});
|
|
|
|
it('should import a file into a collection', function* () {
|
|
this.timeout(10000);
|
|
let testFile = getTestDataDirectory();
|
|
testFile.append("allTypesAndFields.js");
|
|
yield win.Zotero_File_Interface.importFile(testFile);
|
|
|
|
let importedCollection = yield Zotero.Collections.getByLibrary(Zotero.Libraries.userLibraryID).filter(x => x.name == 'allTypesAndFields');
|
|
assert.equal(importedCollection.length, 1);
|
|
let childItems = importedCollection[0].getChildItems();
|
|
let savedItems = {};
|
|
for (let i=0; i<childItems.length; i++) {
|
|
let savedItem = childItems[i].toJSON();
|
|
delete savedItem.dateAdded;
|
|
delete savedItem.dateModified;
|
|
delete savedItem.key;
|
|
delete savedItem.collections;
|
|
savedItems[Zotero.ItemTypes.getName(childItems[i].itemTypeID)] = savedItem;
|
|
}
|
|
let trueItems = loadSampleData('itemJSON');
|
|
for (let itemType in trueItems) {
|
|
let trueItem = trueItems[itemType];
|
|
delete trueItem.dateAdded;
|
|
delete trueItem.dateModified;
|
|
delete trueItem.key;
|
|
delete trueItem.collections;
|
|
}
|
|
assert.deepEqual(savedItems, trueItems, "saved items match inputs")
|
|
});
|
|
}); |