|
| 1 | +import type { Namespace } from '@glimmer/interfaces'; |
| 2 | +import { NS_HTML, NS_MATHML, NS_SVG } from '@glimmer/constants'; |
| 3 | + |
| 4 | +import { defineComponent, jitSuite, RenderTest, test } from '..'; |
| 5 | + |
| 6 | +class MathElementTest extends RenderTest { |
| 7 | + static suiteName = '<math>'; |
| 8 | + query(selector: string) { |
| 9 | + let el = (s: string) => (this.element as unknown as HTMLElement).querySelector(s); |
| 10 | + return el(selector) as Element; |
| 11 | + } |
| 12 | + assertNamespace(selector: string, ns: Namespace) { |
| 13 | + this.assert.strictEqual( |
| 14 | + this.query(selector).namespaceURI, |
| 15 | + ns, |
| 16 | + `Expecting "${ns}" namespace for tag "${selector}"` |
| 17 | + ); |
| 18 | + } |
| 19 | + |
| 20 | + @test |
| 21 | + '<math> element can render'() { |
| 22 | + const Bar = defineComponent({}, '<math><msqrt><mi>x</mi></msqrt></math>'); |
| 23 | + |
| 24 | + this.renderComponent(Bar); |
| 25 | + |
| 26 | + this.assertNamespace('math', NS_MATHML); |
| 27 | + this.assertNamespace('msqrt', NS_MATHML); |
| 28 | + this.assertNamespace('mi', NS_MATHML); |
| 29 | + } |
| 30 | + |
| 31 | + @test |
| 32 | + 'HTML and <math> element can render together'() { |
| 33 | + const Bar = defineComponent( |
| 34 | + {}, |
| 35 | + '<div><p>Math inside:</p><math><msqrt><mi>x</mi></msqrt></math></div>' |
| 36 | + ); |
| 37 | + |
| 38 | + this.renderComponent(Bar); |
| 39 | + |
| 40 | + this.assertNamespace('div', NS_HTML); |
| 41 | + this.assertNamespace('p', NS_HTML); |
| 42 | + this.assertNamespace('math', NS_MATHML); |
| 43 | + this.assertNamespace('msqrt', NS_MATHML); |
| 44 | + this.assertNamespace('mi', NS_MATHML); |
| 45 | + } |
| 46 | + |
| 47 | + @test |
| 48 | + 'SVG and <math> element can render together'() { |
| 49 | + const Bar = defineComponent( |
| 50 | + {}, |
| 51 | + '<svg><circle cx="50" cy="50" r="40" /></svg><math><msqrt><mi>x</mi></msqrt></math>' |
| 52 | + ); |
| 53 | + |
| 54 | + this.renderComponent(Bar); |
| 55 | + |
| 56 | + this.assertNamespace('svg', NS_SVG); |
| 57 | + this.assertNamespace('circle', NS_SVG); |
| 58 | + this.assertNamespace('math', NS_MATHML); |
| 59 | + this.assertNamespace('msqrt', NS_MATHML); |
| 60 | + this.assertNamespace('mi', NS_MATHML); |
| 61 | + } |
| 62 | + |
| 63 | + @test |
| 64 | + 'HTML, SVG, and <math> element can render together'() { |
| 65 | + const Bar = defineComponent( |
| 66 | + {}, |
| 67 | + '<div><p>Math and SVG inside:</p><svg><circle cx="50" cy="50" r="40" /></svg><math><msqrt><mi>x</mi></msqrt></math></div>' |
| 68 | + ); |
| 69 | + |
| 70 | + this.renderComponent(Bar); |
| 71 | + |
| 72 | + this.assertNamespace('div', NS_HTML); |
| 73 | + this.assertNamespace('p', NS_HTML); |
| 74 | + this.assertNamespace('svg', NS_SVG); |
| 75 | + this.assertNamespace('circle', NS_SVG); |
| 76 | + this.assertNamespace('math', NS_MATHML); |
| 77 | + this.assertNamespace('msqrt', NS_MATHML); |
| 78 | + this.assertNamespace('mi', NS_MATHML); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +jitSuite(MathElementTest); |
0 commit comments