Add fileInterface test for importing into selected collection

And update importFile() calls in tests to use current signature
This commit is contained in:
Dan Stillman 2020-06-25 01:59:57 -04:00
parent 71af747df0
commit abadbb2d77

View file

@ -10,11 +10,13 @@ describe("Zotero_File_Interface", function() {
win.close(); win.close();
}); });
it('should import a file into a collection', function* () { it('should import all types and fields into a new collection', async function () {
this.timeout(10000); this.timeout(10000);
let testFile = getTestDataDirectory(); let testFile = getTestDataDirectory();
testFile.append("allTypesAndFields.js"); testFile.append("allTypesAndFields.js");
yield win.Zotero_File_Interface.importFile(testFile); await win.Zotero_File_Interface.importFile({
file: testFile
});
let importedCollection = Zotero.Collections.getByLibrary( let importedCollection = Zotero.Collections.getByLibrary(
Zotero.Libraries.userLibraryID Zotero.Libraries.userLibraryID
@ -38,9 +40,27 @@ describe("Zotero_File_Interface", function() {
delete trueItem.key; delete trueItem.key;
delete trueItem.collections; delete trueItem.collections;
} }
assert.deepEqual(savedItems, trueItems, "saved items match inputs") assert.deepEqual(savedItems, trueItems, "saved items match inputs");
}); });
it("should import RIS into selected collection", async function () {
var collection = await createDataObject('collection');
var testFile = OS.Path.join(getTestDataDirectory().path, 'book_and_child_note.ris');
await win.Zotero_File_Interface.importFile({
file: testFile,
createNewCollection: false
});
var items = collection.getChildItems();
assert.lengthOf(items, 1);
var childNotes = items[0].getNotes();
assert.lengthOf(childNotes, 1);
assert.equal(Zotero.Items.get(childNotes[0]).getNote(), '<p>Child</p>');
});
it('should import an item and snapshot from Zotero RDF', function* () { it('should import an item and snapshot from Zotero RDF', function* () {
var tmpDir = yield getTempDirectory(); var tmpDir = yield getTempDirectory();
var rdfFile = OS.Path.join(tmpDir, 'test.rdf'); var rdfFile = OS.Path.join(tmpDir, 'test.rdf');
@ -53,7 +73,9 @@ describe("Zotero_File_Interface", function() {
); );
var promise = waitForItemEvent('add'); var promise = waitForItemEvent('add');
yield win.Zotero_File_Interface.importFile(Zotero.File.pathToFile(rdfFile)) yield win.Zotero_File_Interface.importFile({
file: rdfFile
});
var ids = yield promise; var ids = yield promise;
// Notifications are batched // Notifications are batched
assert.lengthOf(ids, 2); assert.lengthOf(ids, 2);
@ -78,7 +100,9 @@ describe("Zotero_File_Interface", function() {
var modsFile = OS.Path.join(getTestDataDirectory().path, "mods.xml"); var modsFile = OS.Path.join(getTestDataDirectory().path, "mods.xml");
var promise = waitForItemEvent('add'); var promise = waitForItemEvent('add');
yield win.Zotero_File_Interface.importFile(Zotero.File.pathToFile(modsFile)); yield win.Zotero_File_Interface.importFile({
file: modsFile
});
var ids = yield promise; var ids = yield promise;
assert.lengthOf(ids, 1); assert.lengthOf(ids, 1);