@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
22import { axe } from 'vitest-axe'
33import { mountSuspended } from '@nuxt/test-utils/runtime'
44import { renderEach } from '../component-render'
5- import ChatMessages from '../../src/runtime/components/ChatMessages.vue'
5+ import ChatMessages , { type ChatMessagesSlots } from '../../src/runtime/components/ChatMessages.vue'
66
77describe ( 'ChatMessages' , ( ) => {
88 const statuses = [ 'ready' , 'submitted' , 'streaming' , 'error' ] as any
@@ -43,4 +43,59 @@ describe('ChatMessages', () => {
4343
4444 expect ( await axe ( wrapper . element ) ) . toHaveNoViolations ( )
4545 } )
46+
47+ it ( 'forwards content slot props together with the deprecated `message`' , async ( ) => {
48+ const messages = [
49+ { id : 'm-1' , role : 'user' as const , parts : [ { type : 'text' as const , text : 'a' } ] , metadata : { foo : 'bar' } } ,
50+ { id : 'm-2' , role : 'assistant' as const , parts : [ { type : 'text' as const , text : 'b' } ] }
51+ ]
52+ const captured : Parameters < Exclude < ChatMessagesSlots [ 'content' ] , undefined > > [ 0 ] [ ] = [ ]
53+ await mountSuspended ( ChatMessages , {
54+ props : { messages } ,
55+ slots : {
56+ content : ( slotProps ) => {
57+ captured . push ( slotProps )
58+ return 'x'
59+ }
60+ }
61+ } )
62+
63+ expect ( captured ) . toHaveLength ( 2 )
64+ expect ( captured [ 0 ] ) . toMatchObject ( {
65+ id : 'm-1' ,
66+ role : 'user' ,
67+ parts : messages [ 0 ] ! . parts ,
68+ metadata : { foo : 'bar' } ,
69+ message : messages [ 0 ]
70+ } )
71+ expect ( captured [ 1 ] ) . toMatchObject ( {
72+ id : 'm-2' ,
73+ role : 'assistant' ,
74+ parts : messages [ 1 ] ! . parts ,
75+ message : messages [ 1 ]
76+ } )
77+ } )
78+
79+ it ( 'forwards `message` to the actions slot' , async ( ) => {
80+ const captured : Parameters < Exclude < ChatMessagesSlots [ 'actions' ] , undefined > > [ 0 ] [ ] = [ ]
81+ await mountSuspended ( ChatMessages , {
82+ props : {
83+ ...props ,
84+ user : { actions : [ { icon : 'i-lucide-copy' , label : 'Copy' } ] } ,
85+ assistant : { actions : [ { icon : 'i-lucide-copy' , label : 'Copy' } ] }
86+ } ,
87+ slots : {
88+ actions : ( slotProps ) => {
89+ captured . push ( slotProps )
90+ return 'x'
91+ }
92+ }
93+ } )
94+
95+ expect ( captured . length ) . toBeGreaterThan ( 0 )
96+ for ( const p of captured ) {
97+ expect ( p ) . toHaveProperty ( 'message' )
98+ expect ( p ) . toHaveProperty ( 'actions' )
99+ }
100+ } )
46101} )
0 commit comments