Import supported MJML header metadata and typography
This commit is contained in:
1 parent
69db4bd62e
commit
f5139f2c82
3 files changed
+68
-5
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { createRequire } from "node:module";
|
||||
import type { BlockDocument } from "@wrnexus/blocks";
|
||||
import { renderEmail } from "../src/index.ts";
|
||||
import { renderEmail, importMjml } from "../src/index.ts";
|
||||
|
||||
const compile = createRequire(import.meta.url)("mjml");
|
||||
|
||||
@@ -27,4 +27,28 @@ test("MJML preserves document metadata and global typography in compiled HTML",
|
||||
expect(compiled.html).toContain("Preview <safe> & useful");
|
||||
expect(compiled.html).not.toContain("<safe>");
|
||||
expect(document).toEqual(before);
|
||||
let id = 0;
|
||||
const imported = importMjml(source, { id: () => `import-${++id}` });
|
||||
expect(imported.ok).toBe(true);
|
||||
if (imported.ok) {
|
||||
expect(imported.value.meta.subject).toBe(document.meta.subject);
|
||||
expect(imported.value.meta.preheader).toBe(document.meta.preheader);
|
||||
expect(imported.value.root.props.fontFamily).toBe("Georgia, serif");
|
||||
expect(imported.value.root.props.textColor).toBe("#123456");
|
||||
const rerendered = await renderEmail(imported.value, { mjml: true });
|
||||
expect(rerendered.ok).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
test("MJML header import rejects unsupported globals and unsafe typography", () => {
|
||||
for (const header of [
|
||||
'<mj-attributes><mj-all padding="20px" /></mj-attributes>',
|
||||
'<mj-attributes><mj-all font-family="Arial;position:fixed" /></mj-attributes>',
|
||||
'<mj-attributes><mj-text font-size="20px" /></mj-attributes>',
|
||||
'<mj-style>.test{color:red}</mj-style>',
|
||||
'<mj-breakpoint width="900px" />',
|
||||
]) {
|
||||
let id = 0;
|
||||
expect(importMjml(`<mjml><mj-head>${header}</mj-head><mj-body><mj-section><mj-column><mj-text>Text</mj-text></mj-column></mj-section></mj-body></mjml>`, { id: () => `n${++id}` }).ok).toBe(false);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user