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 () {
|
describe("#migrateExtraFields()", function () {
|
||||||
it("should add a new field and migrate values from Extra", async function () {
|
async function migrate() {
|
||||||
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();
|
|
||||||
|
|
||||||
schema.version++;
|
schema.version++;
|
||||||
schema.itemTypes.find(x => x.itemType == 'book').fields.splice(0, 1, { field: 'fooBar' })
|
schema.itemTypes.find(x => x.itemType == 'book').fields.splice(0, 1, { field: 'fooBar' })
|
||||||
var newLocales = {};
|
var newLocales = {};
|
||||||
|
@ -65,6 +59,16 @@ describe("Zotero.Schema", function() {
|
||||||
});
|
});
|
||||||
await Zotero.Schema._updateGlobalSchemaForTest(schema);
|
await Zotero.Schema._updateGlobalSchemaForTest(schema);
|
||||||
await Zotero.Schema.migrateExtraFields();
|
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.isNumber(Zotero.ItemFields.getID('fooBar'));
|
||||||
assert.equal(Zotero.ItemFields.getLocalizedString('fooBar'), 'Foo Bar');
|
assert.equal(Zotero.ItemFields.getLocalizedString('fooBar'), 'Foo Bar');
|
||||||
|
@ -89,16 +93,7 @@ describe("Zotero.Schema", function() {
|
||||||
item.synced = true;
|
item.synced = true;
|
||||||
await item.saveTx();
|
await item.saveTx();
|
||||||
|
|
||||||
schema.version++;
|
await migrate();
|
||||||
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();
|
var creators = item.getCreators();
|
||||||
assert.lengthOf(creators, 2);
|
assert.lengthOf(creators, 2);
|
||||||
|
@ -126,16 +121,7 @@ describe("Zotero.Schema", function() {
|
||||||
item.synced = true;
|
item.synced = true;
|
||||||
await item.saveTx();
|
await item.saveTx();
|
||||||
|
|
||||||
schema.version++;
|
await migrate();
|
||||||
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();
|
var creators = item.getCreators();
|
||||||
assert.lengthOf(creators, 1);
|
assert.lengthOf(creators, 1);
|
||||||
|
@ -155,16 +141,7 @@ describe("Zotero.Schema", function() {
|
||||||
skipEditCheck: true
|
skipEditCheck: true
|
||||||
});
|
});
|
||||||
|
|
||||||
schema.version++;
|
await migrate();
|
||||||
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();
|
|
||||||
|
|
||||||
assert.isNumber(Zotero.ItemFields.getID('fooBar'));
|
assert.isNumber(Zotero.ItemFields.getID('fooBar'));
|
||||||
assert.equal(item.getField('fooBar'), '');
|
assert.equal(item.getField('fooBar'), '');
|
||||||
|
@ -195,16 +172,7 @@ describe("Zotero.Schema", function() {
|
||||||
item.synced = true;
|
item.synced = true;
|
||||||
await item.saveTx();
|
await item.saveTx();
|
||||||
|
|
||||||
schema.version++;
|
await migrate();
|
||||||
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();
|
|
||||||
|
|
||||||
assert.equal(item.getField('numPages'), 30);
|
assert.equal(item.getField('numPages'), 30);
|
||||||
var creators = item.getCreators();
|
var creators = item.getCreators();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue