/** @odoo-module */ import { ViewButton } from "@web/views/view_button/view_button"; import { useViewButtons } from "@web/views/view_button/view_button_hook"; import { setupViewRegistries } from "./helpers"; import { click, getFixture, mount } from "../helpers/utils"; import { makeTestEnv } from "../helpers/mock_env"; import { registry } from "@web/core/registry"; import { Dropdown } from "@web/core/dropdown/dropdown"; import { DropdownItem } from "@web/core/dropdown/dropdown_item"; import { useRef, Component, xml } from "@odoo/owl"; QUnit.module("UseViewButton tests", (hooks) => { let target; hooks.beforeEach(() => { target = getFixture(); setupViewRegistries(); }); QUnit.test("action can be prevented", async (assert) => { registry.category("services").add( "action", { start() { return { doActionButton() { assert.step("doActionButton"); }, }; }, }, { force: true } ); let executeInHook; let executeInHandler; class MyComponent extends Component { setup() { const rootRef = useRef("root"); useViewButtons({}, rootRef, { beforeExecuteAction: () => { assert.step("beforeExecuteAction in hook"); return executeInHook; }, }); } onClick() { const getResParams = () => ({ resIds: [3], resId: 3, }); const clickParams = {}; const beforeExecute = () => { assert.step("beforeExecuteAction on handler"); return executeInHandler; }; this.env.onClickViewButton({ beforeExecute, getResParams, clickParams }); } } MyComponent.template = xml`