SPB Git

Repository Public

insights.test.ts 2.9 KB 44 lines typescript

1// Tests purs des aperçus de boîte (sans modèle) : forme, lignes, pastilles.2import assert from "node:assert/strict"3import { test } from "node:test"4import { insightChips, insightRows, normalizeInsights } from "./insights"56const msg = (id: string, thread: string, at: string, o: Record<string, unknown> = {}) => ({7  mailbox_id: "mb", email_id: id, thread_id: thread, from: [{ email: "camille@example.org", name: "Camille" }], to: [{ email: "moi@example.org", name: null }], subject: `Objet ${id}`, preview: "", received_at: at,8  keywords: [], mailbox_ids: ["in"], has_attachment: false, size: 10, ...o,9})1011test("normalizeInsights : réponse inattendue → listes vides ; entrées incomplètes écartées", () => {12  assert.deepEqual(normalizeInsights(null, "mb"), { mailbox_id: "mb", newsletters: [], needs_reply: [], unanswered_sent: [], generated_at: "" })13  const i = normalizeInsights({ mailbox_id: "mb", ai: false, newsletters: [msg("a", "t1", "2026-11-20T10:00:00Z"), { email_id: "x" }, "y"], needs_reply: "non", generated_at: "2026-11-20T12:00:00Z" })14  assert.equal(i.newsletters.length, 1)15  assert.deepEqual(i.newsletters[0].folder_roles, [])16  assert.deepEqual(i.needs_reply, [])17  assert.equal(i.generated_at, "2026-11-20T12:00:00Z")18})1920test("insightRows : du plus récent au plus ancien, une ligne par conversation, bonne vue", () => {21  const i = normalizeInsights({22    mailbox_id: "mb",23    newsletters: [msg("old", "t1", "2026-11-18T10:00:00Z", { keywords: ["$seen"] }), msg("new", "t2", "2026-11-20T10:00:00Z"), msg("dup", "t2", "2026-11-19T10:00:00Z")],24    needs_reply: [msg("r", "t3", "2026-11-17T10:00:00Z", { from: [{ email: "seul@example.org", name: " " }] })],25    unanswered_sent: [msg("s", "t4", "2026-11-10T10:00:00Z", { from: [{ email: "moi@example.org", name: "Moi" }], to: [{ email: "dest@example.org", name: "Destinataire" }] })],26  })27  const n = insightRows(i, "newsletters")28  assert.deepEqual(n.map((r) => r.emailId), ["new", "old"])29  assert.deepEqual(n.map((r) => r.unread), [true, false])30  assert.equal(n[0].who, "Camille")31  assert.equal(n[0].view, "inbox")32  assert.equal(insightRows(i, "needs_reply")[0].who, "seul@example.org", "nom vide → adresse")33  const s = insightRows(i, "unanswered_sent")[0]34  assert.deepEqual([s.who, s.view, s.unread], ["Destinataire", "sent", false])35  assert.deepEqual(insightRows(null, "newsletters"), [])36})3738test("insightChips : seulement les aperçus non vides, ordre stable, comptes par conversation", () => {39  assert.deepEqual(insightChips(null), [])40  assert.deepEqual(insightChips(normalizeInsights({})), [])41  const i = normalizeInsights({ unanswered_sent: [msg("s", "t4", "2026-11-10T10:00:00Z")], newsletters: [msg("a", "t1", "2026-11-18T10:00:00Z"), msg("b", "t1", "2026-11-19T10:00:00Z"), msg("c", "t2", "2026-11-19T11:00:00Z")] })42  assert.deepEqual(insightChips(i), [{ kind: "newsletters", count: 2 }, { kind: "unanswered_sent", count: 1 }])43})44
Files main
Menu

Theme