Add test for SandboxItem#setExtra() (#3572)

This commit is contained in:
Abe Jellinek 2024-02-09 02:34:47 -05:00 committed by GitHub
parent 90282b3739
commit 4a91df1b1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 2 deletions

@ -1 +1 @@
Subproject commit 14f434b14754c23a27443a85a50c44ec337f3a21
Subproject commit e0fe482b8a07e42cbf83545947382008ae7ddb82

View file

@ -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() {
});
});
});
}
}