openclaw/src/shared/chat-message-content.test.ts
2026-03-13 20:28:22 +00:00

20 lines
734 B
TypeScript

import { describe, expect, it } from "vitest";
import { extractFirstTextBlock } from "./chat-message-content.js";
describe("shared/chat-message-content", () => {
it("extracts the first text block from array content", () => {
expect(
extractFirstTextBlock({
content: [{ text: "hello" }, { text: "world" }],
}),
).toBe("hello");
});
it("returns undefined for missing, empty, or non-text content", () => {
expect(extractFirstTextBlock(null)).toBeUndefined();
expect(extractFirstTextBlock({ content: [] })).toBeUndefined();
expect(extractFirstTextBlock({ content: [{ type: "image" }] })).toBeUndefined();
expect(extractFirstTextBlock({ content: ["hello"] })).toBeUndefined();
});
});