Add additional test for creator migration from Extra
This commit is contained in:
parent
275e17c7ec
commit
d8d07362ba
1 changed files with 35 additions and 1 deletions
|
@ -75,7 +75,7 @@ describe("Zotero.Schema", function() {
|
||||||
assert.isFalse(item.synced);
|
assert.isFalse(item.synced);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should migrate creator", async function () {
|
it("should migrate valid creator", async function () {
|
||||||
var item = await createDataObject('item', { itemType: 'book' });
|
var item = await createDataObject('item', { itemType: 'book' });
|
||||||
item.setCreators([
|
item.setCreators([
|
||||||
{
|
{
|
||||||
|
@ -112,6 +112,40 @@ describe("Zotero.Schema", function() {
|
||||||
assert.isFalse(item.synced);
|
assert.isFalse(item.synced);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("shouldn't migrate creator not valid for item type", async function () {
|
||||||
|
var item = await createDataObject('item', { itemType: 'book' });
|
||||||
|
item.setCreators([
|
||||||
|
{
|
||||||
|
firstName: 'Abc',
|
||||||
|
lastName: 'Def',
|
||||||
|
creatorType: 'author',
|
||||||
|
fieldMode: 0
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
item.setField('extra', 'container-author: Last || First\nFoo: Bar');
|
||||||
|
item.synced = true;
|
||||||
|
await item.saveTx();
|
||||||
|
|
||||||
|
schema.version++;
|
||||||
|
schema.itemTypes.find(x => x.itemType == 'book').fields.splice(0, 1, { field: 'fooBar' })
|
||||||
|
var newLocales = {};
|
||||||
|
Object.keys(schema.locales).forEach((locale) => {
|
||||||
|
var o = schema.locales[locale];
|
||||||
|
o.fields.fooBar = 'Foo Bar';
|
||||||
|
newLocales[locale] = o;
|
||||||
|
});
|
||||||
|
await Zotero.Schema._updateGlobalSchemaForTest(schema);
|
||||||
|
await Zotero.Schema.migrateExtraFields();
|
||||||
|
|
||||||
|
var creators = item.getCreators();
|
||||||
|
assert.lengthOf(creators, 1);
|
||||||
|
assert.propertyVal(creators[0], 'firstName', 'Abc');
|
||||||
|
assert.propertyVal(creators[0], 'lastName', 'Def');
|
||||||
|
assert.propertyVal(creators[0], 'creatorTypeID', Zotero.CreatorTypes.getID('author'));
|
||||||
|
assert.equal(item.getField('extra'), 'container-author: Last || First\nFoo: Bar');
|
||||||
|
assert.isTrue(item.synced);
|
||||||
|
});
|
||||||
|
|
||||||
it("shouldn't migrate fields in read-only library", async function () {
|
it("shouldn't migrate fields in read-only library", async function () {
|
||||||
var library = await createGroup({ editable: false, filesEditable: false });
|
var library = await createGroup({ editable: false, filesEditable: false });
|
||||||
var item = createUnsavedDataObject('item', { libraryID: library.libraryID, itemType: 'book' });
|
var item = createUnsavedDataObject('item', { libraryID: library.libraryID, itemType: 'book' });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue