From 28d85defa583edd135667d55577e37bb07f3648b Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 24 Oct 2023 11:03:53 +0200 Subject: [PATCH] [REF] web: remove useWidget compatibility helper Now that the last Component using that helper have been fully converted to Owl (AceEditorWrapper -> ResourceEditor), we can remove it. Part of task~3439226 Part-of: odoo/odoo#139154 --- addons/web/static/src/legacy/utils.js | 32 +-------- .../tests/legacy/owl_compatibility_tests.js | 70 +------------------ 2 files changed, 3 insertions(+), 99 deletions(-) diff --git a/addons/web/static/src/legacy/utils.js b/addons/web/static/src/legacy/utils.js index ca87da09d10..6dea3a5206c 100644 --- a/addons/web/static/src/legacy/utils.js +++ b/addons/web/static/src/legacy/utils.js @@ -1,16 +1,6 @@ /** @odoo-module **/ -import { - App, - Component, - onMounted, - onWillStart, - onWillUnmount, - useEnv, - useRef, - useState, - xml, -} from "@odoo/owl"; +import { App, Component, useState, xml } from "@odoo/owl"; import { templates } from "@web/core/assets"; import { _t } from "@web/core/l10n/translation"; @@ -41,26 +31,6 @@ export function createWidgetParent(env) { }; } -export function useWidget(refName, widgetClass, params = []) { - const ref = useRef(refName); - const env = useEnv(); - - const parent = createWidgetParent(env); - const widget = new widgetClass(parent, ...params); - - onWillStart(() => { - return widget._widgetRenderAndInsert(() => {}); - }); - onMounted(() => { - ref.el.append(widget.el); - }); - onWillUnmount(() => { - widget.destroy(); - }); - - return widget; -} - const rootTemplate = xml``; export async function attachComponent(parent, element, componentClass, props = {}) { class Root extends Component { diff --git a/addons/web/static/tests/legacy/owl_compatibility_tests.js b/addons/web/static/tests/legacy/owl_compatibility_tests.js index e4a864927f2..005dcf9decc 100644 --- a/addons/web/static/tests/legacy/owl_compatibility_tests.js +++ b/addons/web/static/tests/legacy/owl_compatibility_tests.js @@ -1,10 +1,8 @@ /** @odoo-module **/ - import { registry } from "@web/core/registry"; - import { attachComponent, useWidget } from "@web/legacy/utils"; + import { attachComponent } from "@web/legacy/utils"; - import { makeTestEnv } from "@web/../tests/helpers/mock_env"; - import { getFixture, mount } from "@web/../tests/helpers/utils"; + import { getFixture } from "@web/../tests/helpers/utils"; import Widget from "@web/legacy/js/core/widget"; import { Component, @@ -13,75 +11,11 @@ onWillDestroy, onWillStart, onWillUpdateProps, - useRef, - useState, xml, } from "@odoo/owl"; import { nextTick } from "./helpers/test_utils"; QUnit.module("Owl Compatibility", function () { - QUnit.test("useWidget", async (assert) => { - assert.expect(9); - - let widget = null; - const CustomWidget = Widget.extend({ - init(_, ...params) { - this._super(...arguments); - widget = this; - assert.step("widget initialized"); - assert.deepEqual(params, ["a", 1]); - this.params = params; - }, - start() { - this.$el.text("Hello World!"); - }, - callTriggerUp() { - this.call("test", "call", { [this.params[0]]: this.params[1] }); - }, - }); - - class ComponentAdapter extends Component { - static template = xml`
`; - setup() { - this.containerRef = useRef("container"); - this.widget = useWidget("container", CustomWidget, ["a", 1]); - assert.strictEqual(this.widget, widget); - } - } - - class Toggle extends Component { - static components = { ComponentAdapter }; - static template = xml``; - state = useState({ active: true }); - } - - const target = getFixture(); - registry.category("services").add("test", { - start: () => ({ - call: (p) => { - assert.step("triggered up"); - assert.deepEqual(p, { a: 1 }); - }, - }), - }); - const component = await mount(Toggle, target, { - env: await makeTestEnv(), - }); - assert.verifySteps(["widget initialized"]); - - assert.strictEqual( - target.querySelector("#adapter").textContent, - "Hello World!" - ); - - widget.callTriggerUp(); - assert.verifySteps(["triggered up"]); - - component.state.active = false; - await nextTick(); - assert.ok(widget.isDestroyed()); - }); - QUnit.test("attachComponent", async (assert) => { assert.expect(13);