From feaa6d64bdd4eacad435fc2dce191aa9de523b76 Mon Sep 17 00:00:00 2001 From: Pierre Paridans Date: Fri, 6 Oct 2023 10:45:49 +0000 Subject: [PATCH] [FIX] web: tests: click helper: throw error if target is disabled This commit is a backport of odoo/odoo@f065276a4611ddad67fd3d200fc131f2e30907b5 Before chrome 116, programmatic clicks on disabled buttons weren't actually fired. With chrome 116, they are. As a consequence, some tests fails on chrome 116 because they click (on purpose) on disabled button to highlight the fact that nothing happens. This commit improves the click helper to make it throw an error when the target is disabled. It also adapts the tests that were clicking on disabled button, in general to simply assert that the button is disabled instead. closes odoo/odoo#139537 X-original-commit: 0e8b50d540c9eee0837282883d603937b94b2fd2 Signed-off-by: Romeo Fragomeli (rfr) Signed-off-by: Pierre Paridans (app) Co-authored-by: Aaron Bohy --- addons/web/static/tests/legacy/helpers/test_utils_dom.js | 3 +++ addons/web/static/tests/views/form/form_view_tests.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web/static/tests/legacy/helpers/test_utils_dom.js b/addons/web/static/tests/legacy/helpers/test_utils_dom.js index bb56a21e549..7c24798f7d9 100644 --- a/addons/web/static/tests/legacy/helpers/test_utils_dom.js +++ b/addons/web/static/tests/legacy/helpers/test_utils_dom.js @@ -134,6 +134,9 @@ import { delay } from "@web/core/utils/concurrency"; if (typeof el === 'string') { el = $(el); } + if (el.disabled || (el instanceof jQuery && el.get(0).disabled)) { + throw new Error("Can't click on a disabled button"); + } if (_isEventTarget(el)) { // EventTarget matches = [el]; diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index fe1d3df7d67..d5bc27839d9 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -9964,7 +9964,7 @@ QUnit.module("Views", (hooks) => { await editInput(target, '.o_field_widget[name="foo"] input', "test"); await clickSave(target); - await clickSave(target); + assert.ok(target.querySelector(".o_form_button_save").disabled); // Save button is disabled, it can't be clicked def.resolve(); await nextTick();