From abadbb2d7781a204802f5f384b4bd838e582165c Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 25 Jun 2020 01:59:57 -0400 Subject: [PATCH] Add fileInterface test for importing into selected collection And update importFile() calls in tests to use current signature --- test/tests/fileInterfaceTest.js | 34 ++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/tests/fileInterfaceTest.js b/test/tests/fileInterfaceTest.js index 9faefebb99..f4bd8887c6 100644 --- a/test/tests/fileInterfaceTest.js +++ b/test/tests/fileInterfaceTest.js @@ -10,11 +10,13 @@ describe("Zotero_File_Interface", function() { 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); let testFile = getTestDataDirectory(); testFile.append("allTypesAndFields.js"); - yield win.Zotero_File_Interface.importFile(testFile); + await win.Zotero_File_Interface.importFile({ + file: testFile + }); let importedCollection = Zotero.Collections.getByLibrary( Zotero.Libraries.userLibraryID @@ -38,9 +40,27 @@ describe("Zotero_File_Interface", function() { delete trueItem.key; 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(), '

Child

'); + }); + + it('should import an item and snapshot from Zotero RDF', function* () { var tmpDir = yield getTempDirectory(); var rdfFile = OS.Path.join(tmpDir, 'test.rdf'); @@ -53,7 +73,9 @@ describe("Zotero_File_Interface", function() { ); 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; // Notifications are batched assert.lengthOf(ids, 2); @@ -78,7 +100,9 @@ describe("Zotero_File_Interface", function() { var modsFile = OS.Path.join(getTestDataDirectory().path, "mods.xml"); 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; assert.lengthOf(ids, 1);