From fd5fc7667744dda336cc13d709b3b922f28d77d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Wed, 9 Dec 2020 10:14:07 +0000 Subject: [PATCH] [FIX] web_editor: Qunit test properly wait for editor stop closes odoo/odoo#63073 Signed-off-by: David Monjoie (dmo) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 3 ++- addons/web_editor/static/tests/field_html_tests.js | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index b6109621218..dfa0f8d3442 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -42,6 +42,7 @@ var Wysiwyg = Widget.extend({ this.value = options.value || ''; this.options = options; this.colorPickers = []; + this.isEditorStoppedPromise = new Promise(resolve => this._editorStoppedResolve = resolve); this.JWEditorLib = JWEditorLib; if (this.options.enableTranslation) { this._modeConfig = { @@ -453,7 +454,7 @@ var Wysiwyg = Widget.extend({ // Saving the content of the editor is not possible after destroy, // so there's no need to keep the pop-up warning in this case. window.onbeforeunload = null; - this.editor.stop(); + this.editor.stop().then(this._editorStoppedResolve); this._super(); }, diff --git a/addons/web_editor/static/tests/field_html_tests.js b/addons/web_editor/static/tests/field_html_tests.js index 81a0d9675b0..98f115389ba 100644 --- a/addons/web_editor/static/tests/field_html_tests.js +++ b/addons/web_editor/static/tests/field_html_tests.js @@ -255,6 +255,7 @@ QUnit.module('web_editor', {}, function () { odoo.__DEBUG__.services['root.widget'] = rootWidget; form.destroy(); + await wysiwyg.isEditorStoppedPromise; }); QUnit.test('media dialog: image', async function (assert) { @@ -320,6 +321,7 @@ QUnit.module('web_editor', {}, function () { testUtils.mock.unpatch(MediaDialog); form.destroy(); + await wysiwyg.isEditorStoppedPromise; }); QUnit.test('media dialog: icon', async function (assert) { @@ -378,6 +380,7 @@ QUnit.module('web_editor', {}, function () { testUtils.mock.unpatch(MediaDialog); form.destroy(); + await wysiwyg.isEditorStoppedPromise; }); QUnit.test('save', async function (assert) { @@ -419,13 +422,17 @@ QUnit.module('web_editor', {}, function () { await testUtils.nextTick(); await new Promise((resolve) => wysiwyg.editor.execCommand(resolve)); await openColorpicker(); - await testUtils.nextTick(); + await testUtils.nextTick(); await new Promise((resolve) => wysiwyg.editor.execCommand(resolve)); await testUtils.dom.click($('jw-toolbar .o_we_color_btn[style="background-color:#00FFFF;"]')); + + await testUtils.nextTick(); + await new Promise((resolve) => wysiwyg.editor.execCommand(resolve)); await testUtils.form.clickSave(form); - await form.destroy(); + await wysiwyg.isEditorStoppedPromise; + form.destroy(); }); QUnit.module('cssReadonly');