68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { renderEmail } from "./render.js";
|
|
import { Layout } from "./components/Layout.js";
|
|
import { Heading, Spacer } from "./components/primitives.js";
|
|
|
|
describe("Layout", () => {
|
|
it("renders title, preview snippet and footer when supplied", () => {
|
|
const { html } = renderEmail(
|
|
Layout({
|
|
children: "BODY-CONTENT-MARKER",
|
|
title: "SUBJECT-LINE",
|
|
previewText: "PREVIEW-SNIPPET",
|
|
footer: "FOOTER-CONTENT",
|
|
})
|
|
);
|
|
expect(html).toContain("<title>SUBJECT-LINE</title>");
|
|
expect(html).toContain("PREVIEW-SNIPPET");
|
|
expect(html).toContain("FOOTER-CONTENT");
|
|
expect(html).toContain("BODY-CONTENT-MARKER");
|
|
// The footer wrapper is the only element that is centred.
|
|
expect(html).toContain("text-align:center");
|
|
});
|
|
|
|
it("omits the title/preview/footer chrome when none are supplied", () => {
|
|
const { html } = renderEmail(Layout({ children: "BODY-ONLY-MARKER" }));
|
|
expect(html).toContain("BODY-ONLY-MARKER");
|
|
// The <html lang> + card wrapper still render, but no optional chrome.
|
|
expect(html).toContain('<html lang="en">');
|
|
expect(html).not.toContain("<title>");
|
|
expect(html).not.toContain("FOOTER-CONTENT");
|
|
expect(html).not.toContain("text-align:center");
|
|
});
|
|
});
|
|
|
|
describe("Heading", () => {
|
|
it("renders an <h1> at the default level", () => {
|
|
const { html } = renderEmail(Heading({ children: "Top" }));
|
|
expect(html).toContain("<h1");
|
|
expect(html).toContain("26px");
|
|
});
|
|
|
|
it("renders an <h2> at level 2", () => {
|
|
const { html } = renderEmail(Heading({ children: "Mid", level: 2 }));
|
|
expect(html).toContain("<h2");
|
|
expect(html).toContain("20px");
|
|
expect(html).not.toContain("<h1");
|
|
});
|
|
|
|
it("renders an <h3> at level 3", () => {
|
|
const { html } = renderEmail(Heading({ children: "Low", level: 3 }));
|
|
expect(html).toContain("<h3");
|
|
expect(html).toContain("17px");
|
|
expect(html).not.toContain("<h2");
|
|
});
|
|
});
|
|
|
|
describe("Spacer", () => {
|
|
it("uses the medium spacing token by default", () => {
|
|
const { html } = renderEmail(Spacer({}));
|
|
expect(html).toContain("height:20px");
|
|
});
|
|
|
|
it("honours an explicit spacing token", () => {
|
|
const { html } = renderEmail(Spacer({ size: "xl" }));
|
|
expect(html).toContain("height:48px");
|
|
});
|
|
});
|