[FIX] tests: views: helpers: the view's env is not the global env
Before this commit in tests, when creating a view with makeView, the same env was shared for services, view and main_components_container. This is rather wrong as bugs in prod could not be reproduced in tests. For example: env.config was present in the env for every services and components, this is wrong as only View must receive it in its env. After this commit, makeView separates the env for services and top-level components from the one dedicated for View. Part-of: odoo/odoo#96618
This commit is contained in:
@@ -53,7 +53,7 @@ function prepareRegistriesWithCleanup() {
|
||||
cloneRegistryWithCleanup(registry.category("command_setup"));
|
||||
cloneRegistryWithCleanup(registry.category("view_widgets"));
|
||||
cloneRegistryWithCleanup(registry.category("fields"));
|
||||
cloneRegistryWithCleanup(registry.category('wowlToLegacyServiceMappers'));
|
||||
cloneRegistryWithCleanup(registry.category("wowlToLegacyServiceMappers"));
|
||||
|
||||
cloneRegistryWithCleanup(registry.category("main_components"));
|
||||
cloneRegistryWithCleanup(registry.category("fields"));
|
||||
@@ -64,7 +64,7 @@ function prepareRegistriesWithCleanup() {
|
||||
clearRegistryWithCleanup(registry.category("error_dialogs"));
|
||||
clearRegistryWithCleanup(registry.category("favoriteMenu"));
|
||||
clearRegistryWithCleanup(registry.category("ir.actions.report handlers"));
|
||||
clearRegistryWithCleanup(registry.category('wowlToLegacyServiceMappers'));
|
||||
clearRegistryWithCleanup(registry.category("wowlToLegacyServiceMappers"));
|
||||
|
||||
clearRegistryWithCleanup(registry.category("services"));
|
||||
clearServicesMetadataWithCleanup();
|
||||
@@ -122,9 +122,11 @@ export async function makeTestEnv(config = {}) {
|
||||
FormController.prototype.multiClickTime = initialQuickEditDelay;
|
||||
});
|
||||
|
||||
const env = makeEnv();
|
||||
owl.Component.env = env;
|
||||
env.config = config.config || {};
|
||||
let env = makeEnv();
|
||||
await startServices(env);
|
||||
owl.Component.env = env;
|
||||
if ("config" in config) {
|
||||
env = Object.assign(Object.create(env), { config: config.config });
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
@@ -78,8 +78,9 @@ export async function makeWithSearch(params) {
|
||||
</WithSearch>`;
|
||||
Parent.components = { Component: params.Component, WithSearch };
|
||||
|
||||
const env = await makeTestEnv({ serverData, mockRPC, config });
|
||||
const parent = await mount(Parent, getFixture(), { env, props });
|
||||
const env = await makeTestEnv({ serverData, mockRPC });
|
||||
const searchEnv = Object.assign(Object.create(env), { config });
|
||||
const parent = await mount(Parent, getFixture(), { env: searchEnv, props });
|
||||
const parentNode = parent.__owl__;
|
||||
const withSearchNode = getUniqueChild(parentNode);
|
||||
const componentNode = getUniqueChild(withSearchNode);
|
||||
|
||||
@@ -322,6 +322,7 @@ QUnit.module("Search", (hooks) => {
|
||||
|
||||
class Parent extends Component {
|
||||
setup() {
|
||||
owl.useSubEnv({ config: {} });
|
||||
this.searchState = useState({
|
||||
resModel: "animal",
|
||||
domain: [["type", "=", "carnivorous"]],
|
||||
|
||||
@@ -61,7 +61,7 @@ export async function makeView(params) {
|
||||
delete props.searchViewArch;
|
||||
}
|
||||
|
||||
const env = await makeTestEnv({ serverData, mockRPC, config });
|
||||
const env = await makeTestEnv({ serverData, mockRPC });
|
||||
Object.assign(env, createDebugContext(env)); // This is needed if the views are in debug mode
|
||||
|
||||
/** Legacy Environment, for compatibility sakes
|
||||
@@ -81,7 +81,8 @@ export async function makeView(params) {
|
||||
await addLegacyMockEnvironment(env, legacyParams);
|
||||
|
||||
const target = getFixture();
|
||||
const view = await mount(View, target, { env, props });
|
||||
const viewEnv = Object.assign(Object.create(env), { config });
|
||||
const view = await mount(View, target, { env: viewEnv, props });
|
||||
await mount(MainComponentsContainer, target, { env, props });
|
||||
|
||||
const viewNode = view.__owl__;
|
||||
|
||||
@@ -58,8 +58,9 @@ QUnit.module("Views", (hooks) => {
|
||||
</Layout>`;
|
||||
ToyComponent.components = { Layout };
|
||||
|
||||
const env = await makeTestEnv({ config: {} });
|
||||
await mount(ToyComponent, getFixture(), { env });
|
||||
const env = await makeTestEnv();
|
||||
const toyEnv = Object.assign(Object.create(env), { config: {} });
|
||||
await mount(ToyComponent, getFixture(), { env: toyEnv });
|
||||
|
||||
assert.containsOnce(target, ".o_view_sample_data");
|
||||
assert.containsNone(target, ".o_control_panel");
|
||||
|
||||
Reference in New Issue
Block a user