Files
T

41 lines
2.0 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { renderReactEmail } from "../render-helpers.js";
import { defaultMailBrand, withBrandDefaults } from "../_layout/theme.js";
import { InvalidActionUrlError } from "../_layout/Button.js";
import { WelcomeEmail } from "./Welcome.js";
describe("WelcomeEmail", () => {
test("renders default-brand named welcome (snapshot)", () => {
const result = renderReactEmail(<WelcomeEmail brand={defaultMailBrand} recipientName="Ada" actionUrl="https://app.example.com/login" />);
expect(result.html).toMatchSnapshot("html");
expect(result.text).toMatchSnapshot("text");
});
test("falls back to anonymous greeting when name missing", () => {
const { html } = renderReactEmail(<WelcomeEmail brand={defaultMailBrand} actionUrl="https://app.example.com/login" />);
expect(html).toContain("Welcome!");
expect(html).not.toContain("Welcome, ");
});
test("applies safe tenant copy and color overrides without replacing the HiveGrid logo", () => {
const brand = withBrandDefaults({ productName: "Acme", primaryColor: "#123456", logoUrl: "https://cdn.acme.test/l.png" });
const { html } = renderReactEmail(<WelcomeEmail brand={brand} recipientName="Ada" actionUrl="https://app.acme.test/login" />);
expect(html).toContain("Welcome to Acme, Ada!");
expect(html).toContain("#123456");
expect(html).toContain("https://hivegrid.de/hivegrid-logo.png");
expect(html).not.toContain("https://cdn.acme.test/l.png");
});
test("escapes user content via React (XSS-safe)", () => {
const { html } = renderReactEmail(
<WelcomeEmail brand={defaultMailBrand} recipientName="<script>alert(1)</script>" actionUrl="https://app.example.com/login" />
);
expect(html).not.toContain("<script>alert(1)</script>");
expect(html).toContain("&lt;script&gt;");
});
test("rejects insecure action URLs", () => {
expect(() => renderReactEmail(<WelcomeEmail brand={defaultMailBrand} actionUrl="javascript:alert(1)" />)).toThrow(InvalidActionUrlError);
});
});