[IMP] component: support dynamic t-component

This commit is contained in:
Géry Debongnie
2019-09-21 09:28:56 +02:00
parent bbbaf95c8e
commit cc82b3ffcd
10 changed files with 133 additions and 101 deletions
+24
View File
@@ -920,6 +920,30 @@ describe("composition", () => {
delete QWeb.components["WidgetB"];
});
test("can use dynamic components (the class) if given", async () => {
class A extends Component<any, any, any> {
static template = xml`<span>child a</span>`;
}
class B extends Component<any, any, any> {
static template = xml`<span>child b</span>`;
}
class App extends Component<any, any, any> {
static template = xml`<t t-component="myComponent" t-key="state.child"/>`;
state = {
child: "a"
};
get myComponent() {
return this.state.child === "a" ? A : B;
}
}
const widget = new App(env);
await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<span>child a</span>");
widget.state.child = "b";
await nextTick();
expect(fixture.innerHTML).toBe("<span>child b</span>");
});
test("don't fallback to global registry if widget defined locally", async () => {
QWeb.registerComponent("WidgetB", WidgetB); // should not use this widget
env.qweb.addTemplate("ParentWidget", `<div><t t-component="WidgetB"/></div>`);