From 5a2ee5079816762771a79e1dbf388e9b7df61526 Mon Sep 17 00:00:00 2001 From: abd-msyukyu-odoo Date: Wed, 4 Oct 2023 14:43:54 +0200 Subject: [PATCH] [FIX] web_editor: change oe-id when switching record Add a test to ensure that the `MediaDialog` is opened with the correct record `resId` (to properly link files to that record) inside an html field. task-3502797 closes odoo/odoo#138525 X-original-commit: 5184bed2efd9923c0371d5e117a7915415ceee5a Signed-off-by: David Monjoie (dmo) Signed-off-by: Thibault Delavallee (tde) --- .../static/tests/html_field_tests.js | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/tests/html_field_tests.js b/addons/web_editor/static/tests/html_field_tests.js index 22ceecf1dc3..dd38fd85f0a 100644 --- a/addons/web_editor/static/tests/html_field_tests.js +++ b/addons/web_editor/static/tests/html_field_tests.js @@ -4,7 +4,8 @@ import { click, editInput, getFixture, makeDeferred, nextTick, patchWithCleanup import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; import { FormController } from '@web/views/form/form_controller'; import { HtmlField } from "@web_editor/js/backend/html_field"; -import { parseHTML } from "@web_editor/js/editor/odoo-editor/src/utils/utils"; +import { MediaDialog } from "@web_editor/components/media_dialog/media_dialog"; +import { parseHTML, setSelection } from "@web_editor/js/editor/odoo-editor/src/utils/utils"; import { onRendered } from "@odoo/owl"; import { wysiwygData } from "@web_editor/../tests/test_utils"; import { OdooEditor } from '@web_editor/js/editor/odoo-editor/src/OdooEditor'; @@ -44,6 +45,63 @@ QUnit.module("WebEditor.HtmlField", ({ beforeEach }) => { setupViewRegistries(); }); + QUnit.module("Form view interactions with the HtmlField"); + + QUnit.test("A new MediaDialog after switching record in a Form view should have the correct resId", async (assert) => { + serverData.models.partner.records = [ + {id: 1, txt: "

first

"}, + {id: 2, txt: "

second

"}, + ]; + let wysiwyg, mediaDialog; + const wysiwygPromise = makeDeferred(); + const mediaDialogPromise = makeDeferred(); + patchWithCleanup(HtmlField.prototype, { + async startWysiwyg() { + await super.startWysiwyg(...arguments); + wysiwyg = this.wysiwyg; + wysiwygPromise.resolve(); + } + }); + patchWithCleanup(MediaDialog.prototype, { + setup() { + mediaDialog = this; + mediaDialogPromise.resolve(); + this.size = 'xl'; + this.contentClass = 'o_select_media_dialog'; + this.title = "TEST"; + this.tabs = []; + this.state = {}; + // no call to super to avoid services dependencies + // this test only cares about the props given to the dialog + } + }); + await makeView({ + type: "form", + resId: 1, + resIds: [1, 2], + resModel: "partner", + serverData, + arch: ` +
+ + `, + }); + await wysiwygPromise; + + assert.containsOnce(target, ".odoo-editor-editable p:contains(first)"); + + // click on the pager to switch to the next record + await click(target.querySelector(".o_pager_next")); + + assert.containsOnce(target, ".odoo-editor-editable p:contains(second)"); + const paragraph = target.querySelector(".odoo-editor-editable p"); + setSelection(paragraph, 0, paragraph, 0); + + wysiwyg.openMediaDialog(); + await mediaDialogPromise; + + assert.equal(mediaDialog.props.resId, 2); + }); QUnit.module('Sandboxed Preview');