[IMP] qweb: t-ref: dyn values with string interpolation

Closes #100
This commit is contained in:
Aaron Bohy
2019-05-28 13:17:38 +02:00
committed by Géry Debongnie
parent bced9f3d04
commit 26f14180e2
10 changed files with 71 additions and 41 deletions
+5 -5
View File
@@ -59,7 +59,7 @@ exports[`attributes format expression 1`] = `
"function anonymous(context,extra
) {
var h = this.utils.h;
var _1 = \`\${context['value'] + 37}\`;
var _1 = context['value'] + 37;
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
var vn2 = h('div', p2, c2);
return vn2;
@@ -70,7 +70,7 @@ exports[`attributes format expression, other format 1`] = `
"function anonymous(context,extra
) {
var h = this.utils.h;
var _1 = \`\${context['value'] + 37}\`;
var _1 = context['value'] + 37;
let c2 = [], p2 = {key:2,attrs:{foo: _1}};
var vn2 = h('div', p2, c2);
return vn2;
@@ -1494,7 +1494,7 @@ exports[`t-ref can get a dynamic ref on a node 1`] = `
let c2 = [], p2 = {key:2};
var vn2 = h('span', p2, c2);
c1.push(vn2);
const ref3 = 'myspan' + 3
const ref3 = \`myspan\${context['id']}\`;
p2.hook = {
create: (_, n) => {
context.refs[ref3] = n.elm;
@@ -1513,7 +1513,7 @@ exports[`t-ref can get a ref on a node 1`] = `
let c2 = [], p2 = {key:2};
var vn2 = h('span', p2, c2);
c1.push(vn2);
const ref3 = 'myspan'
const ref3 = \`myspan\`;
p2.hook = {
create: (_, n) => {
context.refs[ref3] = n.elm;
@@ -1546,7 +1546,7 @@ exports[`t-ref refs in a loop 1`] = `
let c5 = [], p5 = {key:context['item']};
var vn5 = h('div', p5, c5);
c1.push(vn5);
const ref6 = context['item']
const ref6 = context['item'];
p5.hook = {
create: (_, n) => {
context.refs[ref6] = n.elm;
+1 -1
View File
@@ -145,7 +145,7 @@ describe("animations", () => {
env.qweb.addTemplate(
"TestWidget",
`<div><span t-ref="'span'" t-transition="chimay">blue</span></div>`
`<div><span t-ref="span" t-transition="chimay">blue</span></div>`
);
class TestWidget extends Widget {
state = { hide: false };
+6 -6
View File
@@ -896,7 +896,7 @@ describe("composition", () => {
test("t-refs on widget are widgets", async () => {
env.qweb.addTemplate(
"WidgetC",
`<div>Hello<t t-ref="'mywidgetb'" t-widget="b"/></div>`
`<div>Hello<t t-ref="mywidgetb" t-widget="b"/></div>`
);
class WidgetC extends Widget {
widgets = { b: WidgetB };
@@ -912,7 +912,7 @@ describe("composition", () => {
"ParentWidget",
`
<div>
<t t-foreach="state.list" t-as="elem" t-ref="'child'" t-key="elem" t-widget="Widget"/>
<t t-foreach="state.list" t-as="elem" t-ref="child" t-key="elem" t-widget="Widget"/>
</div>`
);
class ParentWidget extends Widget {
@@ -938,8 +938,8 @@ describe("composition", () => {
"ParentWidget",
`
<div>
<t t-if="state.child1" t-ref="'child1'" t-widget="Widget"/>
<t t-if="state.child2" t-ref="'child2'" t-widget="Widget"/>
<t t-if="state.child1" t-ref="child1" t-widget="Widget"/>
<t t-if="state.child2" t-ref="child2" t-widget="Widget"/>
</div>`
);
class ParentWidget extends Widget {
@@ -1004,7 +1004,7 @@ describe("composition", () => {
"ParentWidget",
`<div>
<t t-foreach="state.items" t-as="item">
<t t-widget="Child" t-ref="item" t-key="item"/>
<t t-widget="Child" t-ref="{{item}}" t-key="item"/>
</t>
</div>`
);
@@ -2277,7 +2277,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>`
`<div><input t-ref="input" t-mounted="f"/></div>`
);
class TestWidget extends Widget {
f() {}
+5 -10
View File
@@ -1,10 +1,5 @@
import { QWeb } from "../src/qweb_core";
import {
normalize,
renderToDOM,
renderToString,
trim
} from "./helpers";
import { normalize, renderToDOM, renderToString, trim } from "./helpers";
//------------------------------------------------------------------------------
// Setup and helpers
@@ -1056,16 +1051,16 @@ describe("t-on", () => {
describe("t-ref", () => {
test("can get a ref on a node", () => {
qweb.addTemplate("test", `<div><span t-ref="'myspan'"/></div>`);
qweb.addTemplate("test", `<div><span t-ref="myspan"/></div>`);
let refs: any = {};
renderToDOM(qweb, "test", { refs });
expect(refs.myspan.tagName).toBe("SPAN");
});
test("can get a dynamic ref on a node", () => {
qweb.addTemplate("test", `<div><span t-ref="'myspan' + 3"/></div>`);
qweb.addTemplate("test", `<div><span t-ref="myspan{{id}}"/></div>`);
let refs: any = {};
renderToDOM(qweb, "test", { refs });
renderToDOM(qweb, "test", { refs, id: 3 });
expect(refs.myspan3.tagName).toBe("SPAN");
});
@@ -1075,7 +1070,7 @@ describe("t-ref", () => {
`
<div>
<t t-foreach="items" t-as="item">
<div t-ref="item" t-key="item"><t t-esc="item"/></div>
<div t-ref="{{item}}" t-key="item"><t t-esc="item"/></div>
</t>
</div>`
);
+1 -1
View File
@@ -876,7 +876,7 @@ describe("connecting a component to store", () => {
"Parent",
`
<div>
<t t-widget="Child" t-ref="'child'" t-props="{key: props.current}"/>
<t t-widget="Child" t-props="{key: props.current}"/>
</div>
`
);