65 lines
2.5 KiB
TypeScript
65 lines
2.5 KiB
TypeScript
import { describe, expect, it } from "@suaveplan/testing/runner";
|
|
import { findFirst } from "../../../tests/setup/html.js";
|
|
import { renderVNode } from "../../vnode/vnode.js";
|
|
import { EmailLink } from "./email-link.js";
|
|
|
|
describe("EmailLink", () => {
|
|
it("sets safe rel attribute", { timeout: 5000 }, () => {
|
|
const html = renderVNode(
|
|
EmailLink({ href: "https://x", children: "x" })
|
|
);
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a?.attribs.rel).toBe("noopener noreferrer");
|
|
expect(a?.attribs.target).toBe("_blank");
|
|
});
|
|
|
|
it("underlines by default", { timeout: 5000 }, () => {
|
|
const html = renderVNode(
|
|
EmailLink({ href: "https://x", children: "x" })
|
|
);
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a?.attribs.style ?? "").toContain("text-decoration:underline");
|
|
});
|
|
|
|
it("omits underline when underline=false", { timeout: 5000 }, () => {
|
|
const html = renderVNode(
|
|
EmailLink({ href: "https://x", children: "x", underline: false })
|
|
);
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a?.attribs.style ?? "").toContain("text-decoration:none");
|
|
});
|
|
|
|
it("uses themed primary colour by default", { timeout: 5000 }, () => {
|
|
const html = renderVNode(
|
|
EmailLink({ href: "https://x", children: "x" })
|
|
);
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a?.attribs.style ?? "").toContain("color:#2563eb");
|
|
});
|
|
|
|
it("respects an explicit colour override", { timeout: 5000 }, () => {
|
|
const html = renderVNode(
|
|
EmailLink({ href: "https://x", children: "x", color: "#00ff00" })
|
|
);
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a?.attribs.style ?? "").toContain("color:#00ff00");
|
|
});
|
|
|
|
it("preserves the href attribute verbatim", { timeout: 5000 }, () => {
|
|
const html = renderVNode(
|
|
EmailLink({
|
|
href: "https://example.test/foo?bar=baz",
|
|
children: "x",
|
|
})
|
|
);
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a?.attribs.href).toBe("https://example.test/foo?bar=baz");
|
|
});
|
|
|
|
it("renders without children", { timeout: 5000 }, () => {
|
|
const html = renderVNode(EmailLink({ href: "https://x" }));
|
|
const a = findFirst(html, (el) => el.name === "a");
|
|
expect(a).not.toBeNull();
|
|
});
|
|
});
|