Group strict-mode and non-strict-mode tests for Item::fromJSON()
This commit is contained in:
parent
b41734924d
commit
11caa1b719
1 changed files with 139 additions and 136 deletions
|
@ -1754,18 +1754,6 @@ describe("Zotero.Item", function () {
|
||||||
assert.isFalse(item.inPublications);
|
assert.isFalse(item.inPublications);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should handle Extra in non-strict mode", function () {
|
|
||||||
var json = {
|
|
||||||
itemType: "journalArticle",
|
|
||||||
title: "Test",
|
|
||||||
extra: "Here's some extra text"
|
|
||||||
};
|
|
||||||
var item = new Zotero.Item();
|
|
||||||
item.fromJSON(json);
|
|
||||||
assert.equal(item.getField('extra'), json.extra);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
// Not currently following this behavior
|
// Not currently following this behavior
|
||||||
/*it("should move valid field in Extra to field if not set", function () {
|
/*it("should move valid field in Extra to field if not set", function () {
|
||||||
var doi = '10.1234/abcd';
|
var doi = '10.1234/abcd';
|
||||||
|
@ -1822,7 +1810,19 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.getField('extra'), json.extra);
|
assert.equal(item.getField('extra'), json.extra);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should store unknown fields in Extra in non-strict mode", function () {
|
describe("not-strict mode", function () {
|
||||||
|
it("should handle Extra in non-strict mode", function () {
|
||||||
|
var json = {
|
||||||
|
itemType: "journalArticle",
|
||||||
|
title: "Test",
|
||||||
|
extra: "Here's some extra text"
|
||||||
|
};
|
||||||
|
var item = new Zotero.Item();
|
||||||
|
item.fromJSON(json);
|
||||||
|
assert.equal(item.getField('extra'), json.extra);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should store unknown fields in Extra", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1835,7 +1835,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.getField('extra'), 'Foo Bar: 123\nTest Field: test value');
|
assert.equal(item.getField('extra'), 'Foo Bar: 123\nTest Field: test value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should replace unknown field in Extra in non-strict mode", function () {
|
it("should replace unknown field in Extra", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1848,7 +1848,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.getField('extra'), 'Foo: BBB\nBar: CCC');
|
assert.equal(item.getField('extra'), 'Foo: BBB\nBar: CCC');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should store invalid-for-type field in Extra in non-strict mode", function () {
|
it("should store invalid-for-type field in Extra", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1860,11 +1860,11 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.getField('extra'), 'Medium: 123');
|
assert.equal(item.getField('extra'), 'Medium: 123');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should ignore invalid-for-type base-mapped field if valid-for-type base field is set in Extra in non-strict mode", function () {
|
it("should ignore invalid-for-type base-mapped field if valid-for-type base field is set in Extra", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "document",
|
itemType: "document",
|
||||||
publisher: "Foo", // Valid for 'document'
|
publisher: "Foo", // Valid for 'document'
|
||||||
company: "Bar" // Not invalid for 'document', but mapped to base field 'publisher'
|
company: "Bar" // Not valid for 'document', but mapped to base field 'publisher'
|
||||||
};
|
};
|
||||||
var item = new Zotero.Item;
|
var item = new Zotero.Item;
|
||||||
item.fromJSON(json);
|
item.fromJSON(json);
|
||||||
|
@ -1872,7 +1872,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.getField('extra'), '');
|
assert.equal(item.getField('extra'), '');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shouldn't include base field or invalid base-mapped field in Extra if valid base-mapped field is set in non-strict mode", function () {
|
it("shouldn't include base field or invalid base-mapped field in Extra if valid base-mapped field is set", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "audioRecording",
|
itemType: "audioRecording",
|
||||||
publisher: "A", // Base field, which will be overwritten by the valid base-mapped field
|
publisher: "A", // Base field, which will be overwritten by the valid base-mapped field
|
||||||
|
@ -1885,8 +1885,10 @@ describe("Zotero.Item", function () {
|
||||||
assert.equal(item.getField('label'), 'B');
|
assert.equal(item.getField('label'), 'B');
|
||||||
assert.equal(item.getField('extra'), 'Foo: D');
|
assert.equal(item.getField('extra'), 'Foo: D');
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should throw on unknown field in strict mode", function () {
|
describe("strict mode", function () {
|
||||||
|
it("should throw on unknown field", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1899,7 +1901,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.throws(f, /^Unknown field/);
|
assert.throws(f, /^Unknown field/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw on invalid field for a given item type in strict mode", function () {
|
it("should throw on invalid field for a given item type", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1912,7 +1914,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.throws(f, /^Invalid field/);
|
assert.throws(f, /^Invalid field/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw on unknown creator type in strict mode", function () {
|
it("should throw on unknown creator type", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1931,7 +1933,7 @@ describe("Zotero.Item", function () {
|
||||||
assert.throws(f, /^Unknown creator type/);
|
assert.throws(f, /^Unknown creator type/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should throw on invalid creator type for a given item type in strict mode", function () {
|
it("should throw on invalid creator type for a given item type", function () {
|
||||||
var json = {
|
var json = {
|
||||||
itemType: "journalArticle",
|
itemType: "journalArticle",
|
||||||
title: "Test",
|
title: "Test",
|
||||||
|
@ -1949,6 +1951,7 @@ describe("Zotero.Item", function () {
|
||||||
};
|
};
|
||||||
assert.throws(f, /^Invalid creator type/);
|
assert.throws(f, /^Invalid creator type/);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("should accept ISO 8601 dates", function* () {
|
it("should accept ISO 8601 dates", function* () {
|
||||||
var json = {
|
var json = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue