From 5d7136c21d54516bf646b7d9eedf2d8262ff528c Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Mon, 9 Jan 2023 12:58:16 +0000 Subject: [PATCH] [FIX] web: Incorrect navbar when leaving an invalid form view Before this commit, when trying to change the menu from an invalid form view, you would stay on the form view but the navbar would be modified to dispaly the menu you had selected. How to reproduce: - Go to a form view - Edit the fields so that the record is invalid - Change the menu using the menu app or the palette command Before this commit: The form view has not changed but the navbar has been modified, it shows the menu you selected. After this commit: The form view and the navbar have not changed. closes odoo/odoo#109460 X-original-commit: bd7e36edcd2f9d33a72cc25b030f91c20da78387 Signed-off-by: Aaron Bohy (aab) --- .../src/webclient/actions/action_service.js | 2 +- .../tests/views/form/form_view_tests.js | 67 +++++++++++++++++++ .../web/static/tests/views/list_view_tests.js | 3 +- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index ce15406bd1d..5eb3fc6a321 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -1240,7 +1240,7 @@ function makeActionManager(env) { if (action.target !== "new") { const canProceed = await clearUncommittedChanges(env); if (!canProceed) { - return; + return new Promise(() => {}); } } return _executeActWindowAction(action, options); 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 6c343a5c2e2..9329c3a031d 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -1702,6 +1702,73 @@ QUnit.module("Views", (hooks) => { assert.hasClass(target.querySelector(".o_notebook .nav-link"), "active"); }); + QUnit.test( + "trying to leave an invalid form view should not change the navbar", + async function (assert) { + serverData.menus = { + root: { id: "root", children: [1, 2], name: "root", appID: "root" }, + 1: { id: 1, children: [], name: "App0", appID: 1, xmlid: "menu_3", actionID: 1 }, + 2: { id: 2, children: [], name: "App1", appID: 2, xmlid: "menu_3", actionID: 2 }, + }; + serverData.views = { + "partner,false,form": ` +
+ + + + +
`, + "product,false,list": '', + "product,false,search": "", + "partner,false,search": "", + }; + + serverData.actions = { + 1: { + id: 1, + name: "Partner", + res_model: "partner", + type: "ir.actions.act_window", + views: [[false, "form"]], + }, + 2: { + id: 2, + name: "Product", + res_model: "product", + type: "ir.actions.act_window", + views: [[false, "list"]], + }, + }; + + const target = getFixture(); + const webClient = await createWebClient({ serverData }); + + await doAction(webClient, 1); + assert.strictEqual( + target.querySelector(".o_main_navbar .o_menu_brand").textContent, + "App0" + ); + + await editInput(target, "[name='foo'] input", "blop"); + await click(target, ".o_navbar_apps_menu button"); + await click(target, ".o_navbar_apps_menu .dropdown-item[data-section='2']"); + await nextTick(); + assert.strictEqual( + target.querySelector(".o_main_navbar .o_menu_brand").textContent, + "App0" + ); + + await editInput(target, "[name='display_name'] input", "blop"); + await click(target, ".o_navbar_apps_menu button"); + await click(target, ".o_navbar_apps_menu .dropdown-item[data-section='2']"); + await nextTick(); + assert.strictEqual( + target.querySelector(".o_main_navbar .o_menu_brand").textContent, + "App1" + ); + } + ); + QUnit.test("rendering stat buttons with action", async function (assert) { assert.expect(3); diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 8f315a8d6af..7e801c416c4 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -15357,7 +15357,8 @@ QUnit.module("Views", (hooks) => { await click(target.querySelector(".o_data_cell")); await editInput(target, '.o_data_cell [name="foo"] input', ""); - await doAction(webClient, 2); + doAction(webClient, 2); + await nextTick(); assert.deepEqual( [...target.querySelectorAll(".o_data_cell")].map((el) => el.textContent), ["", "blip", "gnap", "blip"]