From 5266734ac9901fc5c78ed3bc8b1b52ce0a48a4bf Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Wed, 13 Jan 2021 14:01:44 +0200 Subject: [PATCH] Fix note editor tests --- chrome/content/zotero/bindings/noteeditor.xml | 10 ++++++++++ chrome/content/zotero/xpcom/editorInstance.js | 2 +- test/tests/itemPaneTest.js | 16 +++++++++------- test/tests/noteeditorTest.js | 2 +- zotero-note-editor | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/bindings/noteeditor.xml b/chrome/content/zotero/bindings/noteeditor.xml index c7f96f8436..ad3cf40368 100644 --- a/chrome/content/zotero/bindings/noteeditor.xml +++ b/chrome/content/zotero/bindings/noteeditor.xml @@ -106,6 +106,16 @@ onReturn: this._returnHandler, placeholder: this.placeholder }); + if (this._onInitCallback) { + this._onInitCallback(); + } + } + + this.onInit = (callback) => { + if (this._editorInstance) { + return callback(); + } + this._onInitCallback = callback; } this.notify = async (event, type, ids, extraData) => { diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 5ebbe6e0e3..958648d3d1 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -126,7 +126,7 @@ class EditorInstance { saveSync() { if (!this._readOnly && !this._disableSaving && this._iframeWindow) { - let noteData = this._iframeWindow.wrappedJSObject.getDataSync(); + let noteData = this._iframeWindow.wrappedJSObject.getDataSync(true); if (noteData) { noteData = JSON.parse(JSON.stringify(noteData)); } diff --git a/test/tests/itemPaneTest.js b/test/tests/itemPaneTest.js index c6ce5c0d10..72889cff7a 100644 --- a/test/tests/itemPaneTest.js +++ b/test/tests/itemPaneTest.js @@ -282,16 +282,18 @@ describe("Item pane", function () { // Wait for the editor yield new Zotero.Promise((resolve, reject) => { - noteEditor.noteField.onInit(() => resolve()); - }) - assert.equal(noteEditor.noteField.value, ''); - + noteEditor.onInit(() => resolve()); + }); + assert.equal(noteEditor._editorInstance._iframeWindow.wrappedJSObject.getDataSync(), null); item.setNote('

Test

'); yield item.saveTx(); - assert.equal(noteEditor.noteField.value, '

Test

'); - }) - }) + // Wait for asynchronous editor update + do { + yield Zotero.Promise.delay(10); + } while(noteEditor._editorInstance._iframeWindow.wrappedJSObject.getDataSync().html != '

Test

'); + }); + }); describe("Feed buttons", function() { describe("Mark as Read/Unread", function() { diff --git a/test/tests/noteeditorTest.js b/test/tests/noteeditorTest.js index 6145793361..7b0ffb11c4 100644 --- a/test/tests/noteeditorTest.js +++ b/test/tests/noteeditorTest.js @@ -20,7 +20,7 @@ describe("Note Editor", function () { noteEditor = win.document.getElementById('zotero-note-editor'); } return new Zotero.Promise((resolve, reject) => { - noteEditor.noteField.onInit(() => resolve(noteEditor)); + noteEditor.onInit(() => resolve(noteEditor)); }); }); diff --git a/zotero-note-editor b/zotero-note-editor index 73808236ba..007082af6c 160000 --- a/zotero-note-editor +++ b/zotero-note-editor @@ -1 +1 @@ -Subproject commit 73808236baa117a0e712e21f3c0ac06af1a553f0 +Subproject commit 007082af6c4a534d98bc4a6e04c899bb5e9520d8