import { describe, expect, it } from "vitest"; import { plainTextToComposerBody, rewriteCidImagesForEditor, replaceInlineImagePlaceholders, INLINE_IMAGE_PLACEHOLDER, splitRecipients, formatRecipient, parseRecipient, parseRecipientList, formatRecipientList, splitPastedRecipients, waitForPendingUploads, } from "../email-composer-utils"; describe("plainTextToComposerBody", () => { it("returns an empty string for empty input", () => { expect(plainTextToComposerBody("")).toBe(""); }); it("escapes HTML before building composer paragraphs", () => { expect(plainTextToComposerBody("")).toBe( "
<script>alert('x') & "q"</script>
" ); }); it("normalizes line endings and preserves single line breaks", () => { expect(plainTextToComposerBody("line1\r\nline2\rline3")).toBe( "line1
line2
line3
first
second
third
hi
';
expect(rewriteCidImagesForEditor(html)).toBe(html);
});
it("handles empty input", () => {
expect(rewriteCidImagesForEditor("")).toBe("");
});
it("rewrites a cid: src to placeholder + data-cid", () => {
const out = rewriteCidImagesForEditor(
'
';
const out = replaceInlineImagePlaceholders(
html,
new Map([["abc", "data:image/png;base64,AAAA"]])
);
expect(out).toContain('src="https://example.com/other.png"');
expect(out).not.toContain("data:image/png;base64,AAAA");
});
it("leaves unknown cids untouched", () => {
const html = `