mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[REF] tests: remove Widget common class
Bad name, and bad practice to use it. It makes tests less standalone.
This commit is contained in:
@@ -967,7 +967,7 @@ exports[`random stuff/miscellaneous snapshotting compiled code 1`] = `
|
||||
exports[`random stuff/miscellaneous t-on with handler bound to dynamic argument on a t-foreach 1`] = `
|
||||
"function anonymous(context, extra
|
||||
) {
|
||||
// Template name: \\"__template__1\\"
|
||||
// Template name: \\"__template__2\\"
|
||||
let utils = this.constructor.utils;
|
||||
let QWeb = this.constructor;
|
||||
let parent = context;
|
||||
|
||||
+319
-229
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,7 @@ import { Component, Env } from "../../src/component/component";
|
||||
import { QWeb } from "../../src/qweb/qweb";
|
||||
import { xml } from "../../src/tags";
|
||||
import { useState, useRef } from "../../src/hooks";
|
||||
import {
|
||||
makeTestFixture,
|
||||
makeTestEnv,
|
||||
nextTick,
|
||||
} from "../helpers";
|
||||
import { makeTestFixture, makeTestEnv, nextTick } from "../helpers";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Setup and helpers
|
||||
@@ -37,10 +33,10 @@ afterEach(() => {
|
||||
fixture.remove();
|
||||
});
|
||||
|
||||
function children(w: Component<any,any>): Component<any,any>[] {
|
||||
function children(w: Component<any, any>): Component<any, any>[] {
|
||||
const childrenMap = w.__owl__.children;
|
||||
return Object.keys(childrenMap).map(id => childrenMap[id]);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Tests
|
||||
@@ -62,8 +58,8 @@ describe("t-slot directive", () => {
|
||||
</div>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -160,8 +156,8 @@ describe("t-slot directive", () => {
|
||||
<span t-name="Dialog"><t t-slot="footer"/></span>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
state = useState({ val: 0 });
|
||||
doSomething() {
|
||||
@@ -197,9 +193,9 @@ describe("t-slot directive", () => {
|
||||
</div>
|
||||
</templates>
|
||||
`);
|
||||
class Link extends Component<any,any> {}
|
||||
class Link extends Component<any, any> {}
|
||||
|
||||
class App extends Component<any,any> {
|
||||
class App extends Component<any, any> {
|
||||
state = useState({
|
||||
users: [
|
||||
{ id: 1, name: "Aaron" },
|
||||
@@ -241,9 +237,9 @@ describe("t-slot directive", () => {
|
||||
</div>
|
||||
</templates>
|
||||
`);
|
||||
class Link extends Component<any,any> {}
|
||||
class Link extends Component<any, any> {}
|
||||
|
||||
class App extends Component<any,any> {
|
||||
class App extends Component<any, any> {
|
||||
state = useState({
|
||||
users: [
|
||||
{ id: 1, name: "Aaron" },
|
||||
@@ -283,9 +279,9 @@ describe("t-slot directive", () => {
|
||||
</div>
|
||||
</templates>
|
||||
`);
|
||||
class Link extends Component<any,any> {}
|
||||
class Link extends Component<any, any> {}
|
||||
|
||||
class App extends Component<any,any> {
|
||||
class App extends Component<any, any> {
|
||||
state = useState({ user: { id: 1, name: "Aaron" } });
|
||||
static components = { Link };
|
||||
}
|
||||
@@ -305,10 +301,10 @@ describe("t-slot directive", () => {
|
||||
});
|
||||
|
||||
test("refs are properly bound in slots", async () => {
|
||||
class Dialog extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {
|
||||
static template = xml`<span><t t-slot="footer"/></span>`;
|
||||
}
|
||||
class Parent extends Component<any,any> {
|
||||
class Parent extends Component<any, any> {
|
||||
static template = xml`
|
||||
<div>
|
||||
<span class="counter"><t t-esc="state.val"/></span>
|
||||
@@ -351,8 +347,8 @@ describe("t-slot directive", () => {
|
||||
<div t-name="Dialog"><t t-slot="default"/></div>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -371,8 +367,8 @@ describe("t-slot directive", () => {
|
||||
<div t-name="Dialog"><t t-slot="default"/></div>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -396,8 +392,8 @@ describe("t-slot directive", () => {
|
||||
<div t-name="Dialog"><t t-slot="content"/></div>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -419,8 +415,8 @@ describe("t-slot directive", () => {
|
||||
<div t-name="Dialog"><t t-slot="default"/></div>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -443,8 +439,8 @@ describe("t-slot directive", () => {
|
||||
</span>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -467,8 +463,8 @@ describe("t-slot directive", () => {
|
||||
</span>
|
||||
</templates>
|
||||
`);
|
||||
class Dialog extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Dialog };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -489,9 +485,9 @@ describe("t-slot directive", () => {
|
||||
<div t-name="GrandChild">Grand Child</div>
|
||||
</templates>
|
||||
`);
|
||||
class Child extends Component<any,any> {}
|
||||
class GrandChild extends Component<any,any> {}
|
||||
class Parent extends Component<any,any> {
|
||||
class Child extends Component<any, any> {}
|
||||
class GrandChild extends Component<any, any> {}
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Child, GrandChild };
|
||||
}
|
||||
const parent = new Parent();
|
||||
@@ -559,9 +555,9 @@ describe("t-slot directive", () => {
|
||||
</div>
|
||||
</templates>
|
||||
`);
|
||||
class SomeComponent extends Component<any,any> {}
|
||||
class GenericComponent extends Component<any,any> {}
|
||||
class App extends Component<any,any> {
|
||||
class SomeComponent extends Component<any, any> {}
|
||||
class GenericComponent extends Component<any, any> {}
|
||||
class App extends Component<any, any> {
|
||||
static components = { GenericComponent, SomeComponent };
|
||||
state = useState({ val: 4 });
|
||||
|
||||
@@ -598,14 +594,14 @@ describe("t-slot directive", () => {
|
||||
});
|
||||
|
||||
test("template can just return a slot", async () => {
|
||||
class Child extends Component<any,any> {
|
||||
class Child extends Component<any, any> {
|
||||
static template = xml`<span><t t-esc="props.value"/></span>`;
|
||||
}
|
||||
class SlotComponent extends Component<any,any> {
|
||||
class SlotComponent extends Component<any, any> {
|
||||
static template = xml`<t t-slot="default"/>`;
|
||||
}
|
||||
|
||||
class Parent extends Component<any,any> {
|
||||
class Parent extends Component<any, any> {
|
||||
static template = xml`
|
||||
<div>
|
||||
<SlotComponent><Child value="state.value"/></SlotComponent>
|
||||
@@ -647,14 +643,14 @@ describe("t-slot directive", () => {
|
||||
});
|
||||
|
||||
test("slots in t-foreach and re-rendering", async () => {
|
||||
class Child extends Component<any,any> {
|
||||
class Child extends Component<any, any> {
|
||||
static template = xml`<span><t t-esc="state.val"/><t t-slot="default"/></span>`;
|
||||
state = useState({ val: "A" });
|
||||
mounted() {
|
||||
this.state.val = "B";
|
||||
}
|
||||
}
|
||||
class Parent extends Component<any,any> {
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Child };
|
||||
static template = xml`
|
||||
<div>
|
||||
@@ -672,7 +668,7 @@ describe("t-slot directive", () => {
|
||||
});
|
||||
|
||||
test("slots in t-foreach with t-set and re-rendering", async () => {
|
||||
class Child extends Component<any,any> {
|
||||
class Child extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span>
|
||||
<t t-esc="state.val"/>
|
||||
@@ -683,7 +679,7 @@ describe("t-slot directive", () => {
|
||||
this.state.val = "B";
|
||||
}
|
||||
}
|
||||
class ParentWidget extends Component<any,any> {
|
||||
class ParentWidget extends Component<any, any> {
|
||||
static components = { Child };
|
||||
static template = xml`
|
||||
<div>
|
||||
@@ -704,7 +700,7 @@ describe("t-slot directive", () => {
|
||||
|
||||
test("nested slots in same template", async () => {
|
||||
let child, child2, child3;
|
||||
class Child extends Component<any,any> {
|
||||
class Child extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span id="c1">
|
||||
<div>
|
||||
@@ -716,7 +712,7 @@ describe("t-slot directive", () => {
|
||||
child = this;
|
||||
}
|
||||
}
|
||||
class Child2 extends Component<any,any> {
|
||||
class Child2 extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span id="c2">
|
||||
<t t-slot="default"/>
|
||||
@@ -726,7 +722,7 @@ describe("t-slot directive", () => {
|
||||
child2 = this;
|
||||
}
|
||||
}
|
||||
class Child3 extends Component<any,any> {
|
||||
class Child3 extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span>Child 3</span>`;
|
||||
constructor(parent, props) {
|
||||
@@ -734,7 +730,7 @@ describe("t-slot directive", () => {
|
||||
child3 = this;
|
||||
}
|
||||
}
|
||||
class Parent extends Component<any,any> {
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Child, Child2, Child3 };
|
||||
static template = xml`
|
||||
<span id="parent">
|
||||
@@ -759,7 +755,7 @@ describe("t-slot directive", () => {
|
||||
|
||||
test("t-slot nested within another slot", async () => {
|
||||
let portal, modal, child3;
|
||||
class Child3 extends Component<any,any> {
|
||||
class Child3 extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span>Child 3</span>`;
|
||||
constructor(parent, props) {
|
||||
@@ -767,7 +763,7 @@ describe("t-slot directive", () => {
|
||||
child3 = this;
|
||||
}
|
||||
}
|
||||
class Modal extends Component<any,any> {
|
||||
class Modal extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span id="modal">
|
||||
<t t-slot="default"/>
|
||||
@@ -777,7 +773,7 @@ describe("t-slot directive", () => {
|
||||
modal = this;
|
||||
}
|
||||
}
|
||||
class Portal extends Component<any,any> {
|
||||
class Portal extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span id="portal">
|
||||
<t t-slot="default"/>
|
||||
@@ -787,7 +783,7 @@ describe("t-slot directive", () => {
|
||||
portal = this;
|
||||
}
|
||||
}
|
||||
class Dialog extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {
|
||||
static components = { Modal, Portal };
|
||||
static template = xml`
|
||||
<span id="c2">
|
||||
@@ -798,7 +794,7 @@ describe("t-slot directive", () => {
|
||||
</Modal>
|
||||
</span>`;
|
||||
}
|
||||
class Parent extends Component<any,any> {
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Child3, Dialog };
|
||||
static template = xml`
|
||||
<span id="c1">
|
||||
@@ -820,7 +816,7 @@ describe("t-slot directive", () => {
|
||||
|
||||
test("t-slot supports many instances", async () => {
|
||||
let child3;
|
||||
class Child3 extends Component<any,any> {
|
||||
class Child3 extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span>Child 3</span>`;
|
||||
constructor(parent, props) {
|
||||
@@ -828,13 +824,13 @@ describe("t-slot directive", () => {
|
||||
child3 = this;
|
||||
}
|
||||
}
|
||||
class Dialog extends Component<any,any> {
|
||||
class Dialog extends Component<any, any> {
|
||||
static template = xml`
|
||||
<span id="c2">
|
||||
<t t-slot="default"/>
|
||||
</span>`;
|
||||
}
|
||||
class Parent extends Component<any,any> {
|
||||
class Parent extends Component<any, any> {
|
||||
static components = { Child3, Dialog };
|
||||
static template = xml`
|
||||
<span id="c1">
|
||||
@@ -884,4 +880,4 @@ describe("t-slot directive", () => {
|
||||
await parent.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span><p>heyaaron</p></span></div></div>");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
import { Env } from "../src/component/component";
|
||||
import { Env, Component } from "../src/component/component";
|
||||
import { scheduler } from "../src/component/scheduler";
|
||||
import { EvalContext, QWeb } from "../src/qweb/qweb";
|
||||
import { CompilationContext } from "../src/qweb/compilation_context";
|
||||
@@ -25,6 +25,7 @@ beforeEach(() => {
|
||||
slots = Object.assign({}, QWeb.slots);
|
||||
nextId = QWeb.nextId;
|
||||
TEMPLATES = Object.assign({}, QWeb.TEMPLATES);
|
||||
Component.scheduler.tasks = [];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -32,6 +33,7 @@ afterEach(() => {
|
||||
QWeb.slots = slots;
|
||||
QWeb.nextId = nextId;
|
||||
QWeb.TEMPLATES = TEMPLATES;
|
||||
Component.scheduler.tasks = [];
|
||||
});
|
||||
|
||||
// helpers
|
||||
|
||||
@@ -318,7 +318,8 @@ describe("t-set", () => {
|
||||
<t t-set="v1" t-value="'after'"/>
|
||||
<t t-set="v3" t-value="true"/>
|
||||
<t t-raw="v2"/>
|
||||
</div>`);
|
||||
</div>`
|
||||
);
|
||||
|
||||
expect(renderToString(qweb, "test")).toBe("<div><span>before</span></div>");
|
||||
});
|
||||
@@ -335,7 +336,8 @@ describe("t-set", () => {
|
||||
<t t-set="v1" t-value="'after'"/>
|
||||
<t t-set="v3" t-value="false"/>
|
||||
<t t-raw="v2"/>
|
||||
</div>`);
|
||||
</div>`
|
||||
);
|
||||
|
||||
expect(renderToString(qweb, "test")).toBe("<div>Truthy</div>");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user