Files
Moltbot/src/shared/shared-misc.test.ts
2026-03-13 20:23:26 +00:00

43 lines
1.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { extractTextFromChatContent } from "./chat-content.js";
describe("extractTextFromChatContent", () => {
it("normalizes string content", () => {
expect(extractTextFromChatContent(" hello\nworld ")).toBe("hello world");
});
it("extracts text blocks from array content", () => {
expect(
extractTextFromChatContent([
{ type: "text", text: " hello " },
{ type: "image_url", image_url: "https://example.com" },
{ type: "text", text: "world" },
]),
).toBe("hello world");
});
it("applies sanitizer when provided", () => {
expect(
extractTextFromChatContent("Here [Tool Call: foo (ID: 1)] ok", {
sanitizeText: (text) => text.replace(/\[Tool Call:[^\]]+\]\s*/g, ""),
}),
).toBe("Here ok");
});
it("supports custom join and normalization", () => {
expect(
extractTextFromChatContent(
[
{ type: "text", text: " hello " },
{ type: "text", text: "world " },
],
{
sanitizeText: (text) => text.trim(),
joinWith: "\n",
normalizeText: (text) => text.trim(),
},
),
).toBe("hello\nworld");
});
});