+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>
136 lines
3.4 KiB
JavaScript
136 lines
3.4 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
import { registry } from "@web/core/registry";
|
|
import { makeTestEnv } from "../helpers/mock_env";
|
|
import { makeDeferred, nextTick } from "../helpers/utils";
|
|
|
|
const serviceRegistry = registry.category("services");
|
|
|
|
QUnit.module("deployServices");
|
|
|
|
QUnit.test("can start a service", async (assert) => {
|
|
serviceRegistry.add("test", {
|
|
start() {
|
|
return 17;
|
|
},
|
|
});
|
|
const env = await makeTestEnv();
|
|
assert.strictEqual(env.services.test, 17);
|
|
});
|
|
|
|
QUnit.test("can start an asynchronous service", async (assert) => {
|
|
const def = makeDeferred();
|
|
serviceRegistry.add("test", {
|
|
async start() {
|
|
assert.step("before");
|
|
const result = await def;
|
|
assert.step("after");
|
|
return result;
|
|
},
|
|
});
|
|
const prom = makeTestEnv();
|
|
assert.verifySteps(["before"]);
|
|
def.resolve(15);
|
|
const env = await prom;
|
|
assert.verifySteps(["after"]);
|
|
assert.strictEqual(env.services.test, 15);
|
|
});
|
|
|
|
QUnit.test("can start two sequentially dependant asynchronous services", async (assert) => {
|
|
const def1 = makeDeferred();
|
|
const def2 = makeDeferred();
|
|
serviceRegistry.add("test2", {
|
|
dependencies: ["test1"],
|
|
start() {
|
|
assert.step("test2");
|
|
return def2;
|
|
},
|
|
});
|
|
serviceRegistry.add("test1", {
|
|
start() {
|
|
assert.step("test1");
|
|
return def1;
|
|
},
|
|
});
|
|
serviceRegistry.add("test3", {
|
|
dependencies: ["test2"],
|
|
start() {
|
|
assert.step("test3");
|
|
},
|
|
});
|
|
const promise = makeTestEnv();
|
|
await nextTick();
|
|
assert.verifySteps(["test1"]);
|
|
def2.resolve();
|
|
await nextTick();
|
|
assert.verifySteps([]);
|
|
def1.resolve();
|
|
await nextTick();
|
|
assert.verifySteps(["test2", "test3"]);
|
|
await promise;
|
|
});
|
|
|
|
QUnit.test("can start two independant asynchronous services in parallel", async (assert) => {
|
|
const def1 = makeDeferred();
|
|
const def2 = makeDeferred();
|
|
serviceRegistry.add("test1", {
|
|
start() {
|
|
assert.step("test1");
|
|
return def1;
|
|
},
|
|
});
|
|
serviceRegistry.add("test2", {
|
|
start() {
|
|
assert.step("test2");
|
|
return def2;
|
|
},
|
|
});
|
|
serviceRegistry.add("test3", {
|
|
dependencies: ["test1", "test2"],
|
|
start() {
|
|
assert.step("test3");
|
|
},
|
|
});
|
|
const promise = makeTestEnv();
|
|
await nextTick();
|
|
assert.verifySteps(["test1", "test2"]);
|
|
def1.resolve();
|
|
await nextTick();
|
|
assert.verifySteps([]);
|
|
def2.resolve();
|
|
await nextTick();
|
|
assert.verifySteps(["test3"]);
|
|
await promise;
|
|
});
|
|
|
|
QUnit.test("can start a service with a dependency", async (assert) => {
|
|
serviceRegistry.add("aang", {
|
|
dependencies: ["appa"],
|
|
start() {
|
|
assert.step("aang");
|
|
},
|
|
});
|
|
serviceRegistry.add("appa", {
|
|
start() {
|
|
assert.step("appa");
|
|
},
|
|
});
|
|
await makeTestEnv();
|
|
assert.verifySteps(["appa", "aang"]);
|
|
});
|
|
|
|
QUnit.test("get an object containing dependencies as second arg", async (assert) => {
|
|
serviceRegistry.add("aang", {
|
|
dependencies: ["appa"],
|
|
start(env, deps) {
|
|
assert.deepEqual(deps, { appa: "flying bison" });
|
|
},
|
|
});
|
|
serviceRegistry.add("appa", {
|
|
start() {
|
|
return "flying bison";
|
|
},
|
|
});
|
|
await makeTestEnv();
|
|
});
|