From 4a91df1b1d29579d93b481f0d96f322cb3f99f06 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Fri, 9 Feb 2024 02:34:47 -0500 Subject: [PATCH] Add test for SandboxItem#setExtra() (#3572) --- chrome/content/zotero/xpcom/translate | 2 +- test/tests/translateTest.js | 50 ++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/translate b/chrome/content/zotero/xpcom/translate index 14f434b147..e0fe482b8a 160000 --- a/chrome/content/zotero/xpcom/translate +++ b/chrome/content/zotero/xpcom/translate @@ -1 +1 @@ -Subproject commit 14f434b14754c23a27443a85a50c44ec337f3a21 +Subproject commit e0fe482b8a07e42cbf83545947382008ae7ddb82 diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index 5c8f585f45..f77a315ac0 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -860,6 +860,54 @@ describe("Zotero.Translate", function() { Zotero.Translators.get.restore(); }); + + describe("#setExtra()", function () { + it("should set extra field", async function () { + let translator = buildDummyTranslator(1, + String.raw`function doImport() { + var item = new Zotero.Item(); + item.itemType = "book"; + item.title = "The Ultimate Owl Guide"; + item.setExtra("Key 1", "Value 1"); + item.extra += "\nRandom junk"; + item.setExtra("Key 2", "Value 2"); + item.complete(); + }` + ); + let translate = new Zotero.Translate.Import(); + translate.setTranslator(translator); + translate.setString(""); + let items = await translate.translate(); + assert.lengthOf(items, 1); + let [item] = items; + assert.equal(item.getField("extra"), "Key 1: Value 1\nRandom junk\nKey 2: Value 2"); + assert.isUndefined(item.setExtra); + }); + + it("should overwrite field if already present", async function () { + let translator = buildDummyTranslator(1, + String.raw`function doImport() { + var item = new Zotero.Item(); + item.itemType = "book"; + item.title = "The Ultimate Owl Guide"; + item.extra = "Random junk\nKey 1: Value 1.1"; + item.setExtra("Key 1", "Value 1.2"); + item.extra += "\nRandom junk"; + item.setExtra("Key 2", "Value 2"); + item.setExtra("Key 1", "Value 1.3"); + item.complete(); + }` + ); + let translate = new Zotero.Translate.Import(); + translate.setTranslator(translator); + translate.setString(""); + let items = await translate.translate(); + assert.lengthOf(items, 1); + let [item] = items; + assert.equal(item.getField("extra"), "Random junk\nKey 1: Value 1.3\nRandom junk\nKey 2: Value 2"); + assert.isUndefined(item.setExtra); + }); + }); }); @@ -2399,4 +2447,4 @@ describe("Zotero.Translate.ItemGetter", function() { }); }); }); -} \ No newline at end of file +}