Skip to content

Commit

Permalink
Add tests for SVG global attributes (#1210)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg authored Feb 22, 2024
1 parent 85d85a8 commit cdeacb1
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 8 deletions.
93 changes: 93 additions & 0 deletions custom/elements.json
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,99 @@
}
},
"svg": {
"global_attributes": {
"attributes": [
{"class": "className", "tabindex": "tabIndex"},
"clip",
"color",
"cursor",
"data",
"direction",
"display",
"fill",
"filter",
"href",
"id",
"kerning",
"lang",
"mask",
"onabort",
"onactivate",
"onbegin",
"oncancel",
"oncanplay",
"oncanplaythrough",
"onchange",
"onclick",
"onclose",
"oncuechange",
"ondblclick",
"ondrag",
"ondragend",
"ondragenter",
"ondragexit",
"ondragleave",
"ondragover",
"ondragstart",
"ondrop",
"ondurationchange",
"onemptied",
"onend",
"onended",
"onerror",
"onfocus",
"onfocusin",
"onfocusout",
"oninput",
"oninvalid",
"onkeydown",
"onkeypress",
"onkeyup",
"onload",
"onloadeddata",
"onloadedmetadata",
"onloadstart",
"onmousedown",
"onmouseenter",
"onmouseleave",
"onmousemove",
"onmouseout",
"onmouseover",
"onmouseup",
"onmousewheel",
"onpause",
"onplay",
"onplaying",
"onprogress",
"onratechange",
"onrepeat",
"onreset",
"onresize",
"onscroll",
"onseeked",
"onseeking",
"onselect",
"onshow",
"onstalled",
"onsubmit",
"onsuspend",
"ontimeupdate",
"ontoggle",
"onunload",
"onvolumechange",
"onwaiting",
"opacity",
"overflow",
"requiredExtensions",
"requiredFeatures",
"stroke",
"style",
"systemLanguage",
"textLength",
"transform",
"visibility"
]
},
"cursor": {
"interfaceName": "SVGCursorElement",
"attributes": ["href", "x", "xlink_href", "y"]
Expand Down
14 changes: 6 additions & 8 deletions test-builder/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,26 @@ const build = async (specElements, customElements) => {
? `${category}.global_attributes`
: `${category}.elements`;

const interfaceName = data.interfaceName || categoryData.default;
if (!interfaceName) {
throw new Error(`${bcdPath} is missing an interface name`);
}

const customTest = await getCustomTest(bcdPath, subcat, true);

const defaultConstructCode = namespace
? `document.createElementNS('${namespace}', '${el}')`
: `document.createElement('${el}')`;

if (el !== "global_attributes") {
const interfaceName = data.interfaceName || categoryData.default;
if (!interfaceName) {
throw new Error(`${bcdPath} is missing an interface name`);
}

const defaultCode =
category === "mathml"
? `(function () {
throw new Error('MathML elements require custom tests');
})()`
: `(function() {
var instance = ${defaultConstructCode};
return bcd.testObjectName(instance, '${
data.interfaceName || categoryData.default
}');
return bcd.testObjectName(instance, '${interfaceName}');
})()`;
tests[bcdPath] = compileTest({
raw: {code: customTest.test || defaultCode},
Expand Down

0 comments on commit cdeacb1

Please sign in to comment.