From ac153558a698ae4d2de8e1275be259283b7e3eca Mon Sep 17 00:00:00 2001 From: "Michael (mcm)" Date: Fri, 26 May 2023 12:51:16 +0000 Subject: [PATCH] [FIX] web, mail: indirectly call a patched function The commit [1] removed two async module and caused a reorganisation on the module loading. Since that commit, the patches could be applied in a different order and be applied after a save of one these patches. This commit fixes a case where we save the reference of a patched function that we call it later with missing patches. [1]: 96687f29496ab4cf16ae2ab1584ef1a6a3fb4a11 Part-of: odoo/odoo#121185 --- .../mail/static/tests/helpers/test_utils.js | 3 +- .../tests/core/debug/debug_manager_tests.js | 3 +- addons/web/static/tests/helpers/mock_env.js | 52 ++++++++++--------- addons/web/static/tests/setup.js | 4 +- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/addons/mail/static/tests/helpers/test_utils.js b/addons/mail/static/tests/helpers/test_utils.js index faa9dbcb21f..162772a4fb3 100644 --- a/addons/mail/static/tests/helpers/test_utils.js +++ b/addons/mail/static/tests/helpers/test_utils.js @@ -16,12 +16,11 @@ import { registerCleanup } from "@web/../tests/helpers/cleanup"; import { clearRegistryWithCleanup, registryNamesToCloneWithCleanup, - utils, + prepareRegistriesWithCleanup, } from "@web/../tests/helpers/mock_env"; import { getFixture, makeDeferred, patchWithCleanup } from "@web/../tests/helpers/utils"; import { doAction, getActionManagerServerData } from "@web/../tests/webclient/helpers"; -const { prepareRegistriesWithCleanup } = utils; const { afterNextRender } = App; // load emoji data once, when the test suite starts. diff --git a/addons/web/static/tests/core/debug/debug_manager_tests.js b/addons/web/static/tests/core/debug/debug_manager_tests.js index 0a0760530e1..70e7eef664b 100644 --- a/addons/web/static/tests/core/debug/debug_manager_tests.js +++ b/addons/web/static/tests/core/debug/debug_manager_tests.js @@ -10,7 +10,7 @@ import { uiService } from "@web/core/ui/ui_service"; import { useSetupView } from "@web/views/view_hook"; import { ActionDialog } from "@web/webclient/actions/action_dialog"; import { hotkeyService } from "@web/core/hotkeys/hotkey_service"; -import { makeTestEnv, utils } from "../../helpers/mock_env"; +import { makeTestEnv, prepareRegistriesWithCleanup } from "../../helpers/mock_env"; import { fakeCompanyService, fakeCommandService, @@ -33,7 +33,6 @@ import { editSearchView, editView, setDefaults, viewMetadata } from "@web/views/ import { fieldService } from "@web/core/field_service"; import { Component, xml } from "@odoo/owl"; -const { prepareRegistriesWithCleanup } = utils; export class DebugMenuParent extends Component { setup() { diff --git a/addons/web/static/tests/helpers/mock_env.js b/addons/web/static/tests/helpers/mock_env.js index d7e3828f722..7b31a463907 100644 --- a/addons/web/static/tests/helpers/mock_env.js +++ b/addons/web/static/tests/helpers/mock_env.js @@ -60,36 +60,38 @@ export const registryNamesToCloneWithCleanup = [ "wowlToLegacyServiceMappers", ]; -function prepareRegistriesWithCleanup() { - // Clone registries - registryNamesToCloneWithCleanup.forEach((registryName) => - cloneRegistryWithCleanup(registry.category(registryName)) - ); +export const utils = { + prepareRegistriesWithCleanup() { + // Clone registries + registryNamesToCloneWithCleanup.forEach((registryName) => + cloneRegistryWithCleanup(registry.category(registryName)) + ); - // Clear registries - clearRegistryWithCleanup(registry.category("command_categories")); - clearRegistryWithCleanup(registry.category("debug")); - clearRegistryWithCleanup(registry.category("error_dialogs")); - clearRegistryWithCleanup(registry.category("favoriteMenu")); - clearRegistryWithCleanup(registry.category("ir.actions.report handlers")); - clearRegistryWithCleanup(registry.category("main_components")); - clearRegistryWithCleanup(registry.category("wowlToLegacyServiceMappers")); + // Clear registries + clearRegistryWithCleanup(registry.category("command_categories")); + clearRegistryWithCleanup(registry.category("debug")); + clearRegistryWithCleanup(registry.category("error_dialogs")); + clearRegistryWithCleanup(registry.category("favoriteMenu")); + clearRegistryWithCleanup(registry.category("ir.actions.report handlers")); + clearRegistryWithCleanup(registry.category("main_components")); + clearRegistryWithCleanup(registry.category("wowlToLegacyServiceMappers")); - clearRegistryWithCleanup(registry.category("services")); - clearServicesMetadataWithCleanup(); + clearRegistryWithCleanup(registry.category("services")); + clearServicesMetadataWithCleanup(); - clearRegistryWithCleanup(registry.category("systray")); - clearRegistryWithCleanup(registry.category("user_menuitems")); - clearRegistryWithCleanup(registry.category("kanban_examples")); - clearRegistryWithCleanup(registry.category("__processed_archs__")); - // fun fact: at least one registry is missing... this shows that we need a - // better design for the way we clear these registries... -} + clearRegistryWithCleanup(registry.category("systray")); + clearRegistryWithCleanup(registry.category("user_menuitems")); + clearRegistryWithCleanup(registry.category("kanban_examples")); + clearRegistryWithCleanup(registry.category("__processed_archs__")); + // fun fact: at least one registry is missing... this shows that we need a + // better design for the way we clear these registries... + }, +}; // This is exported in a utils object to allow for patching -export const utils = { - prepareRegistriesWithCleanup, -}; +export function prepareRegistriesWithCleanup() { + return utils.prepareRegistriesWithCleanup(); +} /** * @typedef {import("@web/env").OdooEnv} OdooEnv diff --git a/addons/web/static/tests/setup.js b/addons/web/static/tests/setup.js index 716b9f77755..5c5dc7084d8 100644 --- a/addons/web/static/tests/setup.js +++ b/addons/web/static/tests/setup.js @@ -8,7 +8,7 @@ import { browser, makeRAMLocalStorage } from "@web/core/browser/browser"; import { nextTick, patchTimeZone, patchWithCleanup } from "@web/../tests/helpers/utils"; import { memoize } from "@web/core/utils/functions"; import { registerCleanup } from "./helpers/cleanup"; -import { utils } from "./helpers/mock_env"; +import { prepareRegistriesWithCleanup } from "./helpers/mock_env"; import { session as sessionInfo } from "@web/session"; import { config as transitionConfig } from "@web/core/transition"; import { loadLanguages } from "@web/core/l10n/translation"; @@ -20,8 +20,6 @@ import { App, whenReady } from "@odoo/owl"; import { currencies } from "@web/core/currency"; import "./helpers/session"; -const { prepareRegistriesWithCleanup } = utils; - function stringifyObjectValues(obj, properties) { let res = ""; for (const dotted of properties) {