Menu
Public repository / 3af23b0e937520000e1aa43c7e2eb9de2675abd1
AkurAI-Mail / src/lib/webmail/recipients.test.ts
Latest change 22202d1bde69be4ace8a299dffd91f8ff24378df - Recover deployed webmail frontend (frontend parity with EC2 a6afffc) by Ólafur Búi Ólafsson
import { describe, expect, test } from "bun:test";
import { completeRecipient, currentTerm, extractEmail, matchSuggestions, mergeRecent, recipientSuggestions, splitRecipients } from "./recipients";
describe("recipients", () => {
test("splits comma lists", () => {
expect(splitRecipients(" a@x.is, ,b@x.is ")).toEqual(["a@x.is", "b@x.is"]);
});
test("puts new recent recipients first without case-insensitive duplicates, capped at 20", () => {
expect(mergeRecent(["B@x.is"], "a@x.is, b@x.is")).toEqual(["a@x.is", "B@x.is"]);
const many = Array.from({ length: 25 }, (_, i) => `u${i}@x.is`);
expect(mergeRecent([], many.join(","))).toHaveLength(20);
expect(mergeRecent(["a@x.is"], " ")).toEqual(["a@x.is"]);
});
test("suggests contacts then recent addresses that are not contacts", () => {
expect(recipientSuggestions([{ name: "A", email: "a@x.is" }], ["A@x.is", "b@x.is"])).toEqual([{ name: "A", email: "a@x.is" }, { email: "b@x.is" }]);
});
test("matches the term being typed and skips already chosen addresses", () => {
const pool = [{ email: "anna@x.is" }, { email: "ann@y.is" }, { email: "bob@x.is" }];
expect(currentTerm("bob@x.is, an")).toBe("an");
expect(matchSuggestions("ann@y.is, an", pool).map((s) => s.email)).toEqual(["anna@x.is"]);
expect(matchSuggestions("", pool)).toEqual([]);
});
test("completes the current term and leaves room for the next", () => {
expect(completeRecipient("bob@x.is, an", "anna@x.is")).toBe("bob@x.is, anna@x.is, ");
});
test("extracts the bare address", () => {
expect(extractEmail(`"Anna" <Anna@X.is>`)).toBe("anna@x.is");
expect(extractEmail("nobody")).toBe("");
});
});