You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.6 KiB
42 lines
1.6 KiB
import { describe, expect, it } from "vitest";
|
|
import {
|
|
htmlToPlainText,
|
|
plainTextFromMaybeHtml,
|
|
resolveParsedMailBody,
|
|
} from "@/utils/mail-body-text";
|
|
|
|
describe("mail-body-text", () => {
|
|
it("htmlToPlainText keeps line breaks and Chinese", () => {
|
|
const html =
|
|
"<div>\u8bf7\u67e5\u6536\u65b0\u589e\u9884\u62a5\uff1a\u65b0\u8fb0\u6cfd</div><br/><p>\u67dc\u53f7\uff1aWHSU8127240</p>";
|
|
const t = htmlToPlainText(html);
|
|
expect(t).toContain("\u8bf7\u67e5\u6536\u65b0\u589e\u9884\u62a5\uff1a\u65b0\u8fb0\u6cfd");
|
|
expect(t).toContain("\u67dc\u53f7\uff1aWHSU8127240");
|
|
});
|
|
|
|
it("prefers fuller HTML when text/plain is a stub", () => {
|
|
const body = resolveParsedMailBody({
|
|
text: "\u8bf7\u67e5\u6536\u90ae\u4ef6",
|
|
html: "<div>\u8bf7\u67e5\u6536\u65b0\u589e\u9884\u62a5\uff1a\u65b0\u8fb0\u6cfd+WHLC027G597465+WHSU8127240+\u6d1b\u6749\u77f6+40HQ</div><p>DO\u4e5f\u540c\u6b65\u4e0a\u4f20\uff0c\u8bf7\u6ce8\u610f\u67e5\u6536\uff01</p>",
|
|
});
|
|
expect(body).toContain("WHSU8127240");
|
|
expect(body).toContain("DO\u4e5f\u540c\u6b65\u4e0a\u4f20");
|
|
});
|
|
|
|
it("keeps longer HTML over short text/plain", () => {
|
|
const long = "\u5b8c\u6574\u8f6c\u53d1\u6b63\u6587\u5185\u5bb9".repeat(20);
|
|
const body = resolveParsedMailBody({
|
|
text: "short stub",
|
|
html: `<div>${long}</div>`,
|
|
});
|
|
expect(body.length).toBeGreaterThan(40);
|
|
expect(body).toContain("\u5b8c\u6574\u8f6c\u53d1\u6b63\u6587\u5185\u5bb9");
|
|
});
|
|
|
|
it("plainTextFromMaybeHtml leaves plain text alone", () => {
|
|
expect(plainTextFromMaybeHtml("\u67dc\u53f7\uff1aMATU2745683")).toBe(
|
|
"\u67dc\u53f7\uff1aMATU2745683",
|
|
);
|
|
});
|
|
});
|