Change integration test citation style to APA and some refactoring

This commit is contained in:
Adomas Venčkauskas 2022-10-25 13:51:26 +03:00
parent 238c7ce410
commit 4e1754b960
3 changed files with 1921 additions and 131 deletions

1900
test/tests/data/apa.csl Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,116 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" version="1.0" class="in-text" default-locale="en-US" demote-non-dropping-particle="sort-only" page-range-format="expanded">
<info>
<title>Cell</title>
<id>http://www.zotero.org/styles/cell</id>
<link href="http://www.zotero.org/styles/cell" rel="self"/>
<link href="http://www.cell.com/authors" rel="documentation"/>
<author>
<name>Adam Mark</name>
<email>a.mark@uoguelph.ca</email>
</author>
<contributor>
<name>Julian Onions</name>
<email>julian.onions@gmail.com</email>
</contributor>
<contributor>
<name>Aurimas Vinckevicius</name>
<email>aurimas.dev@gmail.com</email>
</contributor>
<category citation-format="author-date"/>
<category field="biology"/>
<issn>0092-8674</issn>
<eissn>1097-4172</eissn>
<summary>The Cell journal style. Original by Julian Onions.</summary>
<updated>2014-09-06T22:02:33+00:00</updated>
<rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
</info>
<macro name="author-short">
<names variable="author">
<name form="short" and="text"/>
</names>
</macro>
<macro name="author-count">
<names variable="author">
<name form="count"/>
</names>
</macro>
<macro name="author">
<names variable="author">
<name name-as-sort-order="all" initialize-with="." and="text" delimiter-precedes-last="always"/>
</names>
</macro>
<macro name="issued">
<date variable="issued">
<date-part name="year"/>
</date>
</macro>
<macro name="publisher">
<group prefix="(" delimiter=": " suffix=")">
<text variable="publisher-place"/>
<text variable="publisher"/>
</group>
</macro>
<macro name="editor">
<names variable="editor">
<name initialize-with="." and="text" delimiter-precedes-last="always"/>
<label form="short" prefix=", "/>
</names>
</macro>
<citation et-al-min="3" et-al-use-first="1" disambiguate-add-year-suffix="true" collapse="year">
<sort>
<key macro="author-short" names-min="1" names-use-first="1"/>
<key macro="author-count" names-min="3" names-use-first="3"/>
<key macro="author" names-min="3" names-use-first="1"/>
<key macro="issued"/>
<key variable="title"/>
</sort>
<layout prefix="(" suffix=")" delimiter="; ">
<group delimiter=", ">
<text macro="author-short"/>
<text macro="issued"/>
</group>
</layout>
</citation>
<bibliography et-al-min="11" et-al-use-first="10">
<sort>
<key macro="author-short" names-min="1" names-use-first="1"/>
<key macro="author-count" names-min="3" names-use-first="3"/>
<key macro="author" names-min="3" names-use-first="1"/>
<key macro="issued"/>
</sort>
<layout suffix=".">
<group delimiter=" ">
<text macro="author"/>
<text macro="issued" prefix="(" suffix=")."/>
<choose>
<if type="article article-magazine article-newspaper article-journal review" match="any">
<text variable="title" suffix="."/>
<text variable="container-title" form="short" text-case="title"/>
<group delimiter=", ">
<text variable="volume" font-style="italic"/>
<text variable="page"/>
</group>
</if>
<else-if type="chapter paper-conference" match="any">
<text variable="title" suffix="."/>
<text variable="container-title" prefix="In " suffix="," text-case="title"/>
<text macro="editor"/>
<text macro="publisher" suffix=","/>
<label variable="page" form="short"/>
<text variable="page"/>
</else-if>
<else-if type="thesis">
<text variable="title" suffix="."/>
<text variable="genre" suffix="."/>
<text variable="publisher"/>
</else-if>
<else>
<text variable="title"/>
<text macro="publisher"/>
</else>
</choose>
</group>
</layout>
</bibliography>
</style>

View file

@ -44,7 +44,7 @@ describe("Zotero.Integration", function () {
/**
* The Document class corresponds to a single word processing document.
*/
DocumentPluginDummy.Document = function() {this.fields = []};
DocumentPluginDummy.Document = function() {this.fields = [], this.fieldIdx = 0};
DocumentPluginDummy.Document.prototype = {
/**
* Displays a dialog in the word processing application
@ -96,7 +96,7 @@ describe("Zotero.Integration", function () {
if (typeof noteType != "number") {
throw new Error("noteType must be an integer");
}
var field = new DocumentPluginDummy.Field(this);
var field = new DocumentPluginDummy.Field(this, this.fieldIdx++);
this.fields.push(field);
return field;
},
@ -179,12 +179,13 @@ describe("Zotero.Integration", function () {
* The Field class corresponds to a field containing an individual citation
* or bibliography
*/
DocumentPluginDummy.Field = function(doc) {
DocumentPluginDummy.Field = function(doc, idx) {
this.doc = doc;
this.code = '';
// This is actually required and current integration code depends on text being non-empty upon insertion.
// insertBibliography will fail if there is no placeholder text.
this.text = '{Placeholder}';
this.idx = idx;
this.wrappedJSObject = this;
};
DocumentPluginDummy.Field.noteIndex = 0;
@ -243,7 +244,12 @@ describe("Zotero.Integration", function () {
let method = DocumentPluginDummy[cls].prototype[methodName];
DocumentPluginDummy[cls].prototype[methodName] = async function() {
try {
if (cls == 'Field') {
Zotero.debug(`DocumentPluginDummy: ${cls}[${this.idx}].${methodName} invoked with args ${JSON.stringify(arguments)}`, 2);
}
else {
Zotero.debug(`DocumentPluginDummy: ${cls}.${methodName} invoked with args ${JSON.stringify(arguments)}`, 2);
}
} catch (e) {
Zotero.debug(`DocumentPluginDummy: ${cls}.${methodName} invoked with args ${arguments}`, 2);
}
@ -262,8 +268,8 @@ describe("Zotero.Integration", function () {
var testItems;
var applications = {};
var addEditCitationSpy, displayDialogStub;
var styleID = "http://www.zotero.org/styles/cell";
var stylePath = OS.Path.join(getTestDataDirectory().path, 'cell.csl');
var styleID = "http://www.zotero.org/styles/apa";
var stylePath = OS.Path.join(getTestDataDirectory().path, 'apa.csl');
var commandList = [
'addCitation', 'editCitation', 'addEditCitation',
@ -306,7 +312,7 @@ describe("Zotero.Integration", function () {
function setDefaultIntegrationDocPrefs() {
dialogResults.integrationDocPrefs = {
style: "http://www.zotero.org/styles/cell",
style: styleID,
locale: 'en-US',
fieldType: 'Field',
automaticJournalAbbreviations: false,
@ -528,7 +534,7 @@ describe("Zotero.Integration", function () {
var doc = applications[docID].doc;
testItems[3].setCreator(0, {creatorType: 'author', lastName: 'Smith', firstName: 'Robert'});
testItems[3].setField('date', '2019-01-01');
testItems[3].setField('date', '2019-01-02');
setAddEditItems(testItems[3]);
yield execCommand('addEditCitation', docID);
@ -553,7 +559,7 @@ describe("Zotero.Integration", function () {
var doc = applications[docID].doc;
testItems[3].setCreator(0, {creatorType: 'author', lastName: 'Smith', firstName: 'Robert'});
testItems[3].setField('date', '2019-01-01');
testItems[3].setField('date', '2019-01-02');
setAddEditItems(testItems[3]);
yield execCommand('addEditCitation', docID);
@ -620,7 +626,7 @@ describe("Zotero.Integration", function () {
yield execCommand('addEditCitation', docID);
assert.equal(getCiteprocBibliographySpy.lastCall.returnValue[0].entry_ids.length, 3);
assert.equal(getCiteprocBibliographySpy.lastCall.returnValue[1][0], "Aaaaa Bbbbb.");
assert.equal(getCiteprocBibliographySpy.lastCall.returnValue[1][0], "Aaaaa. (n.d.). {\\i{}Bbbbb}.");
getCiteprocBibliographySpy.restore();
});
@ -936,11 +942,11 @@ describe("Zotero.Integration", function () {
describe("DocumentData", function() {
it('should properly unserialize old XML document data', function() {
var serializedXMLData = "<data data-version=\"3\" zotero-version=\"5.0.SOURCE\"><session id=\"F0NFmZ32\"/><style id=\"http://www.zotero.org/styles/cell\" hasBibliography=\"1\" bibliographyStyleHasBeenSet=\"1\"/><prefs><pref name=\"fieldType\" value=\"ReferenceMark\"/><pref name=\"automaticJournalAbbreviations\" value=\"true\"/><pref name=\"noteType\" value=\"0\"/></prefs></data>";
var serializedXMLData = `<data data-version="3" zotero-version="5.0.SOURCE"><session id="F0NFmZ32"/><style id="${styleID}" hasBibliography="1" bibliographyStyleHasBeenSet="1"/><prefs><pref name="fieldType" value="ReferenceMark"/><pref name="automaticJournalAbbreviations" value="true"/><pref name="noteType" value="0"/></prefs></data>`;
var data = new Zotero.Integration.DocumentData(serializedXMLData);
var expectedData = {
style: {
styleID: 'http://www.zotero.org/styles/cell',
styleID,
locale: null,
hasBibliography: true,
bibliographyStyleHasBeenSet: true
@ -961,7 +967,7 @@ describe("Zotero.Integration", function () {
it('should properly unserialize JSON document data', function() {
var expectedData = JSON.stringify({
style: {
styleID: 'http://www.zotero.org/styles/cell',
styleID,
locale: 'en-US',
hasBibliography: true,
bibliographyStyleHasBeenSet: true
@ -987,7 +993,7 @@ describe("Zotero.Integration", function () {
data.zoteroVersion = Zotero.version;
data.dataVersion = 3;
data.style = {
styleID: 'http://www.zotero.org/styles/cell',
styleID,
locale: 'en-US',
hasBibliography: false,
bibliographyStyleHasBeenSet: true
@ -1023,7 +1029,7 @@ describe("Zotero.Integration", function () {
data.dataVersion = 4;
data.sessionID = "owl-sesh";
data.style = {
styleID: 'http://www.zotero.org/styles/cell',
styleID,
locale: 'en-US',
hasBibliography: false,
bibliographyStyleHasBeenSet: true