[REF] web: improve main_component registry API to accept props

closes odoo-dev/odoo#910

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Géry Debongnie
2021-06-18 21:31:30 +02:00
committed by Aaron Bohy
parent d73309de28
commit 1b549bddd1
19 changed files with 68 additions and 30 deletions
@@ -34,7 +34,9 @@ QUnit.module("Bus Assets WatchDog", (hooks) => {
serviceRegistry.add("assetsWatchdog", assetsWatchdogService);
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("NotificationContainer", NotificationContainer);
mainComponentRegistry.add("NotificationContainer", {
Component: NotificationContainer
});
patchWithCleanup(browser, {
setTimeout: (fn) => fn(),
clearTimeout: () => {},
@@ -34,7 +34,9 @@ QUnit.module("Calendar Notification", (hooks) => {
serviceRegistry.add("calendarNotification", calendarNotificationService);
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("NotificationContainer", NotificationContainer);
mainComponentRegistry.add("NotificationContainer", {
Component: NotificationContainer
});
patchWithCleanup(browser, {
setTimeout: (fn) => fn(),
+2 -2
View File
@@ -17,8 +17,8 @@ PosApp.template = owl.tags.xml`
<body>
<ChromeAdapter />
<div>
<t t-foreach="Components" t-as="Component" t-key="Component[0]">
<t t-component="Component[1]"/>
<t t-foreach="Components" t-as="C" t-key="C[0]">
<t t-component="C[1].Component" t-props="C[1].props"/>
</t>
</div>
</body>
@@ -57,4 +57,6 @@ DialogContainer.template = tags.xml`
</div>
`;
registry.category("main_components").add("DialogContainer", DialogContainer);
registry.category("main_components").add("DialogContainer", {
Component: DialogContainer,
});
@@ -25,4 +25,6 @@ NotificationContainer.template = tags.xml`
</div>`;
NotificationContainer.components = { NotificationComponent };
registry.category("main_components").add("NotificationContainer", NotificationContainer);
registry.category("main_components").add("NotificationContainer", {
Component: NotificationContainer,
});
@@ -92,7 +92,9 @@ PopoverManager.template = xml`
</div>
`;
registry.category("main_components").add("PopoverManager", PopoverManager);
registry.category("main_components").add("PopoverManager", {
Component: PopoverManager,
});
export const popoverService = {
start() {
@@ -86,4 +86,4 @@ BlockUI.template = tags.xml`
</t>
</div>`;
registry.category("main_components").add("BlockUI", BlockUI);
registry.category("main_components").add("BlockUI", { Component: BlockUI });
@@ -27,4 +27,6 @@ EffectContainer.template = tags.xml`
</div>`;
EffectContainer.components = { RainbowMan };
registry.category("main_components").add("EffectContainer", EffectContainer);
registry.category("main_components").add("EffectContainer", {
Component: EffectContainer,
});
@@ -50,4 +50,6 @@ export class LoadingIndicator extends Component {
LoadingIndicator.template = "web.LoadingIndicator";
registry.category("main_components").add("LoadingIndicator", LoadingIndicator);
registry.category("main_components").add("LoadingIndicator", {
Component: LoadingIndicator,
});
@@ -7,8 +7,8 @@
<ActionContainer/>
<div class="o_dialog_container"/>
<div>
<t t-foreach="Components" t-as="Component" t-key="Component[0]">
<t t-component="Component[1]"/>
<t t-foreach="Components" t-as="C" t-key="C[0]">
<t t-component="C[1].Component" t-props="C[1].props"/>
</t>
</div>
</body>
@@ -31,8 +31,8 @@ PseudoWebClient.template = tags.xml`
<div>
<div class="o_dialog_container"/>
<div>
<t t-foreach="Components" t-as="Component" t-key="Component[0]">
<t t-component="Component[1]"/>
<t t-foreach="Components" t-as="C" t-key="C[0]">
<t t-component="C[1].Component" t-props="C[1].props"/>
</t>
</div>
</div>
@@ -45,7 +45,9 @@ QUnit.module("DialogManager", {
serviceRegistry.add("ui", uiService);
serviceRegistry.add("hotkey", hotkeyService);
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("DialogContainer", DialogContainer);
mainComponentRegistry.add("DialogContainer", {
Component: DialogContainer,
});
env = await makeTestEnv();
},
afterEach() {
@@ -32,8 +32,8 @@ PseudoWebClient.template = xml`
<div id="anchor">Anchor</div>
<div id="close">Close</div>
<div>
<t t-foreach="Components" t-as="Component" t-key="Component[0]">
<t t-component="Component[1]"/>
<t t-foreach="Components" t-as="C" t-key="C[0]">
<t t-component="C[1].Component" t-props="C[1].props"/>
</t>
</div>
</div>
@@ -43,7 +43,9 @@ QUnit.module("PopoverManager", {
async beforeEach() {
serviceRegistry.add("popover", popoverService);
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("PopoverManager", PopoverManager);
mainComponentRegistry.add("PopoverManager", {
Component: PopoverManager,
});
env = await makeTestEnv();
pseudoWebClient = await mount(PseudoWebClient, {
env,
@@ -334,7 +334,9 @@ QUnit.module("ActionManager", (hooks) => {
QUnit.test("test display_notification client action", async function (assert) {
assert.expect(6);
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("NotificationContainer", NotificationContainer);
mainComponentRegistry.add("NotificationContainer", {
Component: NotificationContainer,
});
const webClient = await createWebClient({ testConfig });
await doAction(webClient, 1);
assert.containsOnce(webClient, ".o_kanban_view");
@@ -375,7 +377,9 @@ QUnit.module("ActionManager", (hooks) => {
QUnit.test("test next action on display_notification client action", async function (assert) {
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("NotificationContainer", NotificationContainer);
mainComponentRegistry.add("NotificationContainer", {
Component: NotificationContainer,
});
const webClient = await createWebClient({ testConfig });
const options = {
onClose: function (infos) {
@@ -27,7 +27,9 @@ QUnit.module("ActionManager", (hooks) => {
force: true,
});
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("EffectContainer", EffectContainer);
mainComponentRegistry.add("EffectContainer", {
Component: EffectContainer,
});
const webClient = await createWebClient({ testConfig });
await doAction(webClient, 1);
assert.containsOnce(webClient.el, ".o_kanban_view");
@@ -56,7 +58,9 @@ QUnit.module("ActionManager", (hooks) => {
QUnit.test("show effect notification instead of rainbow man", async function (assert) {
assert.expect(6);
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("NotificationContainer", NotificationContainer);
mainComponentRegistry.add("NotificationContainer", {
Component: NotificationContainer,
});
const webClient = await createWebClient({ testConfig });
await doAction(webClient, 1);
@@ -88,7 +92,9 @@ QUnit.module("ActionManager", (hooks) => {
}
};
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("EffectContainer", EffectContainer);
mainComponentRegistry.add("EffectContainer", {
Component: EffectContainer,
});
const webClient = await createWebClient({ testConfig, mockRPC });
await doAction(webClient, 6);
await click(webClient.el.querySelector('button[name="object"]'));
@@ -115,7 +121,9 @@ QUnit.module("ActionManager", (hooks) => {
}
};
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("EffectContainer", EffectContainer);
mainComponentRegistry.add("EffectContainer", {
Component: EffectContainer,
});
const webClient = await createWebClient({ testConfig, mockRPC });
await doAction(webClient, 6);
@@ -40,7 +40,9 @@ QUnit.module("ActionManager", (hooks) => {
});
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("NotificationContainer", NotificationContainer);
mainComponentRegistry.add("NotificationContainer", {
Component: NotificationContainer,
});
const webClient = await createWebClient({ testConfig });
await doAction(webClient, 3);
assert.containsOnce(webClient, ".o_list_view");
@@ -67,7 +69,9 @@ QUnit.module("ActionManager", (hooks) => {
},
});
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("DialogContainer", DialogContainer);
mainComponentRegistry.add("DialogContainer", {
Component: DialogContainer,
});
const webClient = await createWebClient({ testConfig });
await doAction(webClient, 3);
@@ -19,7 +19,9 @@ QUnit.module("ActionManager", (hooks) => {
hooks.beforeEach(() => {
testConfig = getActionManagerTestConfig();
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("DialogContainer", DialogContainer);
mainComponentRegistry.add("DialogContainer", {
Component: DialogContainer,
});
});
QUnit.module("Report actions");
@@ -2132,7 +2132,9 @@ QUnit.module("ActionManager", (hooks) => {
const mainComponentRegistry = registry.category("main_components");
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("DialogContainer", DialogContainer);
mainComponentRegistry.add("DialogContainer", {
Component: DialogContainer,
});
testConfig.serverData.views["partner,false,form"] = `
<form>
@@ -20,7 +20,7 @@ const commandCategoryRegistry = registry.category("command_categories");
class TestComponent extends Component {}
TestComponent.components = {
DialogContainer: registry.category("main_components").get("DialogContainer"),
DialogContainer: registry.category("main_components").get("DialogContainer").Component,
};
TestComponent.template = xml`
<div>
@@ -50,7 +50,7 @@ QUnit.test("can render a main component", async (assert) => {
class MyComponent extends Component {}
MyComponent.template = xml`<span class="chocolate">MyComponent</span>`;
clearRegistryWithCleanup(mainComponentRegistry);
mainComponentRegistry.add("mycomponent", MyComponent);
mainComponentRegistry.add("mycomponent", { Component: MyComponent });
const env = await makeTestEnv(baseConfig);
const target = getFixture();
const webClient = await mount(WebClient, { env, target });