From bffbe00399592046ac353ddf0176073a0f0cd2cc Mon Sep 17 00:00:00 2001 From: Frank Bennett Date: Tue, 12 Feb 2019 23:32:11 +0900 Subject: [PATCH 1/2] Test of implicit citation update --- test/tests/integrationTest.js | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/test/tests/integrationTest.js b/test/tests/integrationTest.js index a2f452feb0..b5711da826 100644 --- a/test/tests/integrationTest.js +++ b/test/tests/integrationTest.js @@ -448,7 +448,7 @@ describe("Zotero.Integration", function () { } }); it('should insert citation if not in field', insertMultipleCitations); - + it('should edit citation if in citation field', function* () { yield insertMultipleCitations.call(this); var docID = this.test.fullTitle(); @@ -465,6 +465,33 @@ describe("Zotero.Integration", function () { assert.equal(citation.citationItems[0].id, testItems[3].id); }); + it('should write an implicitly updated citation into the document', function* () { + yield insertMultipleCitations.call(this); + var docID = this.test.fullTitle(); + var doc = applications[docID].doc; + + testItems[3].setCreator(0, {creatorType: 'author', lastName: 'Smith', firstName: 'Robert'}); + testItems[3].setField('date', '2019-01-01'); + + setAddEditItems(testItems[3]); + yield execCommand('addEditCitation', docID); + assert.equal(doc.fields[2].text, "(Smith, 2019)"); + + sinon.stub(doc, 'cursorInField').resolves(doc.fields[0]); + sinon.stub(doc, 'canInsertField').resolves(false); + + testItems[4].setCreator(0, {creatorType: 'author', lastName: 'Smith', firstName: 'Robert'}); + testItems[4].setField('date', '2019-01-01'); + + setAddEditItems(testItems[4]); + yield execCommand('addEditCitation', docID); + assert.equal(doc.fields.length, 3); + assert.equal(Zotero.Integration.currentSession.style.registry.registry[testItems[4].id].disambig.year_suffix, '0'); + assert.equal(Zotero.Integration.currentSession.style.registry.registry[testItems[3].id].disambig.year_suffix, '1'); + assert.equal(doc.fields[0].text, "(Smith, 2019a)"); + assert.equal(doc.fields[2].text, "(Smith, 2019b)"); + }); + it('should update bibliography if present', function* () { yield insertMultipleCitations.call(this); var docID = this.test.fullTitle(); From 2c136ffbb09c78d8f41481f893c89e10a80b41a5 Mon Sep 17 00:00:00 2001 From: Frank Bennett Date: Wed, 13 Feb 2019 00:09:35 +0900 Subject: [PATCH 2/2] Add test of multiple new insertions with implicit update on the first --- test/tests/integrationTest.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/test/tests/integrationTest.js b/test/tests/integrationTest.js index b5711da826..a537425a72 100644 --- a/test/tests/integrationTest.js +++ b/test/tests/integrationTest.js @@ -486,8 +486,34 @@ describe("Zotero.Integration", function () { setAddEditItems(testItems[4]); yield execCommand('addEditCitation', docID); assert.equal(doc.fields.length, 3); - assert.equal(Zotero.Integration.currentSession.style.registry.registry[testItems[4].id].disambig.year_suffix, '0'); - assert.equal(Zotero.Integration.currentSession.style.registry.registry[testItems[3].id].disambig.year_suffix, '1'); + assert.equal(doc.fields[0].text, "(Smith, 2019a)"); + assert.equal(doc.fields[2].text, "(Smith, 2019b)"); + }); + + it('should place an implicitly updated citation correctly after multiple new insertions', function* () { + yield insertMultipleCitations.call(this); + var docID = this.test.fullTitle(); + var doc = applications[docID].doc; + + testItems[3].setCreator(0, {creatorType: 'author', lastName: 'Smith', firstName: 'Robert'}); + testItems[3].setField('date', '2019-01-01'); + + setAddEditItems(testItems[3]); + yield execCommand('addEditCitation', docID); + assert.equal(doc.fields[2].text, "(Smith, 2019)"); + + sinon.stub(doc, 'cursorInField').resolves(doc.fields[0]); + sinon.stub(doc, 'canInsertField').resolves(false); + + doc.fields[1].code = doc.fields[0].code; + doc.fields[1].text = doc.fields[0].text; + + testItems[4].setCreator(0, {creatorType: 'author', lastName: 'Smith', firstName: 'Robert'}); + testItems[4].setField('date', '2019-01-01'); + + setAddEditItems(testItems[4]); + yield execCommand('addEditCitation', docID); + assert.equal(doc.fields.length, 3); assert.equal(doc.fields[0].text, "(Smith, 2019a)"); assert.equal(doc.fields[2].text, "(Smith, 2019b)"); });