Change integration test citation style to APA and some refactoring
This commit is contained in:
parent
87a567122e
commit
a28908f0b4
3 changed files with 1921 additions and 131 deletions
|
@ -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 {
|
||||
Zotero.debug(`DocumentPluginDummy: ${cls}.${methodName} invoked with args ${JSON.stringify(arguments)}`, 2);
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue