47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { expect, test } from "bun:test";
|
|
import { createRequire } from "node:module";
|
|
import type { BlockDocument } from "@wrnexus/blocks";
|
|
import { renderEmail } from "../src/index.ts";
|
|
const compile = createRequire(import.meta.url)("mjml");
|
|
|
|
test("survey MJML button inherits brand color and preserves safe text fallback", async () => {
|
|
const document: BlockDocument = {
|
|
schemaVersion: 1,
|
|
kind: "email",
|
|
meta: { subject: "Survey" },
|
|
theme: { tokens: {} },
|
|
root: {
|
|
id: "root",
|
|
type: "layout.email-document",
|
|
version: 1,
|
|
props: { width: "600", linkColor: "#a12345" },
|
|
styles: {},
|
|
slots: {
|
|
content: [
|
|
{
|
|
id: "survey",
|
|
type: "content.survey",
|
|
version: 1,
|
|
props: {
|
|
question: "How was your visit?",
|
|
buttonLabel: "Answer & share",
|
|
href: "https://example.com/survey",
|
|
},
|
|
styles: {},
|
|
slots: {},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
const result = await renderEmail(document, { mjml: true });
|
|
if (!result.ok) throw new Error("Render failed");
|
|
expect(result.value.parts.text.content).toContain(
|
|
"How was your visit?\nAnswer & share: https://example.com/survey",
|
|
);
|
|
const compiled = await compile(result.value.exports!.mjml!, { validationLevel: "strict" });
|
|
expect(compiled.errors).toEqual([]);
|
|
expect(compiled.html).toContain("background:#a12345");
|
|
expect(compiled.html).toContain("Answer & share");
|
|
});
|