zotero/test/tests/creatorsTest.js
Dan Stillman 6c58389563 Fix translation error when firstName is null for fieldMode 1
Some translators (e.g., CrossRef) return firstName: null with fieldMode:
1, which was causing an error
2017-02-27 23:34:16 -05:00

34 lines
993 B
JavaScript

"use strict";
describe("Zotero.Creators", function() {
describe("#getIDFromData()", function () {
it("should create creator and cache data", function* () {
var data1 = {
firstName: "First",
lastName: "Last"
};
var creatorID;
yield Zotero.DB.executeTransaction(function* () {
creatorID = yield Zotero.Creators.getIDFromData(data1, true);
});
assert.typeOf(creatorID, 'number');
var data2 = Zotero.Creators.get(creatorID);
assert.isObject(data2);
assert.propertyVal(data2, "firstName", data1.firstName);
assert.propertyVal(data2, "lastName", data1.lastName);
});
});
describe("#cleanData()", function () {
it("should allow firstName to be null for fieldMode 1", function* () {
var data = Zotero.Creators.cleanData({
firstName: null,
lastName: "Test",
fieldMode: 1
});
assert.propertyVal(data, 'fieldMode', 1);
assert.propertyVal(data, 'firstName', '');
assert.propertyVal(data, 'lastName', 'Test');
});
});
});