Merge branch '4.0'
This commit is contained in:
commit
7f43ca9503
173 changed files with 3568 additions and 1419 deletions
|
@ -1347,8 +1347,7 @@
|
|||
1,
|
||||
2
|
||||
]
|
||||
],
|
||||
"season": "2000-01-02"
|
||||
]
|
||||
},
|
||||
"title": "Title",
|
||||
"type": "patent"
|
||||
|
|
|
@ -221,7 +221,7 @@ describe("Zotero.Utilities", function() {
|
|||
|
||||
yield attachment.saveTx();
|
||||
|
||||
cslJSONAttachment = yield Zotero.Utilities.itemToCSLJSON(attachment);
|
||||
let cslJSONAttachment = yield Zotero.Utilities.itemToCSLJSON(attachment);
|
||||
assert.equal(cslJSONAttachment.type, 'article', 'attachment is exported as "article"');
|
||||
assert.equal(cslJSONAttachment.title, 'Empty', 'attachment title is correct');
|
||||
assert.deepEqual(cslJSONAttachment.accessed, {"date-parts":[["2001",2,3]]}, 'attachment access date is mapped correctly');
|
||||
|
@ -272,5 +272,148 @@ describe("Zotero.Utilities", function() {
|
|||
|
||||
assert.isUndefined(cslJSON.PMID, 'field labels are case-sensitive');
|
||||
}));
|
||||
it("should parse particles in creator names", function() {
|
||||
let creators = [
|
||||
{
|
||||
// No particles
|
||||
firstName: 'John',
|
||||
lastName: 'Smith',
|
||||
creatorType: 'author',
|
||||
expect: {
|
||||
given: 'John',
|
||||
family: 'Smith'
|
||||
}
|
||||
},
|
||||
{
|
||||
// dropping and non-dropping
|
||||
firstName: 'Jean de',
|
||||
lastName: 'la Fontaine',
|
||||
creatorType: 'author',
|
||||
expect: {
|
||||
given: 'Jean',
|
||||
"dropping-particle": 'de',
|
||||
"non-dropping-particle": 'la',
|
||||
family: 'Fontaine'
|
||||
}
|
||||
},
|
||||
{
|
||||
// only non-dropping
|
||||
firstName: 'Vincent',
|
||||
lastName: 'van Gogh',
|
||||
creatorType: 'author',
|
||||
expect: {
|
||||
given: 'Vincent',
|
||||
"non-dropping-particle": 'van',
|
||||
family: 'Gogh'
|
||||
}
|
||||
},
|
||||
{
|
||||
// only dropping
|
||||
firstName: 'Alexander von',
|
||||
lastName: 'Humboldt',
|
||||
creatorType: 'author',
|
||||
expect: {
|
||||
given: 'Alexander',
|
||||
"dropping-particle": 'von',
|
||||
family: 'Humboldt'
|
||||
}
|
||||
},
|
||||
{
|
||||
// institutional author
|
||||
lastName: 'Jean de la Fontaine',
|
||||
creatorType: 'author',
|
||||
fieldMode: 1,
|
||||
expect: {
|
||||
literal: 'Jean de la Fontaine'
|
||||
}
|
||||
},
|
||||
{
|
||||
// protected last name
|
||||
firstName: 'Jean de',
|
||||
lastName: '"la Fontaine"',
|
||||
creatorType: 'author',
|
||||
expect: {
|
||||
given: 'Jean de',
|
||||
family: 'la Fontaine'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
let data = populateDBWithSampleData({
|
||||
item: {
|
||||
itemType: 'journalArticle',
|
||||
creators: creators
|
||||
}
|
||||
});
|
||||
|
||||
let item = Zotero.Items.get(data.item.id);
|
||||
let cslCreators = Zotero.Utilities.itemToCSLJSON(item).author;
|
||||
|
||||
assert.deepEqual(cslCreators[0], creators[0].expect, 'simple name is not parsed');
|
||||
assert.deepEqual(cslCreators[1], creators[1].expect, 'name with dropping and non-dropping particles is parsed');
|
||||
assert.deepEqual(cslCreators[2], creators[2].expect, 'name with only non-dropping particle is parsed');
|
||||
assert.deepEqual(cslCreators[3], creators[3].expect, 'name with only dropping particle is parsed');
|
||||
assert.deepEqual(cslCreators[4], creators[4].expect, 'institutional author is not parsed');
|
||||
assert.deepEqual(cslCreators[5], creators[5].expect, 'protected last name prevents parsing');
|
||||
});
|
||||
});
|
||||
describe("itemFromCSLJSON", function() {
|
||||
it("should stably perform itemToCSLJSON -> itemFromCSLJSON -> itemToCSLJSON", function() {
|
||||
let data = loadSampleData('citeProcJSExport');
|
||||
|
||||
Zotero.DB.beginTransaction();
|
||||
|
||||
for (let i in data) {
|
||||
let item = data[i];
|
||||
|
||||
let zItem = new Zotero.Item();
|
||||
Zotero.Utilities.itemFromCSLJSON(zItem, item);
|
||||
zItem = Zotero.Items.get(zItem.save());
|
||||
|
||||
let newItem = Zotero.Utilities.itemToCSLJSON(zItem);
|
||||
|
||||
delete newItem.id;
|
||||
delete item.id;
|
||||
|
||||
assert.deepEqual(newItem, item, i + ' export -> import -> export is stable');
|
||||
}
|
||||
|
||||
Zotero.DB.commitTransaction();
|
||||
|
||||
});
|
||||
it("should import exported standalone note", function() {
|
||||
let note = new Zotero.Item('note');
|
||||
note.setNote('Some note longer than 50 characters, which will become the title.');
|
||||
note = Zotero.Items.get(note.save());
|
||||
|
||||
let jsonNote = Zotero.Utilities.itemToCSLJSON(note);
|
||||
|
||||
let zItem = new Zotero.Item();
|
||||
Zotero.Utilities.itemFromCSLJSON(zItem, jsonNote);
|
||||
zItem = Zotero.Items.get(zItem.save());
|
||||
|
||||
assert.equal(zItem.getField('title'), jsonNote.title, 'title imported correctly');
|
||||
});
|
||||
it("should import exported standalone attachment", function() {
|
||||
let file = getTestDataDirectory();
|
||||
file.append("empty.pdf");
|
||||
|
||||
let attachment = Zotero.Items.get(Zotero.Attachments.importFromFile(file));
|
||||
attachment.setField('title', 'Empty');
|
||||
attachment.setField('accessDate', '2001-02-03 12:13:14');
|
||||
attachment.setField('url', 'http://example.com');
|
||||
attachment.setNote('Note');
|
||||
|
||||
attachment.save();
|
||||
|
||||
let jsonAttachment = Zotero.Utilities.itemToCSLJSON(attachment);
|
||||
|
||||
let zItem = new Zotero.Item();
|
||||
Zotero.Utilities.itemFromCSLJSON(zItem, jsonAttachment);
|
||||
zItem = Zotero.Items.get(zItem.save());
|
||||
|
||||
assert.equal(zItem.getField('title'), jsonAttachment.title, 'title imported correctly');
|
||||
});
|
||||
>>>>>>> 4.0:test/tests/utilities.js
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue