2022-05-26 23:45:40 +02:00
|
|
|
import { createBlock, mount } from "../../src/runtime/blockdom";
|
2021-11-19 11:31:04 +01:00
|
|
|
import { makeTestFixture } from "./helpers";
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Setup and helpers
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
const XHTML_URI = "http://www.w3.org/1999/xhtml";
|
|
|
|
|
const SVG_URI = "http://www.w3.org/2000/svg";
|
|
|
|
|
let fixture: HTMLElement;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
fixture = makeTestFixture();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
fixture.remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
// Tests
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
describe("namespace", () => {
|
|
|
|
|
test("default namespace is xhtml", () => {
|
|
|
|
|
const block = createBlock(`<tag/>`);
|
|
|
|
|
const tree = block();
|
|
|
|
|
mount(tree, fixture);
|
|
|
|
|
expect(fixture.innerHTML).toBe("<tag></tag>");
|
|
|
|
|
expect(fixture.firstElementChild!.namespaceURI).toBe(XHTML_URI);
|
|
|
|
|
});
|
|
|
|
|
|
2023-08-04 10:44:47 +02:00
|
|
|
test("namespace can be changed with xmlns", () => {
|
|
|
|
|
const block = createBlock(`<tag xmlns="${SVG_URI}"/>`);
|
2021-11-19 11:31:04 +01:00
|
|
|
const tree = block();
|
|
|
|
|
mount(tree, fixture);
|
2023-08-04 10:44:47 +02:00
|
|
|
expect(fixture.innerHTML).toBe(`<tag xmlns="${SVG_URI}"></tag>`);
|
2021-11-19 11:31:04 +01:00
|
|
|
expect(fixture.firstElementChild!.namespaceURI).toBe(SVG_URI);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("namespace is kept for children", () => {
|
|
|
|
|
const block = createBlock(
|
2023-08-04 10:44:47 +02:00
|
|
|
`<parent xmlns="${SVG_URI}"><child><subchild/></child><child/></parent>`
|
2021-11-19 11:31:04 +01:00
|
|
|
);
|
|
|
|
|
const tree = block();
|
|
|
|
|
mount(tree, fixture);
|
|
|
|
|
expect(fixture.innerHTML).toBe(
|
2023-08-04 10:44:47 +02:00
|
|
|
`<parent xmlns="${SVG_URI}"><child><subchild></subchild></child><child></child></parent>`
|
2021-11-19 11:31:04 +01:00
|
|
|
);
|
|
|
|
|
const parent = fixture.firstElementChild!;
|
|
|
|
|
const child1 = parent.firstElementChild!;
|
|
|
|
|
const subchild = child1.firstElementChild!;
|
|
|
|
|
const child2 = child1.nextElementSibling!;
|
|
|
|
|
expect(parent.namespaceURI).toBe(SVG_URI);
|
|
|
|
|
expect(child1.namespaceURI).toBe(SVG_URI);
|
|
|
|
|
expect(child2.namespaceURI).toBe(SVG_URI);
|
|
|
|
|
expect(subchild.namespaceURI).toBe(SVG_URI);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test("various namespaces in same block", () => {
|
2023-08-04 10:44:47 +02:00
|
|
|
const block = createBlock(`<none><one xmlns="one"/><two xmlns="two"/></none>`);
|
2021-11-19 11:31:04 +01:00
|
|
|
const tree = block();
|
|
|
|
|
mount(tree, fixture);
|
2023-08-04 10:44:47 +02:00
|
|
|
expect(fixture.innerHTML).toBe('<none><one xmlns="one"></one><two xmlns="two"></two></none>');
|
2021-11-19 11:31:04 +01:00
|
|
|
const none = fixture.firstElementChild!;
|
|
|
|
|
const one = none.firstElementChild!;
|
|
|
|
|
const two = one.nextElementSibling!;
|
|
|
|
|
expect(none.namespaceURI).toBe(XHTML_URI);
|
|
|
|
|
expect(one.namespaceURI).toBe("one");
|
|
|
|
|
expect(two.namespaceURI).toBe("two");
|
|
|
|
|
});
|
|
|
|
|
});
|