[FIX] qweb: properly handle t-raw in various situations

closes #325
closes #327
This commit is contained in:
Géry Debongnie
2019-10-12 09:07:25 +02:00
parent 41b0618c93
commit 3e8f60cefa
11 changed files with 153 additions and 69 deletions
+6 -36
View File
@@ -630,12 +630,7 @@ exports[`misc global 1`] = `
c1.push(vn21);
var _22 = context['toto'];
if (_22 || _22 === 0) {
var frag23 = utils.getFragment(_22)
var p24 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag23, n.elm),
}};
var vn24 = h('div', p24)
c21.push(vn24);
c21.push(...utils.htmlToVDOM(_22));
} else {
c21.push({text: \`toto default\`});
}
@@ -1670,12 +1665,7 @@ exports[`t-on t-on combined with t-raw 1`] = `
p2.on['click'] = extra.handlers['click' + 2];
var _3 = context['html'];
if (_3 || _3 === 0) {
var frag4 = utils.getFragment(_3)
var p5 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag4, n.elm),
}};
var vn5 = h('div', p5)
c2.push(vn5);
c2.push(...utils.htmlToVDOM(_3));
}
return vn1;
}"
@@ -1851,12 +1841,7 @@ exports[`t-raw literal 1`] = `
var vn1 = h('span', p1, c1);
var _2 = 'ok';
if (_2 || _2 === 0) {
var frag3 = utils.getFragment(_2)
var p4 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag3, n.elm),
}};
var vn4 = h('div', p4)
c1.push(vn4);
c1.push(...utils.htmlToVDOM(_2));
}
return vn1;
}"
@@ -1871,12 +1856,7 @@ exports[`t-raw not escaping 1`] = `
var vn1 = h('div', p1, c1);
var _2 = context['var'];
if (_2 || _2 === 0) {
var frag3 = utils.getFragment(_2)
var p4 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag3, n.elm),
}};
var vn4 = h('div', p4)
c1.push(vn4);
c1.push(...utils.htmlToVDOM(_2));
}
return vn1;
}"
@@ -1895,12 +1875,7 @@ exports[`t-raw t-raw and another sibling node 1`] = `
c2.push({text: \`hello\`});
var _3 = context['var'];
if (_3 || _3 === 0) {
var frag4 = utils.getFragment(_3)
var p5 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag4, n.elm),
}};
var vn5 = h('div', p5)
c1.push(vn5);
c1.push(...utils.htmlToVDOM(_3));
}
return vn1;
}"
@@ -1915,12 +1890,7 @@ exports[`t-raw variable 1`] = `
var vn1 = h('span', p1, c1);
var _2 = context['var'];
if (_2 || _2 === 0) {
var frag3 = utils.getFragment(_2)
var p4 = {hook: {
insert: n => n.elm.parentNode.replaceChild(frag3, n.elm),
}};
var vn4 = h('div', p4)
c1.push(vn4);
c1.push(...utils.htmlToVDOM(_2));
}
return vn1;
}"
+16 -14
View File
@@ -1099,18 +1099,20 @@ describe("t-on", () => {
</t>
</div>`
);
const steps:string[] = [];
const steps: string[] = [];
const owner = {
projects: [{id: 1, name: 'Project 1'}, {id: 2, name: 'Project 2'}],
projects: [{ id: 1, name: "Project 1" }, { id: 2, name: "Project 2" }],
onEdit(projectId, ev) {
expect(ev.defaultPrevented).toBe(true);
steps.push(projectId);
},
}
};
const node = <HTMLElement>renderToDOM(qweb, "test", owner, { handlers: [] });
expect(node.outerHTML).toBe(`<div><a href="#"> Edit Project 1</a><a href="#"> Edit Project 2</a></div>`);
expect(node.outerHTML).toBe(
`<div><a href="#"> Edit Project 1</a><a href="#"> Edit Project 2</a></div>`
);
const links = node.querySelectorAll("a")!;
links[0].click();
@@ -1122,12 +1124,12 @@ describe("t-on", () => {
test("t-on combined with t-esc", async () => {
expect.assertions(3);
qweb.addTemplate("test", `<div><button t-on-click="onClick" t-esc="text"/></div>`);
const steps:string[] = [];
const steps: string[] = [];
const owner = {
text: 'Click here',
text: "Click here",
onClick() {
steps.push('onClick');
},
steps.push("onClick");
}
};
const node = <HTMLElement>renderToDOM(qweb, "test", owner, { handlers: [] });
@@ -1135,18 +1137,18 @@ describe("t-on", () => {
node.querySelector("button")!.click();
expect(steps).toEqual(['onClick']);
expect(steps).toEqual(["onClick"]);
});
test("t-on combined with t-raw", async () => {
expect.assertions(3);
qweb.addTemplate("test", `<div><button t-on-click="onClick" t-raw="html"/></div>`);
const steps:string[] = [];
const steps: string[] = [];
const owner = {
html: 'Click <b>here</b>',
html: "Click <b>here</b>",
onClick() {
steps.push('onClick');
},
steps.push("onClick");
}
};
const node = <HTMLElement>renderToDOM(qweb, "test", owner, { handlers: [] });
@@ -1154,7 +1156,7 @@ describe("t-on", () => {
node.querySelector("button")!.click();
expect(steps).toEqual(['onClick']);
expect(steps).toEqual(["onClick"]);
});
});