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];