[FIX] compiler: svg in new block takes the right namespace

This commit is contained in:
Lucas Perais (lpe)
2022-01-21 09:24:40 +01:00
committed by Aaron Bohy
parent a8d88d4009
commit d88eb34d4f
3 changed files with 53 additions and 6 deletions
+19 -1
View File
@@ -44,10 +44,28 @@ exports[`properly support svg namespace to svg tags added even if already in svg
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><svg block-ns=\\"http://www.w3.org/2000/svg\\"/></svg>\`);
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><svg/></svg>\`);
return function template(ctx, node, key = \\"\\") {
return block1();
}
}"
`;
exports[`properly support svg svg namespace added to sub-blocks 1`] = `
"function anonymous(bdom, helpers
) {
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
let block1 = createBlock(\`<svg block-ns=\\"http://www.w3.org/2000/svg\\"><block-child-0/></svg>\`);
let block2 = createBlock(\`<path block-ns=\\"http://www.w3.org/2000/svg\\"/>\`);
return function template(ctx, node, key = \\"\\") {
let b2;
if (ctx['path']) {
b2 = block2();
}
return block1([], [b2]);
}
}"
`;
+28 -3
View File
@@ -1,5 +1,5 @@
import { renderToString, snapshotEverything } from "../helpers";
import { renderToString, renderToBdom, snapshotEverything, makeTestFixture } from "../helpers";
import { mount } from "../../src/blockdom";
// NB: check the snapshots to see where the SVG namespaces are added
snapshotEverything();
@@ -25,6 +25,31 @@ describe("properly support svg", () => {
test("namespace to svg tags added even if already in svg namespace", () => {
const template = `<svg><svg/></svg>`;
expect(renderToString(template)).toBe(`<svg><svg></svg></svg>`);
const bdom = renderToBdom(template);
const fixture = makeTestFixture();
mount(bdom, fixture);
const elems = fixture.querySelectorAll("svg");
expect(elems.length).toEqual(2);
for (const el of elems) {
expect(el.namespaceURI).toBe("http://www.w3.org/2000/svg");
}
});
test("svg namespace added to sub-blocks", () => {
const template = `<svg><path t-if="path"/></svg>`;
expect(renderToString(template, { path: false })).toBe(`<svg></svg>`);
expect(renderToString(template, { path: true })).toBe(`<svg><path></path></svg>`);
const bdom = renderToBdom(template, { path: true });
const fixture = makeTestFixture();
mount(bdom, fixture);
const elems = fixture.querySelectorAll("svg, path");
expect(elems.length).toEqual(2);
for (const el of elems) {
expect(el.namespaceURI).toBe("http://www.w3.org/2000/svg");
}
});
});