Open History to see the last commit
1import { renderHook } from '@solidjs/testing-library'
2import { describe, expect, it } from 'vitest'
3import { createChatHook } from '../src/create-chat-hook'
4import { createMockConnectionAdapter } from './test-utils'
5import type { UIMessage } from '../src/types'
6
7describe('createChatHook', () => {
8 it('creates a chat from factory options', () => {
9 const initialMessages: Array<UIMessage> = [
10 {
11 id: 'msg-1',
12 role: 'user',
13 parts: [{ type: 'text', content: 'Hello' }],
14 createdAt: new Date(),
15 },
16 ]
17 const { useChat } = createChatHook({
18 connection: createMockConnectionAdapter(),
19 initialMessages,
20 })
21
22 const chat = renderHook(() => useChat({ threadId: 'thread-1' })).result
23
24 expect(chat.messages()).toEqual(initialMessages)
25 })
26
27 it('merges per-call instance overrides', () => {
28 const { useChat } = createChatHook({
29 connection: createMockConnectionAdapter(),
30 initialMessages: [
31 {
32 id: 'factory',
33 role: 'user',
34 parts: [{ type: 'text', content: 'factory' }],
35 createdAt: new Date(),
36 },
37 ],
38 })
39
40 const overrideMessages: Array<UIMessage> = [
41 {
42 id: 'override',
43 role: 'user',
44 parts: [{ type: 'text', content: 'override' }],
45 createdAt: new Date(),
46 },
47 ]
48 const chat = renderHook(() =>
49 useChat({ initialMessages: overrideMessages, threadId: 'thread-1' }),
50 ).result
51
52 expect(chat.messages()).toEqual(overrideMessages)
53 })
54})