import { describe, expect, it } from "vitest";
import { findSvgIconProblem } from "./icons.js";
describe("findSvgIconProblem", () => {
it.each([
["a plain SVG", ''],
["leading whitespace", '\n '],
[
"a fragment reference",
'',
],
["currentColor fills", ''],
])("accepts %s", (_name, svg) => {
expect(findSvgIconProblem(svg)).toBeNull();
});
it.each([
["a non-SVG document", "hello", "not an SVG document"],
["an element", "", "not an SVG document"],
["a script", "", "script elements are not allowed"],
["a foreign object", "", "foreignObject elements are not allowed"],
["a style", "", "style elements are not allowed"],
[
"an event handler",
'',
"event-handler attributes are not allowed",
],
[
"a javascript URL",
'',
"javascript URLs are not allowed",
],
[
"an external href",
'',
"external href references are not allowed",
],
[
"an external xlink:href",
"",
"external href references are not allowed",
],
["markup over 64 KiB", ``, "exceeds 64 KiB"],
])("rejects %s", (_name, svg, reason) => {
expect(findSvgIconProblem(svg)).toBe(reason);
});
it("measures the size in UTF-8 bytes", () => {
const multibyte = "é".repeat(32 * 1024);
expect(findSvgIconProblem(``)).toBe("exceeds 64 KiB");
});
});