mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
@@ -173,10 +173,7 @@ describe("animations", () => {
|
||||
test("t-transition combined with component", async () => {
|
||||
expect.assertions(5);
|
||||
|
||||
env.qweb.addTemplate(
|
||||
"Parent",
|
||||
`<div><Child t-transition="chimay"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("Parent", `<div><Child t-transition="chimay"/></div>`);
|
||||
env.qweb.addTemplate("Child", `<span>blue</span>`);
|
||||
class Parent extends Widget {
|
||||
components = { Child: Child };
|
||||
@@ -320,9 +317,7 @@ describe("animations", () => {
|
||||
expect(spans.length).toBe(1);
|
||||
expect(spans[0].className).toBe(`chimay-${phase} chimay-${phase}-active`);
|
||||
cb();
|
||||
expect(spans[0].className).toBe(
|
||||
`chimay-${phase}-active chimay-${phase}-to`
|
||||
);
|
||||
expect(spans[0].className).toBe(`chimay-${phase}-active chimay-${phase}-to`);
|
||||
def.resolve();
|
||||
});
|
||||
|
||||
@@ -330,9 +325,7 @@ describe("animations", () => {
|
||||
button!.click();
|
||||
await def; // wait for the mocked repaint to be done
|
||||
widget.el!.querySelector("span")!.dispatchEvent(new Event("transitionend")); // mock end of css transition
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><button>Toggle</button><span class="">blue</span></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div><button>Toggle</button><span class="">blue</span></div>');
|
||||
|
||||
// click to remove the span, and click again to re-add it before transitionend
|
||||
def = makeDeferred();
|
||||
@@ -346,9 +339,7 @@ describe("animations", () => {
|
||||
|
||||
await def; // wait for the mocked repaint to be done
|
||||
widget.el!.querySelector("span")!.dispatchEvent(new Event("transitionend")); // mock end of css transition
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><button>Toggle</button><span class="">blue</span></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div><button>Toggle</button><span class="">blue</span></div>');
|
||||
});
|
||||
|
||||
test("t-transition combined with t-component, remove and re-add before transitionend", async () => {
|
||||
@@ -386,9 +377,7 @@ describe("animations", () => {
|
||||
expect(spans.length).toBe(1);
|
||||
expect(spans[0].className).toBe(`chimay-${phase} chimay-${phase}-active`);
|
||||
cb();
|
||||
expect(spans[0].className).toBe(
|
||||
`chimay-${phase}-active chimay-${phase}-to`
|
||||
);
|
||||
expect(spans[0].className).toBe(`chimay-${phase}-active chimay-${phase}-to`);
|
||||
def.resolve();
|
||||
});
|
||||
|
||||
@@ -396,9 +385,7 @@ describe("animations", () => {
|
||||
button!.click();
|
||||
await def; // wait for the mocked repaint to be done
|
||||
widget.el!.querySelector("span")!.dispatchEvent(new Event("transitionend")); // mock end of css transition
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><button>Toggle</button><span class="">blue</span></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div><button>Toggle</button><span class="">blue</span></div>');
|
||||
|
||||
// click to remove the span, and click again to re-add it before transitionend
|
||||
def = makeDeferred();
|
||||
@@ -412,8 +399,6 @@ describe("animations", () => {
|
||||
|
||||
await def; // wait for the mocked repaint to be done
|
||||
widget.el!.querySelector("span")!.dispatchEvent(new Event("transitionend")); // mock end of css transition
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><button>Toggle</button><span class="">blue</span></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div><button>Toggle</button><span class="">blue</span></div>');
|
||||
});
|
||||
});
|
||||
|
||||
+60
-202
@@ -92,9 +92,7 @@ describe("basic widget properties", () => {
|
||||
try {
|
||||
await widget.mount(fixture);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe(
|
||||
'Could not find template for component "SomeWidget"'
|
||||
);
|
||||
expect(e.message).toBe('Could not find template for component "SomeWidget"');
|
||||
}
|
||||
});
|
||||
|
||||
@@ -128,9 +126,7 @@ describe("basic widget properties", () => {
|
||||
class StyledWidget extends Widget {}
|
||||
const widget = new StyledWidget(env);
|
||||
await widget.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
`<div style="font-weight:bold;" class="some-class">world</div>`
|
||||
);
|
||||
expect(fixture.innerHTML).toBe(`<div style="font-weight:bold;" class="some-class">world</div>`);
|
||||
});
|
||||
|
||||
test("changing state before first render does not trigger a render", async () => {
|
||||
@@ -249,10 +245,7 @@ describe("lifecycle hooks", () => {
|
||||
"ParentWidget",
|
||||
`<div><t t-if="state.flag"><t t-component="child"/></t></div>`
|
||||
);
|
||||
env.qweb.addTemplate(
|
||||
"ChildWidget",
|
||||
`<div><t t-component="childchild"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ChildWidget", `<div><t t-component="childchild"/></div>`);
|
||||
|
||||
class ParentWidget extends Widget {
|
||||
components = { child: ChildWidget };
|
||||
@@ -300,10 +293,7 @@ describe("lifecycle hooks", () => {
|
||||
test("willPatch, patched hook are called on subsubcomponents, in proper order", async () => {
|
||||
const steps: any[] = [];
|
||||
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="child" n="state.n"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="child" n="state.n"/></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
components = { child: ChildWidget };
|
||||
state = { n: 1 };
|
||||
@@ -314,10 +304,7 @@ describe("lifecycle hooks", () => {
|
||||
steps.push("parent:patched");
|
||||
}
|
||||
}
|
||||
env.qweb.addTemplate(
|
||||
"ChildWidget",
|
||||
`<div><t t-component="childchild" n="props.n"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ChildWidget", `<div><t t-component="childchild" n="props.n"/></div>`);
|
||||
class ChildWidget extends Widget {
|
||||
components = { childchild: ChildChildWidget };
|
||||
willPatch() {
|
||||
@@ -780,11 +767,7 @@ describe("lifecycle hooks", () => {
|
||||
expect(steps).toEqual(["child:mounted", "child:willUnmount"]);
|
||||
widget.state.flag = true;
|
||||
await nextTick();
|
||||
expect(steps).toEqual([
|
||||
"child:mounted",
|
||||
"child:willUnmount",
|
||||
"child:mounted"
|
||||
]);
|
||||
expect(steps).toEqual(["child:mounted", "child:willUnmount", "child:mounted"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -859,10 +842,7 @@ describe("composition", () => {
|
||||
|
||||
test("can use components from the global registry", async () => {
|
||||
QWeb.register("WidgetB", WidgetB);
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="WidgetB"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="WidgetB"/></div>`);
|
||||
class ParentWidget extends Widget {}
|
||||
const widget = new ParentWidget(env);
|
||||
await widget.mount(fixture);
|
||||
@@ -872,10 +852,7 @@ describe("composition", () => {
|
||||
|
||||
test("don't fallback to global registry if widget defined locally", async () => {
|
||||
QWeb.register("WidgetB", WidgetB); // should not use this widget
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="WidgetB"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="WidgetB"/></div>`);
|
||||
env.qweb.addTemplate("AnotherWidgetB", `<span>Belgium</span>`);
|
||||
class AnotherWidgetB extends Widget {}
|
||||
class ParentWidget extends Widget {
|
||||
@@ -912,17 +889,12 @@ describe("composition", () => {
|
||||
try {
|
||||
await parent.mount(fixture);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe(
|
||||
'Cannot find the definition of component "SomeMispelledWidget"'
|
||||
);
|
||||
expect(e.message).toBe('Cannot find the definition of component "SomeMispelledWidget"');
|
||||
}
|
||||
});
|
||||
|
||||
test("t-refs on widget are components", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"WidgetC",
|
||||
`<div>Hello<t t-ref="mywidgetb" t-component="b"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("WidgetC", `<div>Hello<t t-ref="mywidgetb" t-component="b"/></div>`);
|
||||
class WidgetC extends Widget {
|
||||
components = { b: WidgetB };
|
||||
}
|
||||
@@ -1007,24 +979,17 @@ describe("composition", () => {
|
||||
});
|
||||
|
||||
test("modifying a sub widget", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="Counter"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="Counter"/></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
components = { Counter };
|
||||
}
|
||||
const widget = new ParentWidget(env);
|
||||
await widget.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>0<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>0<button>Inc</button></div></div>");
|
||||
const button = fixture.getElementsByTagName("button")[0];
|
||||
await button.click();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>1<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||
});
|
||||
|
||||
test("refs in a loop", async () => {
|
||||
@@ -1066,10 +1031,7 @@ describe("composition", () => {
|
||||
});
|
||||
|
||||
test("rerendering a widget with a sub widget", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="Counter"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="Counter"/></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
components = { Counter };
|
||||
}
|
||||
@@ -1078,20 +1040,13 @@ describe("composition", () => {
|
||||
const button = fixture.getElementsByTagName("button")[0];
|
||||
await button.click();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>1<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||
await widget.render();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>1<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||
});
|
||||
|
||||
test("sub components are destroyed if no longer in dom, then recreated", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-if="state.ok"><Counter /></t></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-if="state.ok"><Counter /></t></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
state = { ok: true };
|
||||
components = { Counter };
|
||||
@@ -1101,18 +1056,14 @@ describe("composition", () => {
|
||||
const button = fixture.getElementsByTagName("button")[0];
|
||||
await button.click();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>1<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||
widget.state.ok = false;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("<div></div>");
|
||||
|
||||
widget.state.ok = true;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>0<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>0<button>Inc</button></div></div>");
|
||||
});
|
||||
|
||||
test("sub components with t-keepalive are not destroyed if no longer in dom", async () => {
|
||||
@@ -1129,9 +1080,7 @@ describe("composition", () => {
|
||||
const button = fixture.getElementsByTagName("button")[0];
|
||||
await button.click();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>1<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||
const counter = children(widget)[0];
|
||||
expect(counter.__owl__.isMounted).toBe(true);
|
||||
|
||||
@@ -1143,9 +1092,7 @@ describe("composition", () => {
|
||||
widget.state.ok = true;
|
||||
await nextTick();
|
||||
expect(counter.__owl__.isMounted).toBe(true);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div>1<button>Inc</button></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div>1<button>Inc</button></div></div>");
|
||||
});
|
||||
|
||||
test("sub components dom state with t-keepalive is preserved", async () => {
|
||||
@@ -1320,10 +1267,7 @@ describe("composition", () => {
|
||||
});
|
||||
|
||||
test("t-component with dynamic value", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="{{state.widget}}"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="{{state.widget}}"/></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
components = { WidgetB };
|
||||
state = { widget: "WidgetB" };
|
||||
@@ -1335,10 +1279,7 @@ describe("composition", () => {
|
||||
});
|
||||
|
||||
test("t-component with dynamic value 2", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="Widget{{state.widget}}"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="Widget{{state.widget}}"/></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
components = { WidgetB };
|
||||
state = { widget: "B" };
|
||||
@@ -1352,10 +1293,7 @@ describe("composition", () => {
|
||||
|
||||
describe("props evaluation ", () => {
|
||||
test("explicit object prop", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"Parent",
|
||||
`<div><t t-component="child" value="state.val"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("Parent", `<div><t t-component="child" value="state.val"/></div>`);
|
||||
class Parent extends Widget {
|
||||
components = { child: Child };
|
||||
state = { val: 42 };
|
||||
@@ -1379,10 +1317,7 @@ describe("props evaluation ", () => {
|
||||
env.qweb.addTemplate("Child", `<span><t t-esc="props.greetings"/></span>`);
|
||||
class Child extends Widget {}
|
||||
|
||||
env.qweb.addTemplate(
|
||||
"Parent",
|
||||
`<div><t t-component="child" greetings="greetings"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("Parent", `<div><t t-component="child" greetings="greetings"/></div>`);
|
||||
class Parent extends Widget {
|
||||
components = { child: Child };
|
||||
get greetings() {
|
||||
@@ -1600,9 +1535,7 @@ describe("class and style attributes with t-component", () => {
|
||||
}
|
||||
const widget = new ParentWidget(env);
|
||||
await widget.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
`<div><div style="font-weight: bold;"></div></div>`
|
||||
);
|
||||
expect(fixture.innerHTML).toBe(`<div><div style="font-weight: bold;"></div></div>`);
|
||||
});
|
||||
|
||||
test("dynamic t-att-style is properly added and updated on widget root el", async () => {
|
||||
@@ -1622,16 +1555,12 @@ describe("class and style attributes with t-component", () => {
|
||||
|
||||
expect(env.qweb.templates.ParentWidget.fn.toString()).toMatchSnapshot();
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
`<div><div style="font-size: 20px;"></div></div>`
|
||||
);
|
||||
expect(fixture.innerHTML).toBe(`<div><div style="font-size: 20px;"></div></div>`);
|
||||
|
||||
widget.state.style = "font-size: 30px";
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
`<div><div style="font-size: 30px;"></div></div>`
|
||||
);
|
||||
expect(fixture.innerHTML).toBe(`<div><div style="font-size: 30px;"></div></div>`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1891,10 +1820,7 @@ describe("other directives with t-component", () => {
|
||||
});
|
||||
|
||||
test("t-if works with t-component", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"ParentWidget",
|
||||
`<div><t t-component="child" t-if="state.flag"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("ParentWidget", `<div><t t-component="child" t-if="state.flag"/></div>`);
|
||||
class ParentWidget extends Widget {
|
||||
components = { child: Child };
|
||||
state = { flag: true };
|
||||
@@ -2044,19 +1970,13 @@ describe("random stuff/miscellaneous", () => {
|
||||
// in this situation, we protect against a bug that occurred: because of the
|
||||
// interplay between components and vnodes, a sub widget vnode was patched
|
||||
// twice.
|
||||
env.qweb.addTemplate(
|
||||
"Parent",
|
||||
`<div><t t-component="child" flag="state.flag"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("Parent", `<div><t t-component="child" flag="state.flag"/></div>`);
|
||||
class Parent extends Widget {
|
||||
components = { child: Child };
|
||||
state = { flag: false };
|
||||
}
|
||||
|
||||
env.qweb.addTemplate(
|
||||
"Child",
|
||||
`<span>abc<t t-if="props.flag">def</t></span>`
|
||||
);
|
||||
env.qweb.addTemplate("Child", `<span>abc<t t-if="props.flag">def</t></span>`);
|
||||
class Child extends Widget {}
|
||||
|
||||
const widget = new Parent(env);
|
||||
@@ -2077,10 +1997,7 @@ describe("random stuff/miscellaneous", () => {
|
||||
state = { flag: false };
|
||||
}
|
||||
|
||||
env.qweb.addTemplate(
|
||||
"Child",
|
||||
`<span>abc<t t-if="props.flag">def</t></span>`
|
||||
);
|
||||
env.qweb.addTemplate("Child", `<span>abc<t t-if="props.flag">def</t></span>`);
|
||||
class Child extends Widget {}
|
||||
|
||||
const widget = new Parent(env);
|
||||
@@ -2190,9 +2107,7 @@ describe("random stuff/miscellaneous", () => {
|
||||
|
||||
const a = new A(env);
|
||||
await a.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
`<div>A<div>B</div><div>C<div>D</div><div>E</div></div></div>`
|
||||
);
|
||||
expect(fixture.innerHTML).toBe(`<div>A<div>B</div><div>C<div>D</div><div>E</div></div></div>`);
|
||||
expect(steps).toEqual([
|
||||
"A:willStart",
|
||||
"A:render",
|
||||
@@ -2267,10 +2182,7 @@ describe("async rendering", () => {
|
||||
test("destroying/recreating a subwidget with different props (if start is not over)", async () => {
|
||||
let def = makeDeferred();
|
||||
let n = 0;
|
||||
env.qweb.addTemplate(
|
||||
"W",
|
||||
`<div><t t-if="state.val > 1"><Child val="state.val"/></t></div>`
|
||||
);
|
||||
env.qweb.addTemplate("W", `<div><t t-if="state.val > 1"><Child val="state.val"/></t></div>`);
|
||||
class W extends Widget {
|
||||
components = { Child };
|
||||
state = { val: 1 };
|
||||
@@ -2380,23 +2292,15 @@ describe("async rendering", () => {
|
||||
}
|
||||
const parent = new Parent(env);
|
||||
await parent.mount(fixture);
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe(
|
||||
"<div><span>a1</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe("<div><span>a1</span></div>");
|
||||
parent.state.valA = 2;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe(
|
||||
"<div><span>a1</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe("<div><span>a1</span></div>");
|
||||
parent.state.flagB = true;
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe(
|
||||
"<div><span>a1</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe("<div><span>a1</span></div>");
|
||||
defB.resolve();
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe(
|
||||
"<div><span>a1</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe("<div><span>a1</span></div>");
|
||||
defA.resolve();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML.replace(/\r?\n|\r|\s+/g, "")).toBe(
|
||||
@@ -2569,25 +2473,19 @@ describe("async rendering", () => {
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(env.qweb.templates.Parent.fn.toString()).toMatchSnapshot();
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>0</span><span>0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>0</span><span>0</span>");
|
||||
|
||||
// click on button to increment Parent counter
|
||||
def = makeDeferred();
|
||||
fixture.querySelector("button")!.click();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1</span><span>0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1</span><span>0</span>");
|
||||
|
||||
def.resolve();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1</span><span>1</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1</span><span>1</span>");
|
||||
});
|
||||
|
||||
test("fast component with t-asyncroot directive", async () => {
|
||||
@@ -2624,25 +2522,19 @@ describe("async rendering", () => {
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(env.qweb.templates.Parent.fn.toString()).toMatchSnapshot();
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>0</span><span>0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>0</span><span>0</span>");
|
||||
|
||||
// click on button to increment Parent counter
|
||||
def = makeDeferred();
|
||||
fixture.querySelector("button")!.click();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1</span><span>0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1</span><span>0</span>");
|
||||
|
||||
def.resolve();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1</span><span>1</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1</span><span>1</span>");
|
||||
});
|
||||
|
||||
test("t-component with t-asyncroot directive: mixed re-renderings", async () => {
|
||||
@@ -2687,40 +2579,30 @@ describe("async rendering", () => {
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(env.qweb.templates.Parent.fn.toString()).toMatchSnapshot();
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>0/0</span><span>0/0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>0/0</span><span>0/0</span>");
|
||||
|
||||
// click on button to increment Parent counter
|
||||
def = makeDeferred();
|
||||
fixture.querySelector("button")!.click();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>0/1</span><span>0/0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>0/1</span><span>0/0</span>");
|
||||
|
||||
// click on each Child to increment their local counter
|
||||
const children = parent.el!.querySelectorAll("span");
|
||||
children[0]!.click();
|
||||
await nextTick();
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1/1</span><span>0/0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1/1</span><span>0/0</span>");
|
||||
|
||||
children[1]!.click();
|
||||
await nextTick();
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1/1</span><span>1/0</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1/1</span><span>1/0</span>");
|
||||
|
||||
// finalize first re-rendering (coming from the props update)
|
||||
def.resolve();
|
||||
await nextTick();
|
||||
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe(
|
||||
"<span>1/1</span><span>1/1</span>"
|
||||
);
|
||||
expect(fixture.querySelector(".children")!.innerHTML).toBe("<span>1/1</span><span>1/1</span>");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2860,9 +2742,7 @@ describe("widget and observable state", () => {
|
||||
try {
|
||||
await parent.mount(fixture);
|
||||
} catch (e) {
|
||||
expect(e.message).toBe(
|
||||
'Observed state cannot be changed here! (key: "coffee", val: "2")'
|
||||
);
|
||||
expect(e.message).toBe('Observed state cannot be changed here! (key: "coffee", val: "2")');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -2903,10 +2783,7 @@ describe("t-mounted directive", () => {
|
||||
});
|
||||
|
||||
test("combined with a t-if", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"TestWidget",
|
||||
`<div><input t-if="state.flag" t-mounted="f"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("TestWidget", `<div><input t-if="state.flag" t-mounted="f"/></div>`);
|
||||
class TestWidget extends Widget {
|
||||
state = { flag: false };
|
||||
f() {}
|
||||
@@ -2922,10 +2799,7 @@ describe("t-mounted directive", () => {
|
||||
});
|
||||
|
||||
test("combined with a t-ref", async () => {
|
||||
env.qweb.addTemplate(
|
||||
"TestWidget",
|
||||
`<div><input t-ref="input" t-mounted="f"/></div>`
|
||||
);
|
||||
env.qweb.addTemplate("TestWidget", `<div><input t-ref="input" t-mounted="f"/></div>`);
|
||||
class TestWidget extends Widget {
|
||||
f() {}
|
||||
}
|
||||
@@ -3099,9 +2973,7 @@ describe("t-slot directive", () => {
|
||||
const parent = new Parent(env);
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div><span>sts rocks</span></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>sts rocks</span></div></div>");
|
||||
});
|
||||
|
||||
test("default slot work with text nodes", async () => {
|
||||
@@ -3144,9 +3016,7 @@ describe("t-slot directive", () => {
|
||||
const parent = new Parent(env);
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div><span>sts</span><span>rocks</span></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>sts</span><span>rocks</span></div></div>");
|
||||
});
|
||||
|
||||
test("multiple roots are allowed in a default slot", async () => {
|
||||
@@ -3168,9 +3038,7 @@ describe("t-slot directive", () => {
|
||||
const parent = new Parent(env);
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div><span>sts</span><span>rocks</span></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>sts</span><span>rocks</span></div></div>");
|
||||
});
|
||||
|
||||
test("missing slots are ignored", async () => {
|
||||
@@ -3193,9 +3061,7 @@ describe("t-slot directive", () => {
|
||||
const parent = new Parent(env);
|
||||
await parent.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><span><span>some content</span></span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><span><span>some content</span></span></div>");
|
||||
});
|
||||
|
||||
test("t-debug on a t-set (defining a slot)", async () => {
|
||||
@@ -3264,16 +3130,12 @@ describe("t-model directive", () => {
|
||||
const comp = new SomeComponent(env);
|
||||
await comp.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><input type="checkbox"><span>no</span></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div><input type="checkbox"><span>no</span></div>');
|
||||
|
||||
let input = fixture.querySelector("input")!;
|
||||
input.click();
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div><input type="checkbox"><span>yes</span></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div><input type="checkbox"><span>yes</span></div>');
|
||||
expect(comp.state.flag).toBe(true);
|
||||
expect(env.qweb.templates.SomeComponent.fn.toString()).toMatchSnapshot();
|
||||
|
||||
@@ -3296,16 +3158,12 @@ describe("t-model directive", () => {
|
||||
const comp = new SomeComponent(env);
|
||||
await comp.mount(fixture);
|
||||
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><textarea></textarea><span></span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><textarea></textarea><span></span></div>");
|
||||
|
||||
const textarea = fixture.querySelector("textarea")!;
|
||||
await editInput(textarea, "test");
|
||||
expect(comp.state.text).toBe("test");
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><textarea></textarea><span>test</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><textarea></textarea><span>test</span></div>");
|
||||
});
|
||||
|
||||
test("on an input type=radio", async () => {
|
||||
|
||||
@@ -52,15 +52,11 @@ interface FileData {
|
||||
sections: MarkDownSection[];
|
||||
}
|
||||
|
||||
function isLinkValid(
|
||||
link: MarkDownLink,
|
||||
current: FileData,
|
||||
files: FileData[]
|
||||
): boolean {
|
||||
function isLinkValid(link: MarkDownLink, current: FileData, files: FileData[]): boolean {
|
||||
const parts = link.link.split("#");
|
||||
const currentParts = current.name.split("/");
|
||||
const path = currentParts.length > 1 ? currentParts[0] + '/' : "";
|
||||
const fullName = path + parts[0];
|
||||
const path = currentParts.length > 1 ? currentParts[0] + "/" : "";
|
||||
const fullName = path + parts[0];
|
||||
if (parts.length === 1) {
|
||||
// no # in url
|
||||
if (parts[0].endsWith(".md")) {
|
||||
@@ -70,8 +66,7 @@ function isLinkValid(
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const file =
|
||||
parts[0] === "" ? current : files.find(f => f.name === fullName);
|
||||
const file = parts[0] === "" ? current : files.find(f => f.name === fullName);
|
||||
if (!file) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ describe("event bus behaviour", () => {
|
||||
test("throw error if callback is undefined", () => {
|
||||
expect.assertions(1);
|
||||
const bus = new EventBus();
|
||||
expect(() => bus.on("event", {}, <any>undefined)).toThrow(
|
||||
`Missing callback`
|
||||
);
|
||||
expect(() => bus.on("event", {}, <any>undefined)).toThrow(`Missing callback`);
|
||||
});
|
||||
|
||||
test("can unsubscribe", () => {
|
||||
|
||||
+2
-9
@@ -68,11 +68,7 @@ export function renderToDOM(
|
||||
return result.elm as HTMLElement;
|
||||
}
|
||||
|
||||
export function renderToString(
|
||||
qweb: QWeb,
|
||||
t: string,
|
||||
context: EvalContext = {}
|
||||
): string {
|
||||
export function renderToString(qweb: QWeb, t: string, context: EvalContext = {}): string {
|
||||
const node = renderToDOM(qweb, t, context);
|
||||
return node instanceof Text ? node.textContent! : node.outerHTML;
|
||||
}
|
||||
@@ -92,10 +88,7 @@ export function unpatchNextFrame() {
|
||||
UTILS.nextFrame = nextFrame;
|
||||
}
|
||||
|
||||
export async function editInput(
|
||||
input: HTMLInputElement | HTMLTextAreaElement,
|
||||
value: string
|
||||
) {
|
||||
export async function editInput(input: HTMLInputElement | HTMLTextAreaElement, value: string) {
|
||||
input.value = value;
|
||||
input.dispatchEvent(new Event("input"));
|
||||
input.dispatchEvent(new Event("change"));
|
||||
|
||||
@@ -126,7 +126,6 @@ describe("props validation", () => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test("can validate a prop with multiple types", async () => {
|
||||
let TestWidget = class extends Widget {
|
||||
static props = { p: [String, Boolean] };
|
||||
@@ -149,16 +148,14 @@ describe("props validation", () => {
|
||||
|
||||
expect(() => {
|
||||
new TestWidget(env, { p: "hey" });
|
||||
new TestWidget(env, { });
|
||||
new TestWidget(env, {});
|
||||
}).not.toThrow();
|
||||
|
||||
expect(() => {
|
||||
new TestWidget(env, { p: 1 });
|
||||
}).toThrow();
|
||||
|
||||
});
|
||||
|
||||
|
||||
test("can validate an array with given primitive type", async () => {
|
||||
let TestWidget = class extends Widget {
|
||||
static props = { p: { type: Array, element: String } };
|
||||
@@ -222,7 +219,7 @@ describe("props validation", () => {
|
||||
type: Object,
|
||||
shape: {
|
||||
id: Number,
|
||||
url: [Boolean, {type: Array, element: Number}],
|
||||
url: [Boolean, { type: Array, element: Number }]
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -230,21 +227,19 @@ describe("props validation", () => {
|
||||
|
||||
expect(() => {
|
||||
new TestWidget(env, { p: { id: 1, url: true } });
|
||||
new TestWidget(env, { p: { id: 1, url: [12]} });
|
||||
new TestWidget(env, { p: { id: 1, url: [12] } });
|
||||
}).not.toThrow();
|
||||
|
||||
expect(() => {
|
||||
new TestWidget(env, { p: { id: 1, url: [12, true]} });
|
||||
new TestWidget(env, { p: { id: 1, url: [12, true] } });
|
||||
}).toThrow();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe("default props", () => {
|
||||
test("can set default values", async () => {
|
||||
class TestWidget extends Widget {
|
||||
static defaultProps = {p: 4}
|
||||
static defaultProps = { p: 4 };
|
||||
}
|
||||
|
||||
const w = new TestWidget(env, {});
|
||||
@@ -253,10 +248,10 @@ describe("default props", () => {
|
||||
|
||||
test("default values are also set whenever component is updated", async () => {
|
||||
class TestWidget extends Widget {
|
||||
static defaultProps = {p: 4}
|
||||
static defaultProps = { p: 4 };
|
||||
}
|
||||
|
||||
const w = new TestWidget(env, {p: 1});
|
||||
const w = new TestWidget(env, { p: 1 });
|
||||
await w.__updateProps({});
|
||||
expect(w.props.p).toBe(4);
|
||||
});
|
||||
|
||||
+35
-111
@@ -26,9 +26,7 @@ describe("static templates", () => {
|
||||
|
||||
test("simple dynamic value", () => {
|
||||
qweb.addTemplate("test", '<t><t t-esc="text"/></t>');
|
||||
expect(renderToString(qweb, "test", { text: "hello vdom" })).toBe(
|
||||
"hello vdom"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { text: "hello vdom" })).toBe("hello vdom");
|
||||
});
|
||||
|
||||
test("simple string, with some dynamic value", () => {
|
||||
@@ -54,9 +52,7 @@ describe("static templates", () => {
|
||||
|
||||
describe("error handling", () => {
|
||||
test("invalid xml", () => {
|
||||
expect(() => qweb.addTemplate("test", "<div>")).toThrow(
|
||||
"Invalid XML in template"
|
||||
);
|
||||
expect(() => qweb.addTemplate("test", "<div>")).toThrow("Invalid XML in template");
|
||||
});
|
||||
|
||||
test("template with text node and tag", () => {
|
||||
@@ -73,9 +69,7 @@ describe("error handling", () => {
|
||||
|
||||
test("cannot add twice the same template", () => {
|
||||
qweb.addTemplate("test", `<t></t>`);
|
||||
expect(() => qweb.addTemplate("test", "<div/>", true)).not.toThrow(
|
||||
"already defined"
|
||||
);
|
||||
expect(() => qweb.addTemplate("test", "<div/>", true)).not.toThrow("already defined");
|
||||
expect(() => qweb.addTemplate("test", "<div/>")).toThrow("already defined");
|
||||
});
|
||||
|
||||
@@ -94,19 +88,14 @@ describe("error handling", () => {
|
||||
|
||||
test("nice error when t-on is evaluated with a missing event", () => {
|
||||
qweb.addTemplate("templatename", `<div t-on="somemethod"></div>`);
|
||||
expect(() =>
|
||||
qweb.render("templatename", { someMethod() {} }, { handlers: [] })
|
||||
).toThrow("Missing event name with t-on directive");
|
||||
expect(() => qweb.render("templatename", { someMethod() {} }, { handlers: [] })).toThrow(
|
||||
"Missing event name with t-on directive"
|
||||
);
|
||||
});
|
||||
|
||||
test("error when unknown directive", () => {
|
||||
qweb.addTemplate(
|
||||
"templatename",
|
||||
`<div t-best-beer="rochefort 10">test</div>`
|
||||
);
|
||||
expect(() => qweb.render("templatename")).toThrow(
|
||||
"Unknown QWeb directive: 't-best-beer'"
|
||||
);
|
||||
qweb.addTemplate("templatename", `<div t-best-beer="rochefort 10">test</div>`);
|
||||
expect(() => qweb.render("templatename")).toThrow("Unknown QWeb directive: 't-best-beer'");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -123,9 +112,7 @@ describe("t-esc", () => {
|
||||
|
||||
test.skip("escaping", () => {
|
||||
qweb.addTemplate("test", `<span><t t-esc="var"/></span>`);
|
||||
expect(renderToString(qweb, "test", { var: "<ok>" })).toBe(
|
||||
"<span><ok></span>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { var: "<ok>" })).toBe("<span><ok></span>");
|
||||
});
|
||||
|
||||
test("escaping on a node", () => {
|
||||
@@ -157,9 +144,7 @@ describe("t-raw", () => {
|
||||
|
||||
test("not escaping", () => {
|
||||
qweb.addTemplate("test", `<div><t t-raw="var"/></div>`);
|
||||
expect(renderToString(qweb, "test", { var: "<ok></ok>" })).toBe(
|
||||
"<div><ok></ok></div>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { var: "<ok></ok>" })).toBe("<div><ok></ok></div>");
|
||||
});
|
||||
|
||||
test("t-raw and another sibling node", () => {
|
||||
@@ -172,10 +157,7 @@ describe("t-raw", () => {
|
||||
|
||||
describe("t-set", () => {
|
||||
test("set from attribute literal", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div><t t-set="value" t-value="'ok'"/><t t-esc="value"/></div>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div><t t-set="value" t-value="'ok'"/><t t-esc="value"/></div>`);
|
||||
expect(renderToString(qweb, "test")).toBe("<div>ok</div>");
|
||||
});
|
||||
|
||||
@@ -187,24 +169,16 @@ describe("t-set", () => {
|
||||
<t t-if="v === 'ok'">grimbergen</t>
|
||||
</div>`
|
||||
);
|
||||
expect(renderToString(qweb, "test", { value: "ok" })).toBe(
|
||||
"<div>grimbergen</div>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { value: "ok" })).toBe("<div>grimbergen</div>");
|
||||
});
|
||||
|
||||
test("set from body literal", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<t><t t-set="value">ok</t><t t-esc="value"/></t>`
|
||||
);
|
||||
qweb.addTemplate("test", `<t><t t-set="value">ok</t><t t-esc="value"/></t>`);
|
||||
expect(renderToString(qweb, "test")).toBe("ok");
|
||||
});
|
||||
|
||||
test("set from attribute lookup", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div><t t-set="stuff" t-value="value"/><t t-esc="stuff"/></div>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div><t t-set="stuff" t-value="value"/><t t-esc="stuff"/></div>`);
|
||||
expect(renderToString(qweb, "test", { value: "ok" })).toBe("<div>ok</div>");
|
||||
});
|
||||
|
||||
@@ -236,18 +210,12 @@ describe("t-set", () => {
|
||||
});
|
||||
|
||||
test("value priority", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div><t t-set="value" t-value="1">2</t><t t-esc="value"/></div>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div><t t-set="value" t-value="1">2</t><t t-esc="value"/></div>`);
|
||||
expect(renderToString(qweb, "test")).toBe("<div>1</div>");
|
||||
});
|
||||
|
||||
test("evaluate value expression", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div><t t-set="value" t-value="1 + 2"/><t t-esc="value"/></div>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div><t t-set="value" t-value="1 + 2"/><t t-esc="value"/></div>`);
|
||||
expect(renderToString(qweb, "test")).toBe("<div>3</div>");
|
||||
});
|
||||
|
||||
@@ -272,25 +240,19 @@ describe("t-set", () => {
|
||||
"test",
|
||||
`<div><t t-set="value" t-value="somevariable + 2"/><t t-esc="value"/></div>`
|
||||
);
|
||||
expect(renderToString(qweb, "test", { somevariable: 43 })).toBe(
|
||||
"<div>45</div>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { somevariable: 43 })).toBe("<div>45</div>");
|
||||
});
|
||||
});
|
||||
|
||||
describe("t-if", () => {
|
||||
test("boolean value true condition", () => {
|
||||
qweb.addTemplate("test", `<div><t t-if="condition">ok</t></div>`);
|
||||
expect(renderToString(qweb, "test", { condition: true })).toBe(
|
||||
"<div>ok</div>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { condition: true })).toBe("<div>ok</div>");
|
||||
});
|
||||
|
||||
test("boolean value false condition", () => {
|
||||
qweb.addTemplate("test", `<div><t t-if="condition">ok</t></div>`);
|
||||
expect(renderToString(qweb, "test", { condition: false })).toBe(
|
||||
"<div></div>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { condition: false })).toBe("<div></div>");
|
||||
});
|
||||
|
||||
test("boolean value condition missing", () => {
|
||||
@@ -307,9 +269,7 @@ describe("t-if", () => {
|
||||
<t t-else="">beer</t></div>
|
||||
`
|
||||
);
|
||||
expect(renderToString(qweb, "test", { color: "red" })).toBe(
|
||||
"<div>red is dead</div>"
|
||||
);
|
||||
expect(renderToString(qweb, "test", { color: "red" })).toBe("<div>red is dead</div>");
|
||||
});
|
||||
|
||||
test("boolean value condition else", () => {
|
||||
@@ -335,9 +295,7 @@ describe("t-if", () => {
|
||||
`
|
||||
);
|
||||
const result = trim(renderToString(qweb, "test", { condition: false }));
|
||||
expect(result).toBe(
|
||||
"<div><span>begin</span>fail-else<span>end</span></div>"
|
||||
);
|
||||
expect(result).toBe("<div><span>begin</span>fail-else<span>end</span></div>");
|
||||
});
|
||||
|
||||
test("can use some boolean operators in expressions", () => {
|
||||
@@ -362,9 +320,7 @@ describe("t-if", () => {
|
||||
m: 5,
|
||||
n: 2
|
||||
};
|
||||
expect(normalize(renderToString(qweb, "test", context))).toBe(
|
||||
"<div>andormgtnlt</div>"
|
||||
);
|
||||
expect(normalize(renderToString(qweb, "test", context))).toBe("<div>andormgtnlt</div>");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -489,10 +445,7 @@ describe("attributes", () => {
|
||||
});
|
||||
|
||||
test("format multiple", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div t-attf-foo="a {{value1}} is {{value2}} of {{value3}} ]"/>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div t-attf-foo="a {{value1}} is {{value2}} of {{value3}} ]"/>`);
|
||||
const result = renderToString(qweb, "test", {
|
||||
value1: 0,
|
||||
value2: 1,
|
||||
@@ -528,19 +481,13 @@ describe("attributes", () => {
|
||||
});
|
||||
|
||||
test("class and t-attf-class with ternary operation", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div class="hello" t-attf-class="{{value ? 'world' : ''}}"/>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div class="hello" t-attf-class="{{value ? 'world' : ''}}"/>`);
|
||||
const result = renderToString(qweb, "test", { value: true });
|
||||
expect(result).toBe(`<div class="hello world"></div>`);
|
||||
});
|
||||
|
||||
test("t-att-class with object", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div class="static" t-att-class="{a: b, c: d, e: f}"/>`
|
||||
);
|
||||
qweb.addTemplate("test", `<div class="static" t-att-class="{a: b, c: d, e: f}"/>`);
|
||||
const result = renderToString(qweb, "test", { b: true, d: false, f: true });
|
||||
expect(result).toBe(`<div class="static a e"></div>`);
|
||||
});
|
||||
@@ -569,10 +516,7 @@ describe("t-call (template calling", () => {
|
||||
|
||||
test("with unused setbody", () => {
|
||||
qweb.addTemplate("_basic-callee", "<div>ok</div>");
|
||||
qweb.addTemplate(
|
||||
"caller",
|
||||
'<t t-call="_basic-callee"><t t-set="qux" t-value="3"/></t>'
|
||||
);
|
||||
qweb.addTemplate("caller", '<t t-call="_basic-callee"><t t-set="qux" t-value="3"/></t>');
|
||||
const expected = "<div>ok</div>";
|
||||
expect(renderToString(qweb, "caller")).toBe(expected);
|
||||
});
|
||||
@@ -678,9 +622,7 @@ describe("foreach", () => {
|
||||
</t>
|
||||
</div>`
|
||||
);
|
||||
const result = trim(
|
||||
renderToString(qweb, "test", { value: { a: 1, b: 2, c: 3 } })
|
||||
);
|
||||
const result = trim(renderToString(qweb, "test", { value: { a: 1, b: 2, c: 3 } }));
|
||||
const expected = `<div>[0:a1][1:b2][2:c3]</div>`;
|
||||
expect(result).toBe(expected);
|
||||
});
|
||||
@@ -727,14 +669,8 @@ describe("foreach", () => {
|
||||
describe("misc", () => {
|
||||
test("global", () => {
|
||||
qweb.addTemplate("_callee-asc", `<Año t-att-falló="'agüero'" t-raw="0"/>`);
|
||||
qweb.addTemplate(
|
||||
"_callee-uses-foo",
|
||||
`<span t-esc="foo">foo default</span>`
|
||||
);
|
||||
qweb.addTemplate(
|
||||
"_callee-asc-toto",
|
||||
`<div t-raw="toto">toto default</div>`
|
||||
);
|
||||
qweb.addTemplate("_callee-uses-foo", `<span t-esc="foo">foo default</span>`);
|
||||
qweb.addTemplate("_callee-asc-toto", `<div t-raw="toto">toto default</div>`);
|
||||
qweb.addTemplate(
|
||||
"caller",
|
||||
`
|
||||
@@ -847,10 +783,7 @@ describe("t-on", () => {
|
||||
});
|
||||
|
||||
test("can bind handlers with object arguments", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<button t-on-click="add({val: 5})">Click</button>`
|
||||
);
|
||||
qweb.addTemplate("test", `<button t-on-click="add({val: 5})">Click</button>`);
|
||||
let a = 1;
|
||||
const node = renderToDOM(
|
||||
qweb,
|
||||
@@ -868,10 +801,7 @@ describe("t-on", () => {
|
||||
|
||||
test("can bind handlers with empty object", () => {
|
||||
expect.assertions(2);
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<button t-on-click="doSomething({})">Click</button>`
|
||||
);
|
||||
qweb.addTemplate("test", `<button t-on-click="doSomething({})">Click</button>`);
|
||||
const node = renderToDOM(
|
||||
qweb,
|
||||
"test",
|
||||
@@ -887,10 +817,7 @@ describe("t-on", () => {
|
||||
|
||||
test("can bind handlers with empty object (with non empty inner string)", () => {
|
||||
expect.assertions(2);
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<button t-on-click="doSomething({ })">Click</button>`
|
||||
);
|
||||
qweb.addTemplate("test", `<button t-on-click="doSomething({ })">Click</button>`);
|
||||
const node = renderToDOM(
|
||||
qweb,
|
||||
"test",
|
||||
@@ -1190,13 +1117,10 @@ describe("whitespace handling", () => {
|
||||
|
||||
describe("t-key", () => {
|
||||
test("can use t-key directive on a node", () => {
|
||||
qweb.addTemplate(
|
||||
"test",
|
||||
`<div t-key="beer.id"><t t-esc="beer.name"/></div>`
|
||||
qweb.addTemplate("test", `<div t-key="beer.id"><t t-esc="beer.name"/></div>`);
|
||||
expect(renderToString(qweb, "test", { beer: { id: 12, name: "Chimay Rouge" } })).toBe(
|
||||
"<div>Chimay Rouge</div>"
|
||||
);
|
||||
expect(
|
||||
renderToString(qweb, "test", { beer: { id: 12, name: "Chimay Rouge" } })
|
||||
).toBe("<div>Chimay Rouge</div>");
|
||||
});
|
||||
|
||||
test("t-key directive in a list", () => {
|
||||
|
||||
@@ -2,9 +2,7 @@ import { compileExpr, tokenize } from "../src/qweb_expressions";
|
||||
|
||||
describe("tokenizer", () => {
|
||||
test("simple tokens", () => {
|
||||
expect(tokenize("1.3")).toEqual([
|
||||
{ type: "VALUE", value: "1.3" }
|
||||
]);
|
||||
expect(tokenize("1.3")).toEqual([{ type: "VALUE", value: "1.3" }]);
|
||||
|
||||
expect(tokenize("{}")).toEqual([
|
||||
{ type: "LEFT_BRACE", value: "{" },
|
||||
@@ -29,10 +27,7 @@ describe("tokenizer", () => {
|
||||
{ type: "VALUE", value: "2" },
|
||||
{ type: "RIGHT_BRACE", value: "}" }
|
||||
]);
|
||||
expect(tokenize("a,")).toEqual([
|
||||
{ type: "SYMBOL", value: "a" },
|
||||
{ type: "COMMA", value: "," }
|
||||
]);
|
||||
expect(tokenize("a,")).toEqual([{ type: "SYMBOL", value: "a" }, { type: "COMMA", value: "," }]);
|
||||
expect(tokenize("][")).toEqual([
|
||||
{ type: "RIGHT_BRACKET", value: "]" },
|
||||
{ type: "LEFT_BRACKET", value: "[" }
|
||||
@@ -46,7 +41,7 @@ describe("tokenizer", () => {
|
||||
{ type: "OPERATOR", value: "<" },
|
||||
{ type: "OPERATOR", value: ">" },
|
||||
{ type: "OPERATOR", value: "!==" },
|
||||
{ type: "OPERATOR", value: "!=" },
|
||||
{ type: "OPERATOR", value: "!=" }
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -54,25 +49,17 @@ describe("tokenizer", () => {
|
||||
expect(() => tokenize("'")).toThrow("Invalid expression");
|
||||
expect(() => tokenize("'\\")).toThrow("Invalid expression");
|
||||
expect(() => tokenize("'\\'")).toThrow("Invalid expression");
|
||||
expect(tokenize("'hello ged'")).toEqual([
|
||||
{ type: "VALUE", value: "'hello ged'" }
|
||||
]);
|
||||
expect(tokenize("'hello \\'ged\\''")).toEqual([
|
||||
{ type: "VALUE", value: "'hello \\'ged\\''" }
|
||||
]);
|
||||
expect(tokenize("'hello ged'")).toEqual([{ type: "VALUE", value: "'hello ged'" }]);
|
||||
expect(tokenize("'hello \\'ged\\''")).toEqual([{ type: "VALUE", value: "'hello \\'ged\\''" }]);
|
||||
|
||||
expect(() => tokenize('"')).toThrow("Invalid expression");
|
||||
expect(() => tokenize('"\\"')).toThrow("Invalid expression");
|
||||
expect(tokenize('"hello ged"')).toEqual([
|
||||
{ type: "VALUE", value: '"hello ged"' }
|
||||
]);
|
||||
expect(tokenize('"hello ged"')).toEqual([{ type: "VALUE", value: '"hello ged"' }]);
|
||||
expect(tokenize('"hello ged"}')).toEqual([
|
||||
{ type: "VALUE", value: '"hello ged"' },
|
||||
{ type: "RIGHT_BRACE", value: "}" }
|
||||
]);
|
||||
expect(tokenize('"hello \\"ged\\""')).toEqual([
|
||||
{ type: "VALUE", value: '"hello \\"ged\\""' }
|
||||
]);
|
||||
expect(tokenize('"hello \\"ged\\""')).toEqual([{ type: "VALUE", value: '"hello \\"ged\\""' }]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -113,9 +100,7 @@ describe("expression evaluation", () => {
|
||||
test("arrays and objects", () => {
|
||||
expect(compileExpr("[{b:1}] ", {})).toBe("[{b:1}]");
|
||||
expect(compileExpr("{a: []} ", {})).toBe("{a:[]}");
|
||||
expect(compileExpr("[{b:1, c: [1, {d: {e: 3}} ]}] ", {})).toBe(
|
||||
"[{b:1,c:[1,{d:{e:3}}]}]"
|
||||
);
|
||||
expect(compileExpr("[{b:1, c: [1, {d: {e: 3}} ]}] ", {})).toBe("[{b:1,c:[1,{d:{e:3}}]}]");
|
||||
});
|
||||
|
||||
test("dot operator", () => {
|
||||
@@ -130,13 +115,9 @@ describe("expression evaluation", () => {
|
||||
});
|
||||
|
||||
test("various binary operators", () => {
|
||||
expect(compileExpr("color == 'black'", {})).toBe(
|
||||
"context['color']=='black'"
|
||||
);
|
||||
expect(compileExpr("color == 'black'", {})).toBe("context['color']=='black'");
|
||||
expect(compileExpr("a || b", {})).toBe("context['a']||context['b']");
|
||||
expect(compileExpr("color === 'black'", {})).toBe(
|
||||
"context['color']==='black'"
|
||||
);
|
||||
expect(compileExpr("color === 'black'", {})).toBe("context['color']==='black'");
|
||||
expect(compileExpr("'li_'+item", {})).toBe("'li_'+context['item']");
|
||||
expect(compileExpr("state.val > 1", {})).toBe("context['state'].val>1");
|
||||
});
|
||||
@@ -164,18 +145,14 @@ describe("expression evaluation", () => {
|
||||
expect(compileExpr("a()", {})).toBe("context['a']()");
|
||||
expect(compileExpr("a(1)", {})).toBe("context['a'](1)");
|
||||
expect(compileExpr("a(1,2)", {})).toBe("context['a'](1,2)");
|
||||
expect(compileExpr("a(1,2,{a:[a]})", {})).toBe(
|
||||
"context['a'](1,2,{a:[context['a']]})"
|
||||
);
|
||||
expect(compileExpr("a(1,2,{a:[a]})", {})).toBe("context['a'](1,2,{a:[context['a']]})");
|
||||
expect(compileExpr("'x'.toUpperCase()", {})).toBe("'x'.toUpperCase()");
|
||||
expect(compileExpr("'x'.toUpperCase({a: 3})", {})).toBe(
|
||||
"'x'.toUpperCase({a:3})"
|
||||
expect(compileExpr("'x'.toUpperCase({a: 3})", {})).toBe("'x'.toUpperCase({a:3})");
|
||||
expect(compileExpr("'x'.toUpperCase(a)", { a: { id: "_v5", expr: "" } })).toBe(
|
||||
"'x'.toUpperCase(_v5)"
|
||||
);
|
||||
expect(compileExpr("'x'.toUpperCase({b: a})", { a: { id: "_v5", expr: "" } })).toBe(
|
||||
"'x'.toUpperCase({b:_v5})"
|
||||
);
|
||||
expect(
|
||||
compileExpr("'x'.toUpperCase(a)", { a: { id: "_v5", expr: "" } })
|
||||
).toBe("'x'.toUpperCase(_v5)");
|
||||
expect(
|
||||
compileExpr("'x'.toUpperCase({b: a})", { a: { id: "_v5", expr: "" } })
|
||||
).toBe("'x'.toUpperCase({b:_v5})");
|
||||
});
|
||||
});
|
||||
|
||||
+6
-21
@@ -1,11 +1,6 @@
|
||||
import { Component, Env } from "../src/component";
|
||||
import { connect, Store } from "../src/store";
|
||||
import {
|
||||
makeTestFixture,
|
||||
makeTestEnv,
|
||||
nextMicroTick,
|
||||
nextTick
|
||||
} from "./helpers";
|
||||
import { makeTestFixture, makeTestEnv, nextMicroTick, nextTick } from "./helpers";
|
||||
import { Observer } from "../src";
|
||||
|
||||
describe("basic use", () => {
|
||||
@@ -794,9 +789,7 @@ describe("connecting a component to store", () => {
|
||||
|
||||
store.commit("addTodo", "hoegaarden");
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><span>jupiler</span><span>hoegaarden</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><span>jupiler</span><span>hoegaarden</span></div>");
|
||||
});
|
||||
|
||||
test("connect receives store getters as third argument", async () => {
|
||||
@@ -930,9 +923,7 @@ describe("connecting a component to store", () => {
|
||||
|
||||
store.commit("addBeer", "kwak");
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><span>jupiler</span><span>kwak</span></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><span>jupiler</span><span>kwak</span></div>");
|
||||
});
|
||||
|
||||
test("connected component with undefined, null and string props", async () => {
|
||||
@@ -984,9 +975,7 @@ describe("connecting a component to store", () => {
|
||||
const app = new App(env);
|
||||
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div><span>taster:aaron</span></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>taster:aaron</span></div></div>");
|
||||
|
||||
app.state.beerId = 1;
|
||||
await nextTick();
|
||||
@@ -1062,9 +1051,7 @@ describe("connecting a component to store", () => {
|
||||
const app = new App(env);
|
||||
|
||||
await app.mount(fixture);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
"<div><div><span>taster:aaron</span></div></div>"
|
||||
);
|
||||
expect(fixture.innerHTML).toBe("<div><div><span>taster:aaron</span></div></div>");
|
||||
|
||||
app.state.beerId = 1;
|
||||
await nextTick();
|
||||
@@ -1334,9 +1321,7 @@ describe("connecting a component to store", () => {
|
||||
await nextTick();
|
||||
expect(renderCount).toBe(1);
|
||||
expect(fCount).toBe(1);
|
||||
expect(fixture.innerHTML).toBe(
|
||||
'<div class="todoapp"></div>'
|
||||
);
|
||||
expect(fixture.innerHTML).toBe('<div class="todoapp"></div>');
|
||||
});
|
||||
|
||||
test("connected component willpatch/patch hooks are called on store updates", async () => {
|
||||
|
||||
+28
-143
@@ -59,9 +59,7 @@ describe("attributes", function() {
|
||||
test("are set correctly when namespaced", function() {
|
||||
const vnode1 = h("div", { attrs: { "xlink:href": "#foo" } });
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(elm.getAttributeNS("http://www.w3.org/1999/xlink", "href")).toBe(
|
||||
"#foo"
|
||||
);
|
||||
expect(elm.getAttributeNS("http://www.w3.org/1999/xlink", "href")).toBe("#foo");
|
||||
});
|
||||
|
||||
test("should not touch class nor id fields", function() {
|
||||
@@ -207,12 +205,8 @@ describe("snabbdom", function() {
|
||||
expect(elm.firstChild.namespaceURI).toBe(SVGNamespace);
|
||||
|
||||
// verify that svg tag automatically gets svg namespace
|
||||
elm = patch(
|
||||
vnode0,
|
||||
h("svg", [
|
||||
h("foreignObject", [h("div", ["I am HTML embedded in SVG"])])
|
||||
])
|
||||
).elm;
|
||||
elm = patch(vnode0, h("svg", [h("foreignObject", [h("div", ["I am HTML embedded in SVG"])])]))
|
||||
.elm;
|
||||
expect(elm.namespaceURI).toBe(SVGNamespace);
|
||||
expect(elm.firstChild.namespaceURI).toBe(SVGNamespace);
|
||||
expect(elm.firstChild.firstChild.namespaceURI).toBe(XHTMLNamespace);
|
||||
@@ -352,13 +346,7 @@ describe("snabbdom", function() {
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(elm.children.length).toBe(2);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]);
|
||||
});
|
||||
|
||||
test("add elements in the middle", function() {
|
||||
@@ -368,13 +356,7 @@ describe("snabbdom", function() {
|
||||
expect(elm.children.length).toBe(4);
|
||||
expect(elm.children.length).toBe(4);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]);
|
||||
});
|
||||
|
||||
test("add elements at beginning and end", function() {
|
||||
@@ -383,13 +365,7 @@ describe("snabbdom", function() {
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(elm.children.length).toBe(3);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"5"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2", "3", "4", "5"]);
|
||||
});
|
||||
|
||||
test("adds children to parent with no children", function() {
|
||||
@@ -588,35 +564,19 @@ describe("snabbdom", function() {
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(elm.children.length).toBe(6);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"4",
|
||||
"3",
|
||||
"2",
|
||||
"1",
|
||||
"5",
|
||||
"0"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["4", "3", "2", "1", "5", "0"]);
|
||||
});
|
||||
|
||||
test("supports null/undefined children", function() {
|
||||
const vnode1 = h("i", [0, 1, 2, 3, 4, 5].map(spanNum));
|
||||
const vnode2 = h(
|
||||
"i",
|
||||
[null, 2, undefined, null, 1, 0, null, 5, 4, null, 3, undefined].map(
|
||||
spanNum
|
||||
)
|
||||
[null, 2, undefined, null, 1, 0, null, 5, 4, null, 3, undefined].map(spanNum)
|
||||
);
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(elm.children.length).toBe(6);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"2",
|
||||
"1",
|
||||
"0",
|
||||
"5",
|
||||
"4",
|
||||
"3"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["2", "1", "0", "5", "4", "3"]);
|
||||
});
|
||||
|
||||
test("supports all null/undefined children", function() {
|
||||
@@ -627,14 +587,7 @@ describe("snabbdom", function() {
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(elm.children.length).toBe(0);
|
||||
elm = patch(vnode2, vnode3).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"5",
|
||||
"4",
|
||||
"3",
|
||||
"2",
|
||||
"1",
|
||||
"0"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["5", "4", "3", "2", "1", "0"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -714,18 +667,10 @@ describe("snabbdom", function() {
|
||||
});
|
||||
|
||||
test("removes elements", function() {
|
||||
const vnode1 = h("div", [
|
||||
h("span", "One"),
|
||||
h("span", "Two"),
|
||||
h("span", "Three")
|
||||
]);
|
||||
const vnode1 = h("div", [h("span", "One"), h("span", "Two"), h("span", "Three")]);
|
||||
const vnode2 = h("div", [h("span", "One"), h("span", "Three")]);
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["One", "Two", "Three"]);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["One", "Three"]);
|
||||
});
|
||||
@@ -760,49 +705,19 @@ describe("snabbdom", function() {
|
||||
});
|
||||
|
||||
test("reorders elements", function() {
|
||||
const vnode1 = h("div", [
|
||||
h("span", "One"),
|
||||
h("div", "Two"),
|
||||
h("b", "Three")
|
||||
]);
|
||||
const vnode2 = h("div", [
|
||||
h("b", "Three"),
|
||||
h("span", "One"),
|
||||
h("div", "Two")
|
||||
]);
|
||||
const vnode1 = h("div", [h("span", "One"), h("div", "Two"), h("b", "Three")]);
|
||||
const vnode2 = h("div", [h("b", "Three"), h("span", "One"), h("div", "Two")]);
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"One",
|
||||
"Two",
|
||||
"Three"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["One", "Two", "Three"]);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
expect(map(elm.children, c => c.tagName)).toEqual(["B", "SPAN", "DIV"]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual([
|
||||
"Three",
|
||||
"One",
|
||||
"Two"
|
||||
]);
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["Three", "One", "Two"]);
|
||||
});
|
||||
|
||||
test("supports null/undefined children", function() {
|
||||
const vnode1 = h("i", [null, h("i", "1"), h("i", "2"), null]);
|
||||
const vnode2 = h("i", [
|
||||
h("i", "2"),
|
||||
undefined,
|
||||
undefined,
|
||||
h("i", "1"),
|
||||
undefined
|
||||
]);
|
||||
const vnode3 = h("i", [
|
||||
null,
|
||||
h("i", "1"),
|
||||
undefined,
|
||||
null,
|
||||
h("i", "2"),
|
||||
undefined,
|
||||
null
|
||||
]);
|
||||
const vnode2 = h("i", [h("i", "2"), undefined, undefined, h("i", "1"), undefined]);
|
||||
const vnode3 = h("i", [null, h("i", "1"), undefined, null, h("i", "2"), undefined, null]);
|
||||
elm = patch(vnode0, vnode1).elm;
|
||||
expect(map(elm.children, c => c.innerHTML)).toEqual(["1", "2"]);
|
||||
elm = patch(vnode1, vnode2).elm;
|
||||
@@ -835,10 +750,7 @@ describe("snabbdom", function() {
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("span", "First sibling"),
|
||||
h("div", { hook: { create: cb } }, [
|
||||
h("span", "Child 1"),
|
||||
h("span", "Child 2")
|
||||
]),
|
||||
h("div", { hook: { create: cb } }, [h("span", "Child 1"), h("span", "Child 2")]),
|
||||
h("span", "Can't touch me")
|
||||
]);
|
||||
patch(vnode0, vnode1);
|
||||
@@ -855,10 +767,7 @@ describe("snabbdom", function() {
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("span", "First sibling"),
|
||||
h("div", { hook: { insert: cb } }, [
|
||||
h("span", "Child 1"),
|
||||
h("span", "Child 2")
|
||||
]),
|
||||
h("div", { hook: { insert: cb } }, [h("span", "Child 1"), h("span", "Child 2")]),
|
||||
h("span", "Can touch me")
|
||||
]);
|
||||
patch(vnode0, vnode1);
|
||||
@@ -874,17 +783,11 @@ describe("snabbdom", function() {
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("span", "First sibling"),
|
||||
h("div", { hook: { prepatch: cb } }, [
|
||||
h("span", "Child 1"),
|
||||
h("span", "Child 2")
|
||||
])
|
||||
h("div", { hook: { prepatch: cb } }, [h("span", "Child 1"), h("span", "Child 2")])
|
||||
]);
|
||||
const vnode2 = h("div", [
|
||||
h("span", "First sibling"),
|
||||
h("div", { hook: { prepatch: cb } }, [
|
||||
h("span", "Child 1"),
|
||||
h("span", "Child 2")
|
||||
])
|
||||
h("div", { hook: { prepatch: cb } }, [h("span", "Child 1"), h("span", "Child 2")])
|
||||
]);
|
||||
patch(vnode0, vnode1);
|
||||
patch(vnode1, vnode2);
|
||||
@@ -965,10 +868,7 @@ describe("snabbdom", function() {
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("span", "First sibling"),
|
||||
h("div", { hook: { remove: cb } }, [
|
||||
h("span", "Child 1"),
|
||||
h("span", "Child 2")
|
||||
])
|
||||
h("div", { hook: { remove: cb } }, [h("span", "Child 1"), h("span", "Child 2")])
|
||||
]);
|
||||
const vnode2 = h("div", [h("span", "First sibling")]);
|
||||
patch(vnode0, vnode1);
|
||||
@@ -981,9 +881,7 @@ describe("snabbdom", function() {
|
||||
function cb(vnode) {
|
||||
calls++;
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("div", { hook: { destroy: cb } }, [h("span", "Child 1")])
|
||||
]);
|
||||
const vnode1 = h("div", [h("div", { hook: { destroy: cb } }, [h("span", "Child 1")])]);
|
||||
const vnode2 = h("div", "Text node");
|
||||
patch(vnode0, vnode1);
|
||||
patch(vnode1, vnode2);
|
||||
@@ -1053,10 +951,7 @@ describe("snabbdom", function() {
|
||||
result.push(vnode);
|
||||
rm();
|
||||
}
|
||||
const vnode1 = h("div", { hook: { remove: cb } }, [
|
||||
h("b", "Child 1"),
|
||||
h("i", "Child 2")
|
||||
]);
|
||||
const vnode1 = h("div", { hook: { remove: cb } }, [h("b", "Child 1"), h("i", "Child 2")]);
|
||||
const vnode2 = h("span", [h("b", "Child 1"), h("i", "Child 2")]);
|
||||
patch(vnode0, vnode1);
|
||||
patch(vnode1, vnode2);
|
||||
@@ -1091,10 +986,7 @@ describe("snabbdom", function() {
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("span", "First sibling"),
|
||||
h("div", [
|
||||
h("span", { hook: { destroy: cb } }, "Child 1"),
|
||||
h("span", "Child 2")
|
||||
])
|
||||
h("div", [h("span", { hook: { destroy: cb } }, "Child 1"), h("span", "Child 2")])
|
||||
]);
|
||||
const vnode2 = h("div");
|
||||
patch(vnode0, vnode1);
|
||||
@@ -1150,11 +1042,7 @@ describe("snabbdom", function() {
|
||||
}
|
||||
}
|
||||
]);
|
||||
const vnode1 = h("div", [
|
||||
h("span", "First child"),
|
||||
"",
|
||||
h("span", "Third child")
|
||||
]);
|
||||
const vnode1 = h("div", [h("span", "First child"), "", h("span", "Third child")]);
|
||||
const vnode2 = h("div");
|
||||
patch(vnode0, vnode1);
|
||||
patch(vnode1, vnode2);
|
||||
@@ -1196,10 +1084,7 @@ describe("snabbdom", function() {
|
||||
function cb(vnode) {
|
||||
result.push(vnode);
|
||||
}
|
||||
const vnode1 = h("div", [
|
||||
h("span", { hook: { update: cb } }, "Hello"),
|
||||
h("span", "there")
|
||||
]);
|
||||
const vnode1 = h("div", [h("span", { hook: { update: cb } }, "Hello"), h("span", "there")]);
|
||||
patch(vnode0, vnode1);
|
||||
patch(vnode1, vnode1);
|
||||
expect(result).toHaveLength(0);
|
||||
|
||||
Reference in New Issue
Block a user