mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] compiler: does not modify xml doc in place
This commit is contained in:
committed by
Aaron Bohy
parent
3af5e57825
commit
e4b4ee471f
@@ -1,5 +1,19 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`loading templates addTemplates does not modify its xml document in place 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><block-text-0/></div>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
let txt1 = ctx['value'];
|
||||
return block1([txt1]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`loading templates can initialize qweb with a string 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -24,6 +24,17 @@ describe("loading templates", () => {
|
||||
expect(context.renderToString("hey")).toBe("<div>jupiler</div>");
|
||||
});
|
||||
|
||||
test("addTemplates does not modify its xml document in place", () => {
|
||||
const data = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve"><div t-name="hey"><t t-esc="value"/></div></templates>`;
|
||||
const xml = new DOMParser().parseFromString(data, "text/xml");
|
||||
const context = new TestContext();
|
||||
expect(xml.firstElementChild!.innerHTML).toBe(`<div t-name="hey"><t t-esc="value"/></div>`);
|
||||
context.addTemplates(xml);
|
||||
expect(context.renderToString("hey", { value: 123 })).toBe("<div>123</div>");
|
||||
expect(xml.firstElementChild!.innerHTML).toBe(`<div t-name="hey"><t t-esc="value"/></div>`);
|
||||
});
|
||||
|
||||
test("can load a few templates from a xml string", () => {
|
||||
const data = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ export function snapshotEverything() {
|
||||
});
|
||||
|
||||
const originalCompileTemplate = TemplateSet.prototype._compileTemplate;
|
||||
TemplateSet.prototype._compileTemplate = function (name: string, template: string | Node) {
|
||||
TemplateSet.prototype._compileTemplate = function (name: string, template: string | Element) {
|
||||
const fn = originalCompileTemplate.call(this, "", template);
|
||||
if (!globalTemplateNames.has(name)) {
|
||||
expect(fn.toString()).toMatchSnapshot();
|
||||
|
||||
Reference in New Issue
Block a user