From 54343c49fb00200e26e43f3ea83c2034fac59587 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 2 Sep 2019 09:22:58 -0400 Subject: [PATCH] Fix "getNote() can only be called on notes and attachments" CR error This bug may be as old as the sync system itself. It could occur if there were conflicts for both a note and a regular item in the same batch. --- chrome/content/zotero/bindings/merge.xml | 8 ++-- test/tests/syncLocalTest.js | 57 ++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/bindings/merge.xml b/chrome/content/zotero/bindings/merge.xml index 5747ff7af6..aa7fdba580 100644 --- a/chrome/content/zotero/bindings/merge.xml +++ b/chrome/content/zotero/bindings/merge.xml @@ -102,11 +102,9 @@ } // Check for note or attachment - if (!this.type) { - this.type = this._getTypeFromObject( - this._data.left.deleted ? this._data.right : this._data.left - ); - } + this.type = this._getTypeFromObject( + this._data.left.deleted ? this._data.right : this._data.left + ); var showButton = this.type != 'item'; diff --git a/test/tests/syncLocalTest.js b/test/tests/syncLocalTest.js index 783a1ab03a..a4b66fbf0f 100644 --- a/test/tests/syncLocalTest.js +++ b/test/tests/syncLocalTest.js @@ -994,6 +994,63 @@ describe("Zotero.Sync.Data.Local", function() { yield promise; }); + + it("should switch types by showing regular item after note", async function () { + var note = await createDataObject('item', { itemType: 'note' }); + var item = await createDataObject('item'); + + var promise = waitForWindow('chrome://zotero/content/merge.xul', function (dialog) { + var doc = dialog.document; + var wizard = doc.documentElement; + var mergeGroup = wizard.getElementsByTagName('zoteromergegroup')[0]; + + // 1 (accept remote deletion) + assert.equal(mergeGroup.leftpane.getAttribute('selected'), 'true'); + mergeGroup.rightpane.click(); + wizard.getButton('next').click(); + + // 2 (accept remote deletion) + mergeGroup.rightpane.click(); + if (Zotero.isMac) { + assert.isTrue(wizard.getButton('next').hidden); + assert.isFalse(wizard.getButton('finish').hidden); + } + else { + // TODO + } + wizard.getButton('finish').click(); + }); + + var mergeData = Zotero.Sync.Data.Local.showConflictResolutionWindow([ + { + libraryID: note.libraryID, + key: note.key, + processed: false, + conflict: true, + left: note.toJSON(), + right: { + deleted: true, + dateDeleted: "2019-09-01 00:00:00" + } + }, + { + libraryID: item.libraryID, + key: item.key, + processed: false, + conflict: true, + left: item.toJSON(), + right: { + deleted: true, + dateDeleted: "2019-09-01 01:00:00" + } + } + ]); + + await promise; + + assert.isTrue(mergeData[0].data.deleted); + assert.isTrue(mergeData[1].data.deleted); + }); });