Add test for SandboxItem#setExtra() (#3572)
This commit is contained in:
parent
90282b3739
commit
4a91df1b1d
2 changed files with 50 additions and 2 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 14f434b14754c23a27443a85a50c44ec337f3a21
|
||||
Subproject commit e0fe482b8a07e42cbf83545947382008ae7ddb82
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue