From f950fd1190085372b7b96173bc967cfe408ce5ec Mon Sep 17 00:00:00 2001 From: Nicolas Bayet Date: Tue, 26 Oct 2021 11:09:45 +0000 Subject: [PATCH] [FIX] web_editor: wait editor loading in tests In a undeterministic circumstance, an element in the editor is not found. It might be because the check is done before the editor is fully loaded. The commit 46c22143b22e204e93c70b21d002eb179be34a33 tried to wait 100ms, but the bug continue to appear. This commit only perform the check when the editor is fully loaded. If the undeterministic bug continue to appear, it means that the cause is different. Task-2678110 closes odoo/odoo#79078 X-original-commit: 930b6822961f1ffdd1198e1ab2fe52229e14a50d Signed-off-by: David Monjoie (dmo) --- .../static/tests/field_html_tests.js | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/addons/web_editor/static/tests/field_html_tests.js b/addons/web_editor/static/tests/field_html_tests.js index 6bce3c1e0dd..b873a95a6a3 100644 --- a/addons/web_editor/static/tests/field_html_tests.js +++ b/addons/web_editor/static/tests/field_html_tests.js @@ -10,12 +10,22 @@ var core = require('web.core'); var Wysiwyg = require('web_editor.wysiwyg'); var MediaDialog = require('wysiwyg.widgets.MediaDialog'); var LinkDialog = require('wysiwyg.widgets.LinkDialog'); +var FieldHtml = require('web_editor.field.html'); const { registerCleanup } = require("@web/../tests/helpers/cleanup"); const { legacyExtraNextTick, patchWithCleanup } = require("@web/../tests/helpers/utils"); var _t = core._t; +FieldHtml.include({ + _onLoadWysiwyg: function () { + this._super.apply(this, arguments); + if (FieldHtml._resolveTestPromise) { + FieldHtml._resolveTestPromise(); + } + } +}); + QUnit.module('web_editor', {}, function () { QUnit.module('field html', { @@ -170,8 +180,9 @@ QUnit.module('web_editor', {}, function () { assert.strictEqual($field.attr('style'), 'height: 100px', "should have applied the style correctly"); + const promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; $field = form.$('.oe_form_field[name="body"]'); assert.strictEqual($field.find('.note-editable').html(), '

toto toto toto

tata

', @@ -193,8 +204,9 @@ QUnit.module('web_editor', {}, function () { res_id: 6, }); // check that there is no error on clicking Edit + const promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; assert.containsOnce(form, '.o_form_editable'); form.destroy(); @@ -221,8 +233,9 @@ QUnit.module('web_editor', {}, function () { } }, true); + const promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; await testUtils.dom.click(form.$('.o_form_button_save')); form.destroy(); @@ -439,8 +452,9 @@ QUnit.module('web_editor', {}, function () { '

External website

', "should have rendered a div with correct content in readonly"); + const promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; $field = form.$('.oe_form_field[name="body"]'); // the dialog load some xml assets const defLinkDialog = testUtils.makeTestPromise(); @@ -487,8 +501,9 @@ QUnit.module('web_editor', {}, function () { '

This website

', "should have rendered a div with correct content in readonly"); + const promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; $field = form.$('.oe_form_field[name="body"]'); // the dialog load some xml assets const defLinkDialog = testUtils.makeTestPromise(); @@ -535,8 +550,9 @@ QUnit.module('web_editor', {}, function () { assert.strictEqual($field.children('.o_readonly').html(), '

New external link

', "should have rendered a div with correct content in readonly"); + const promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; $field = form.$('.oe_form_field[name="body"]'); // the dialog load some xml assets const defLinkDialog = testUtils.makeTestPromise(); @@ -584,8 +600,9 @@ QUnit.module('web_editor', {}, function () { assert.strictEqual($field.children('.o_readonly').html(), '

New internal link

', "should have rendered a div with correct content in readonly"); + let promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; $field = form.$('.oe_form_field[name="body"]'); // the dialog load some xml assets const defLinkDialog = testUtils.makeTestPromise(); @@ -614,8 +631,9 @@ QUnit.module('web_editor', {}, function () { '

New internal link

', "the link should be created with the right format"); + promise = new Promise((resolve) => FieldHtml._resolveTestPromise = resolve); await testUtils.form.clickEdit(form); - await new Promise((resolve)=>setTimeout(resolve, 100)); + await promise; $field = form.$('.oe_form_field[name="body"]'); pText = $field.find('.note-editable a').eq(0).contents()[0];