Align email buttons consistently across formats and directions
Quality / quality (ubuntu-latest) (push) Failing after 0s
Quality / quality (windows-latest) (push) Canceled after 0s

This commit is contained in:
Clintchiz committed 2026-09-05 16:21:08 +05:30
1 parent f9cf2a648a
commit 7110e1a7f1
3 files changed
+33 -6

No files matched your search

@@ -2,6 +2,27 @@ import { expect, test } from "bun:test";
import type { BlockDocument } from "@wrnexus/blocks";
import { renderEmail, validateMjml } from "../src/index.ts";
test("button alignment maps physical and logical positions consistently in LTR and RTL", async () => {
for (const direction of ["ltr", "rtl"] as const) {
for (const alignment of [undefined, "left", "center", "right", "start", "end"]) {
const expected = !alignment || alignment === "start" ? (direction === "rtl" ? "right" : "left") : alignment === "end" ? (direction === "rtl" ? "left" : "right") : alignment;
const document: BlockDocument = {
schemaVersion: 1, kind: "email", meta: { subject: "Alignment", lang: "en" }, theme: { tokens: {} },
root: { id: "root", type: "layout.email-document", version: 1, props: { width: "600" }, styles: {}, slots: {
content: [{ id: "cta", type: "content.button", version: 1, props: { label: "Act", href: "https://example.com" }, styles: alignment ? { textAlign: { base: alignment } } : {}, slots: {} }],
} },
};
const rendered = await renderEmail(document, { direction, amp: true, mjml: true, ampValidationTimeoutMs: 10000 });
expect(rendered.ok).toBe(true);
if (!rendered.ok) continue;
expect(rendered.value.parts.html.content).toContain(`<table role="presentation" align="${expected}" cellpadding="0"`);
expect(rendered.value.parts.amp?.content).toContain(`data-block-id="cta" align="${expected}"`);
expect(rendered.value.parts.amp?.validation.valid).toBe(true);
expect(rendered.value.exports?.mjml).toContain(`<mj-button align="${expected}"`);
}
}
});
test("button typography and corners reach the clickable element in every target", async () => {
const document: BlockDocument = {
schemaVersion: 1, kind: "email", meta: { subject: "Styled CTA", lang: "en" }, theme: { tokens: {} },