[REF] tests: remove Widget common class

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