From 9c2d0d7272cbfc7e31517b8db0b89c6ceeb96ca5 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 14 Jan 2019 02:32:26 -0500 Subject: [PATCH] Add skipped test for importing related items from Zotero RDF This is hard to do currently because the natural place to do it (and where the previous seeAlso stuff was done) is translate_item.js, but with async import translators that now only gets one item at a time, whereas saving item relations requires all items to be saved. So this would probably need to be done in the import code in translate.js. It might also require undoing https://github.com/zotero/zotero/pull/453 so that getResourceURI() works on notes and figuring out another solution for the problem that was trying to solve. --- test/tests/data/zotero_rdf.xml | 32 ++++++++++++++++++++++++++++++++ test/tests/importExportTest.js | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/tests/data/zotero_rdf.xml diff --git a/test/tests/data/zotero_rdf.xml b/test/tests/data/zotero_rdf.xml new file mode 100644 index 0000000000..49e1a42715 --- /dev/null +++ b/test/tests/data/zotero_rdf.xml @@ -0,0 +1,32 @@ + + + book + + + + ISBN 1-4214-0283-1 + A + + + C + + + D + + + webpage + + + + + + http://example.com + + B + + \ No newline at end of file diff --git a/test/tests/importExportTest.js b/test/tests/importExportTest.js index ccbef38021..d670774174 100644 --- a/test/tests/importExportTest.js +++ b/test/tests/importExportTest.js @@ -68,5 +68,31 @@ describe("Import/Export", function () { '#item_' + note1.id ); }); + + // Not currently supported + it.skip("should import related items", async function () { + var libraryID = Zotero.Libraries.userLibraryID; + var file = OS.Path.join(getTestDataDirectory().path, 'zotero_rdf.xml'); + translation = new Zotero.Translate.Import(); + translation.setLocation(Zotero.File.pathToFile(file)); + let translators = await translation.getTranslators(); + translation.setTranslator(translators[0]); + var newItems = await translation.translate({ libraryID }); + assert.lengthOf(newItems, 2); // DEBUG: why aren't child items returned here? + // Parent item + assert.lengthOf(newItems[0].relatedItems, 1); + assert.lengthOf(newItems[1].relatedItems, 1); + assert.sameMembers(newItems[0].relatedItems, [newItems[1]]); + assert.sameMembers(newItems[1].relatedItems, [newItems[0]]); + + var notes = newItems[0].getNotes(); + assert.lengthOf(notes, 2); + var newNote1 = Zotero.Items.get(notes[0]); + var newNote2 = Zotero.Items.get(notes[1]); + assert.lengthOf(newNote1.relatedItems, 1); + assert.lengthOf(newNote2.relatedItems, 1); + assert.sameMembers(newNote1.relatedItems, [newNote2]); + assert.sameMembers(newNote2.relatedItems, [newNote1]); + }); }); }); \ No newline at end of file