import type { ReactNode } from "react"; import { renderToString } from "react-dom/server"; import { describe, expect, it, vi } from "vitest"; vi.mock("@lingui/react/macro", () => { const t = (parts: TemplateStringsArray, ...values: unknown[]) => parts.reduce((text, part, index) => `${text}${part}${values[index] ?? ""}`, ""); return { useLingui: () => ({ t }), Trans: ({ children }: { children: ReactNode }) => children }; }); import { DelegatedTaskCard, SentMessageCard } from "./DelegatedTaskCard"; const task = { botId: "researcher", botName: "Researcher", color: "#14B8A6", title: "Owl facts", text: "Collect three owl facts.", }; describe("delegated task card", () => { it.each([ ["queued", "Queued"], ["running", "Working…"], ["waiting", "Needs you"], ["done", "Done"], ["failed", "Failed"], ["cancelled", "Cancelled"], ] as const)("labels a %s task as %s", (status, label) => { const html = renderToString(); expect(html).toContain(`data-status="${status}"`); expect(html).toContain(label); }); it("shows who and what up front and folds the brief", () => { const html = renderToString(); expect(html).toContain('data-testid="delegated-task-card"'); expect(html).toMatch(/]*>/); expect(html).not.toMatch(/]*open/); expect(html).toContain("Researcher"); expect(html).toContain("Owl facts"); expect(html).toContain("Collect three owl facts."); expect(html).toContain("rakazo-bot-avatar"); }); }); describe("sent message card", () => { it("names the recipient without a status the message does not have", () => { const html = renderToString( undefined} />, ); expect(html).toContain('aria-label="Messaged Researcher"'); expect(html).toContain("peer-exchange-alpha"); expect(html).not.toContain("Working"); expect(html).not.toContain("Delegiert"); }); });