Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+67
@@ -0,0 +1,67 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
theme,
|
||||
renderEmail,
|
||||
htmlToPlainText,
|
||||
Layout,
|
||||
Heading,
|
||||
Paragraph,
|
||||
Spacer,
|
||||
Button,
|
||||
Footer,
|
||||
WelcomeEmail,
|
||||
TrialReminderEmail,
|
||||
ReActivationEmail,
|
||||
GenericStepEmail,
|
||||
} from "./index.js";
|
||||
|
||||
describe("public API barrel", () => {
|
||||
it("re-exports the render helpers and theme tokens", () => {
|
||||
expect(typeof renderEmail).toBe("function");
|
||||
expect(typeof htmlToPlainText).toBe("function");
|
||||
expect(htmlToPlainText("<p>Hello</p>")).toBe("Hello");
|
||||
expect(theme.colors.primary).toBe("#2563eb");
|
||||
expect(theme.containerWidth).toBe(600);
|
||||
});
|
||||
|
||||
it("re-exports the layout and primitive components", () => {
|
||||
for (const component of [Layout, Heading, Paragraph, Spacer, Button, Footer]) {
|
||||
expect(typeof component).toBe("function");
|
||||
}
|
||||
});
|
||||
|
||||
it("re-exports every sequence template and renders through the barrel", () => {
|
||||
for (const template of [WelcomeEmail, TrialReminderEmail, ReActivationEmail, GenericStepEmail]) {
|
||||
expect(typeof template).toBe("function");
|
||||
}
|
||||
const { html, text } = renderEmail(
|
||||
WelcomeEmail({
|
||||
productName: "ToolCtrl",
|
||||
ctaUrl: "https://app.example.com/onboard",
|
||||
unsubscribeUrl: "https://app.example.com/unsubscribe/tok",
|
||||
})
|
||||
);
|
||||
expect(html.startsWith("<!DOCTYPE html>")).toBe(true);
|
||||
expect(html).toContain("Welcome to ToolCtrl");
|
||||
expect(text).toContain("Welcome to ToolCtrl");
|
||||
});
|
||||
});
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* Ships pre-built React-Email-style templates for the sequence engine.
|
||||
* `renderEmail(<Template props />)` returns `{ html, text }` ready for
|
||||
* any `@toolctrl/mail` `SendMailInput`. Theme tokens + layout primitives
|
||||
* any `@hivegrid/mail` `SendMailInput`. Theme tokens + layout primitives
|
||||
* are reusable for additional sequences operators define in the admin
|
||||
* UI (when wired to a runtime template-registry).
|
||||
*/
|
||||
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { renderEmail } from "./render.js";
|
||||
import { WelcomeEmail } from "./sequences/welcome.js";
|
||||
import { TrialReminderEmail } from "./sequences/trial-reminder.js";
|
||||
import { ReActivationEmail } from "./sequences/re-activation.js";
|
||||
import { GenericStepEmail } from "./sequences/generic-step.js";
|
||||
|
||||
const UNSUBSCRIBE = "https://app.example.com/unsubscribe/tok";
|
||||
|
||||
describe("GenericStepEmail edge cases", () => {
|
||||
it("greets a provided recipientName and omits the CTA when no url is given", () => {
|
||||
const { html, text } = renderEmail(
|
||||
GenericStepEmail({
|
||||
productName: "ToolCtrl",
|
||||
recipientName: "Grace",
|
||||
headline: "Step",
|
||||
bodyParagraphs: ["Body."],
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
})
|
||||
);
|
||||
expect(text).toContain("Hi Grace,");
|
||||
// No ctaUrl -> default CTA label must not appear.
|
||||
expect(html).not.toContain("Open dashboard");
|
||||
});
|
||||
|
||||
it("honours a ctaLabel override and renders the preface node", () => {
|
||||
const { html } = renderEmail(
|
||||
GenericStepEmail({
|
||||
productName: "ToolCtrl",
|
||||
headline: "Step",
|
||||
bodyParagraphs: ["Body."],
|
||||
ctaUrl: "https://app.example.com/go",
|
||||
ctaLabel: "Jump in",
|
||||
preface: "PREFACE-LINE",
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
})
|
||||
);
|
||||
expect(html).toContain("Jump in");
|
||||
expect(html).not.toContain("Open dashboard");
|
||||
expect(html).toContain("PREFACE-LINE");
|
||||
expect(html).toContain("https://app.example.com/go");
|
||||
});
|
||||
|
||||
it("falls back to the generic recipient when recipientName is whitespace only", () => {
|
||||
const { text } = renderEmail(
|
||||
GenericStepEmail({
|
||||
productName: "ToolCtrl",
|
||||
recipientName: " ",
|
||||
headline: "Step",
|
||||
bodyParagraphs: ["Body."],
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
})
|
||||
);
|
||||
expect(text).toContain("Hi there,");
|
||||
});
|
||||
});
|
||||
|
||||
describe("TrialReminderEmail edge cases", () => {
|
||||
it("greets a provided recipientName", () => {
|
||||
const { text } = renderEmail(
|
||||
TrialReminderEmail({
|
||||
productName: "ToolCtrl",
|
||||
recipientName: "Linus",
|
||||
daysRemaining: 5,
|
||||
upgradeUrl: "https://app.example.com/upgrade",
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
})
|
||||
);
|
||||
expect(text).toContain("Hi Linus,");
|
||||
});
|
||||
});
|
||||
|
||||
describe("ReActivationEmail edge cases", () => {
|
||||
it("greets a provided recipientName", () => {
|
||||
const { text } = renderEmail(
|
||||
ReActivationEmail({
|
||||
productName: "ToolCtrl",
|
||||
recipientName: "Margaret",
|
||||
returnUrl: "https://app.example.com/back",
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
})
|
||||
);
|
||||
expect(text).toContain("Hi Margaret,");
|
||||
});
|
||||
});
|
||||
|
||||
describe("WelcomeEmail edge cases", () => {
|
||||
it("uses the senderName in the signoff when provided", () => {
|
||||
const { text } = renderEmail(
|
||||
WelcomeEmail({
|
||||
productName: "ToolCtrl",
|
||||
ctaUrl: "https://app.example.com/onboard",
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
senderName: "Ada from ToolCtrl",
|
||||
})
|
||||
);
|
||||
expect(text).toContain("Ada from ToolCtrl");
|
||||
// The "<sender> ??" left branch wins, so the team fallback must be absent.
|
||||
expect(text).not.toContain("The ToolCtrl team");
|
||||
});
|
||||
|
||||
it("honours a ctaLabel override and falls back on a blank recipient", () => {
|
||||
const { html, text } = renderEmail(
|
||||
WelcomeEmail({
|
||||
productName: "ToolCtrl",
|
||||
ctaUrl: "https://app.example.com/onboard",
|
||||
ctaLabel: "Start now",
|
||||
recipientName: " ",
|
||||
unsubscribeUrl: UNSUBSCRIBE,
|
||||
})
|
||||
);
|
||||
expect(html).toContain("Start now");
|
||||
expect(html).not.toContain("Get started");
|
||||
expect(text).toContain("Hi there,");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user