31 lines
1.8 KiB
TypeScript
31 lines
1.8 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("MJML preserves document metadata and global typography in compiled HTML", async () => {
|
|
const document: BlockDocument = {
|
|
schemaVersion: 1, kind: "email", meta: { subject: 'Brand & "News" <today>', preheader: 'Preview <safe> & useful', lang: "en" }, theme: { tokens: {} },
|
|
root: { id: "root", type: "layout.email-document", version: 1, props: { width: "600", fontFamily: "Georgia, serif", textColor: "#123456" }, styles: {}, slots: {
|
|
content: [{ id: "text", type: "content.text", version: 1, props: { text: "Brand text" }, styles: {}, slots: {} }, { id: "button", type: "content.button", version: 1, props: { label: "Brand action", href: "https://example.com" }, styles: {}, slots: {} }],
|
|
} },
|
|
};
|
|
const before = structuredClone(document);
|
|
const result = await renderEmail(document, { mjml: true });
|
|
expect(result.ok).toBe(true);
|
|
if (!result.ok) return;
|
|
const source = result.value.exports!.mjml!;
|
|
expect(source).toContain('<mj-title>Brand & "News" <today></mj-title>');
|
|
expect(source).toContain('<mj-preview>Preview <safe> & useful</mj-preview>');
|
|
expect(source).toContain('<mj-all font-family="Georgia, serif" />');
|
|
const compiled = await compile(source, { validationLevel: "strict", minify: false });
|
|
expect(compiled.errors).toEqual([]);
|
|
expect(compiled.html).toContain("font-family:Georgia, serif");
|
|
expect(compiled.html).toContain("color:#123456");
|
|
expect(compiled.html).toContain("Preview <safe> & useful");
|
|
expect(compiled.html).not.toContain("<safe>");
|
|
expect(document).toEqual(before);
|
|
});
|