+1








0573acae23
This commit is the first phase of the conversion of the web/ JS codebase to the owl framework. The impact of this commit is two-fold. First, it rewrites the framework part of web with a new system of services and registries. Services allow to execute code (e.g. do rpcs, setup things) before launching the application. They can also expose an API to be used by other parts of the application (e.g. a notification service would expose a function to display notifications). Services are often a good extension point for external modules that want to execute code at webclient startup. Registries offer another way to extend the application. They provide well designed extension points to add elements/behaviors from the outside (for instance, to add a systray item, an error handler...). Second, this commit initiates the conversion of the webclient to owl with a top-down approach, around those notions of services and registries. The root of the web application is now an owl application. Among others, the WebClient, ActionManager, Navbar, UserMenu, DebugManager, Dialogs, services (e.g. notification, ajax...) have been converted to the new framework/architecture. Legacy views and client actions are still supported (and used). They will be converted in the next months, and at some point, the support will be dropped. Co-authored-by: Aaron Bohy <aab@odoo.com> Co-authored-by: Bruno Boi <boi@odoo.com> Co-authored-by: Géry Debongnie <ged@odoo.com> Co-authored-by: Samuel Degueldre <sad@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com> Co-authored-by: Simon Genin (ges) <ges@odoo.com> Co-authored-by: Francois (fge) <fge@odoo.com> Co-authored-by: Michael Mattiello (mcm) <mcm@odoo.com> Co-authored-by: Julien Mougenot <jum@odoo.com> Co-authored-by: Lucas Perais (lpe) <lpe@odoo.com> Co-authored-by: Jorge Pinna Puissant <jpp@odoo.com>
93 lines
3.5 KiB
JavaScript
93 lines
3.5 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
import core from "web.core";
|
|
import session from "web.session";
|
|
import { browser } from "@web/core/browser/browser";
|
|
import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
|
import { legacyProm } from "web.test_legacy";
|
|
import { registerCleanup } from "./helpers/cleanup";
|
|
import { prepareRegistriesWithCleanup, setTestOdooWithCleanup } from "./helpers/mock_env";
|
|
|
|
const { whenReady, loadFile } = owl.utils;
|
|
|
|
owl.config.enableTransitions = false;
|
|
owl.QWeb.dev = true;
|
|
|
|
function forceLocaleAndTimezoneWithCleanup() {
|
|
const originalLocale = luxon.Settings.defaultLocale;
|
|
luxon.Settings.defaultLocale = "en";
|
|
const originalZoneName = luxon.Settings.defaultZoneName;
|
|
luxon.Settings.defaultZoneName = "Europe/Brussels";
|
|
registerCleanup(() => {
|
|
luxon.Settings.defaultLocale = originalLocale;
|
|
luxon.Settings.defaultZoneName = originalZoneName;
|
|
});
|
|
}
|
|
|
|
function patchBrowserWithCleanup() {
|
|
// patch addEventListner to automatically remove listeners bound (via browser.addEventListener)
|
|
// during a test (e.g. during the deployment of a service)
|
|
const originalAddEventListener = browser.addEventListener;
|
|
const originalRemoveEventListener = browser.removeEventListener;
|
|
patchWithCleanup(browser, {
|
|
addEventListener() {
|
|
originalAddEventListener(...arguments);
|
|
registerCleanup(() => {
|
|
originalRemoveEventListener(...arguments);
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
function patchLegacyCoreBus() {
|
|
// patch core.bus.on to automatically remove listners bound on the legacy bus
|
|
// during a test (e.g. during the deployment of a service)
|
|
const originalOn = core.bus.on.bind(core.bus);
|
|
const originalOff = core.bus.off.bind(core.bus);
|
|
patchWithCleanup(core.bus, {
|
|
on() {
|
|
originalOn(...arguments);
|
|
registerCleanup(() => {
|
|
originalOff(...arguments);
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
function patchLegacySession() {
|
|
const userContext = Object.getOwnPropertyDescriptor(session, "user_context");
|
|
registerCleanup(() => {
|
|
Object.defineProperty(session, "user_context", userContext);
|
|
});
|
|
}
|
|
|
|
export async function setupTests() {
|
|
QUnit.testStart(() => {
|
|
setTestOdooWithCleanup();
|
|
prepareRegistriesWithCleanup();
|
|
forceLocaleAndTimezoneWithCleanup();
|
|
patchBrowserWithCleanup();
|
|
patchLegacyCoreBus();
|
|
patchLegacySession();
|
|
});
|
|
|
|
const templatesUrl = `/web/webclient/qweb/${new Date().getTime()}?bundle=web.assets_qweb`;
|
|
// TODO replace by `processTemplates` when the legacy system is removed
|
|
let templates = await loadFile(templatesUrl);
|
|
// as we currently have two qweb engines (owl and legacy), owl templates are
|
|
// flagged with attribute `owl="1"`. The following lines removes the 'owl'
|
|
// attribute from the templates, so that it doesn't appear in the DOM. For now,
|
|
// we make the assumption that 'templates' only contains owl templates. We
|
|
// might need at some point to handle the case where we have both owl and
|
|
// legacy templates. At the end, we'll get rid of all this.
|
|
const doc = new DOMParser().parseFromString(templates, "text/xml");
|
|
const owlTemplates = [];
|
|
for (let child of doc.querySelectorAll("templates > [owl]")) {
|
|
child.removeAttribute("owl");
|
|
owlTemplates.push(child.outerHTML);
|
|
}
|
|
templates = `<templates> ${owlTemplates.join("\n")} </templates>`;
|
|
window.__ODOO_TEMPLATES__ = templates;
|
|
await Promise.all([whenReady(), legacyProm]);
|
|
}
|