import test from "node:test"; import assert from "node:assert/strict"; import { buildMailtoUrl } from "../js/mailto.js"; test("builds a plain mailto URL when there is no subject or body", () => { assert.equal(buildMailtoUrl({ to: "ada@example.com" }), "mailto:ada@example.com"); }); test("includes subject and body as URL-encoded query parameters", () => { const url = buildMailtoUrl({ to: "owner@example.com", subject: "Hello, Ada!", body: "Line one\nLine two & ", }); assert.ok(url.startsWith("mailto:owner@example.com?")); const params = new URL(url).searchParams; assert.equal(params.get("subject"), "Hello, Ada!"); assert.equal(params.get("body"), "Line one\nLine two & "); }); test("omits empty subject and body", () => { const url = buildMailtoUrl({ to: "owner@example.com", subject: "", body: "" }); assert.equal(url, "mailto:owner@example.com"); }); test("encodes spaces and special characters so the mail client opens pre-filled", () => { const url = buildMailtoUrl({ to: "o@example.com", subject: "a b", body: "x&y=z" }); const params = new URL(url).searchParams; assert.equal(params.get("subject"), "a b"); assert.equal(params.get("body"), "x&y=z"); });