Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/packages/email-templates/src/sequences-edge.test.ts
T
2026-07-08 16:15:37 +02:00

117 lines
3.6 KiB
TypeScript

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,");
});
});