Refactor migrateExtraFields() tests
This commit is contained in:
parent
9d330206ed
commit
02b43cbfac
1 changed files with 15 additions and 47 deletions
|
@ -48,13 +48,7 @@ describe("Zotero.Schema", function() {
|
|||
});
|
||||
|
||||
describe("#migrateExtraFields()", function () {
|
||||
it("should add a new field and migrate values from Extra", async function () {
|
||||
var item = await createDataObject('item', { itemType: 'book' });
|
||||
item.setField('numPages', "10");
|
||||
item.setField('extra', 'Foo Bar: This is a value.\nnumber-of-pages: 11\nThis is another line.');
|
||||
item.synced = true;
|
||||
await item.saveTx();
|
||||
|
||||
async function migrate() {
|
||||
schema.version++;
|
||||
schema.itemTypes.find(x => x.itemType == 'book').fields.splice(0, 1, { field: 'fooBar' })
|
||||
var newLocales = {};
|
||||
|
@ -65,6 +59,16 @@ describe("Zotero.Schema", function() {
|
|||
});
|
||||
await Zotero.Schema._updateGlobalSchemaForTest(schema);
|
||||
await Zotero.Schema.migrateExtraFields();
|
||||
}
|
||||
|
||||
it("should add a new field and migrate values from Extra", async function () {
|
||||
var item = await createDataObject('item', { itemType: 'book' });
|
||||
item.setField('numPages', "10");
|
||||
item.setField('extra', 'Foo Bar: This is a value.\nnumber-of-pages: 11\nThis is another line.');
|
||||
item.synced = true;
|
||||
await item.saveTx();
|
||||
|
||||
await migrate();
|
||||
|
||||
assert.isNumber(Zotero.ItemFields.getID('fooBar'));
|
||||
assert.equal(Zotero.ItemFields.getLocalizedString('fooBar'), 'Foo Bar');
|
||||
|
@ -89,16 +93,7 @@ describe("Zotero.Schema", function() {
|
|||
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();
|
||||
await migrate();
|
||||
|
||||
var creators = item.getCreators();
|
||||
assert.lengthOf(creators, 2);
|
||||
|
@ -126,16 +121,7 @@ describe("Zotero.Schema", function() {
|
|||
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();
|
||||
await migrate();
|
||||
|
||||
var creators = item.getCreators();
|
||||
assert.lengthOf(creators, 1);
|
||||
|
@ -155,16 +141,7 @@ describe("Zotero.Schema", function() {
|
|||
skipEditCheck: true
|
||||
});
|
||||
|
||||
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();
|
||||
await migrate();
|
||||
|
||||
assert.isNumber(Zotero.ItemFields.getID('fooBar'));
|
||||
assert.equal(item.getField('fooBar'), '');
|
||||
|
@ -195,16 +172,7 @@ describe("Zotero.Schema", function() {
|
|||
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();
|
||||
await migrate();
|
||||
|
||||
assert.equal(item.getField('numPages'), 30);
|
||||
var creators = item.getCreators();
|
||||
|
|
Loading…
Reference in a new issue