Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2import { toolResultContentToString } from '../../src/chat-ui/tool-result-content'
3
4describe('toolResultContentToString', () => {
5 it('returns string content unchanged', () => {
6 expect(toolResultContentToString('hello world')).toBe('hello world')
7 })
8
9 it('returns an empty string unchanged', () => {
10 expect(toolResultContentToString('')).toBe('')
11 })
12
13 it('concatenates the text parts of array content', () => {
14 const content = [
15 { type: 'text' as const, content: 'first' },
16 { type: 'text' as const, content: 'second' },
17 ]
18 expect(toolResultContentToString(content)).toBe('firstsecond')
19 })
20
21 it('skips non-text parts and keeps surrounding text', () => {
22 const content = [
23 { type: 'text' as const, content: 'before' },
24 {
25 type: 'image' as const,
26 source: { type: 'url' as const, value: 'https://example.com/x.png' },
27 },
28 { type: 'text' as const, content: 'after' },
29 ]
30 expect(toolResultContentToString(content)).toBe('beforeafter')
31 })
32
33 it('returns an empty string when array content has no text parts', () => {
34 const content = [
35 {
36 type: 'image' as const,
37 source: { type: 'url' as const, value: 'https://example.com/x.png' },
38 },
39 ]
40 expect(toolResultContentToString(content)).toBe('')
41 })
42
43 it('returns an empty string for an empty array', () => {
44 expect(toolResultContentToString([])).toBe('')
45 })
46})