diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 5845a737a3..13adb1cfff 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -1968,14 +1968,14 @@ Zotero.Integration.Session.prototype.handleRetractedItems = async function () { if (zoteroItem.cslItemID) { embeddedZoteroItems.push(zoteroItem); } - else if (Zotero.Retractions.isRetracted(zoteroItem)) { + else if (Zotero.Retractions.shouldShowCitationWarning(zoteroItem)) { dealWithRetracted(zoteroItem, true); } } } - var retractedIndices = await Promise.race(Zotero.Retractions.getRetractionsFromJSON( + var retractedIndices = await Promise.race([Zotero.Retractions.getRetractionsFromJSON( embeddedZoteroItems.map(item => item.toJSON()) - ), Zotero.Promise.delay(1000).then(() => [])); + ), Zotero.Promise.delay(1000).then(() => [])]); for (let index of retractedIndices) { dealWithRetracted(embeddedZoteroItems[index]); } diff --git a/test/tests/integrationTest.js b/test/tests/integrationTest.js index cf28e3ffd0..69382bb353 100644 --- a/test/tests/integrationTest.js +++ b/test/tests/integrationTest.js @@ -309,7 +309,7 @@ describe("Zotero.Integration", function () { testItems = []; for (let i = 0; i < 5; i++) { let testItem = yield createDataObject('item', {libraryID: Zotero.Libraries.userLibraryID}); - testItem.setField('title', `title${1}`); + testItem.setField('title', `title${i}`); testItem.setCreator(0, {creatorType: 'author', name: `Author No${i}`}); testItems.push(testItem); } @@ -815,6 +815,62 @@ describe("Zotero.Integration", function () { setCodeSpy.restore(); }) }); + + describe('with retracted items', function () { + it('should display a retraction warning for a retracted item in a document', async function () { + var docID = this.test.fullTitle(); + await initDoc(docID); + var doc = applications[docID].doc; + setAddEditItems(testItems[0]); + await execCommand('addEditCitation', docID); + + let stub1 = sinon.stub(Zotero.Retractions, 'isRetracted').returns(true); + let stub2 = sinon.stub(Zotero.Retractions, 'shouldShowCitationWarning').returns(true); + + let promise = execCommand('refresh', docID); + await assert.isFulfilled(waitForDialog()); + + stub1.restore(); + stub2.restore(); + await promise; + }); + + it('should display a retraction warning for an embedded retracted item in a document', async function () { + var docID = this.test.fullTitle(); + await initDoc(docID); + var doc = applications[docID].doc; + let testItem = await createDataObject('item', { libraryID: Zotero.Libraries.userLibraryID }); + testItem.setField('title', `embedded title`); + testItem.setCreator(0, { creatorType: 'author', name: `Embedded Author` }); + setAddEditItems(testItem); + await execCommand('addEditCitation', docID); + await testItem.eraseTx(); + + let stub = sinon.stub(Zotero.Retractions, 'getRetractionsFromJSON').resolves([0]); + + let promise = execCommand('refresh', docID); + await assert.isFulfilled(waitForDialog()); + + stub.restore(); + await promise; + }); + + it('should not display retraction warning when disabled for a retracted item', async function () { + var docID = this.test.fullTitle(); + await initDoc(docID); + var doc = applications[docID].doc; + let testItem = await createDataObject('item', { libraryID: Zotero.Libraries.userLibraryID }); + testItem.setField('title', `title`); + testItem.setCreator(0, { creatorType: 'author', name: `Author` }); + await Zotero.Retractions.disableCitationWarningsForItem(testItem); + setAddEditItems(testItem); + await execCommand('addEditCitation', docID); + + await assert.isFulfilled(execCommand('refresh', docID)); + + await testItem.eraseTx(); + }); + }); }); describe('#addEditBibliography', function() {