test: tighten shared join and message content coverage

This commit is contained in:
Peter Steinberger 2026-03-13 21:46:20 +00:00
parent 2d7a061161
commit ae5563dd18
2 changed files with 19 additions and 0 deletions

View File

@ -18,6 +18,19 @@ describe("shared/chat-message-content", () => {
).toBe("");
});
it("only considers the first content block even if later blocks have text", () => {
expect(
extractFirstTextBlock({
content: [null, { text: "later" }],
}),
).toBeUndefined();
expect(
extractFirstTextBlock({
content: [{ type: "image" }, { text: "later" }],
}),
).toBeUndefined();
});
it("returns undefined for missing, empty, or non-text content", () => {
expect(extractFirstTextBlock(null)).toBeUndefined();
expect(extractFirstTextBlock({ content: [] })).toBeUndefined();

View File

@ -13,6 +13,8 @@ describe("concatOptionalTextSegments", () => {
it("falls back to whichever side is present and honors custom separators", () => {
expect(concatOptionalTextSegments({ left: "A" })).toBe("A");
expect(concatOptionalTextSegments({ right: "B" })).toBe("B");
expect(concatOptionalTextSegments({ left: "", right: "B" })).toBe("B");
expect(concatOptionalTextSegments({ left: "" })).toBe("");
expect(concatOptionalTextSegments({ left: "A", right: "B", separator: " | " })).toBe("A | B");
});
});
@ -36,4 +38,8 @@ describe("joinPresentTextSegments", () => {
"A | B",
);
});
it("preserves segment whitespace when trim is disabled", () => {
expect(joinPresentTextSegments(["A", " B "], { separator: "|" })).toBe("A| B ");
});
});