@@ -75,12 +75,14 @@ describe('ChatHistoryListItemGroups', () => {
7575 } ) ;
7676 } ) ;
7777
78- test ( 'renders grouped chat history correctly' , ( ) => {
78+ test ( 'renders grouped chat history correctly' , async ( ) => {
7979 renderWithContext ( < ChatHistoryListItemGroups groupedChatHistory = { mockGroupedChatHistory } /> )
8080
8181 // Check if group month and titles are rendered
82- expect ( screen . getByText ( '2024-11' ) ) . toBeInTheDocument ( )
83- expect ( screen . getByText ( 'Chat 1' ) ) . toBeInTheDocument ( )
82+ await waitFor ( ( ) => {
83+ expect ( screen . getByText ( '2024-11' ) ) . toBeInTheDocument ( ) ;
84+ expect ( screen . getAllByText ( 'Chat 1' ) . length ) . toBeGreaterThan ( 1 ) ;
85+ } ) ;
8486 } )
8587
8688 test ( 'displays a spinner when fetching history' , async ( ) => {
@@ -162,8 +164,8 @@ describe('ChatHistoryListItemCell', () => {
162164 test ( 'renders the chat history item' , ( ) => {
163165 renderWithContext ( < ChatHistoryListItemCell item = { conversation } onSelect = { mockOnSelect } /> , mockAppState )
164166
165- const titleElement = screen . getByText ( / T e s t C h a t / i)
166- expect ( titleElement ) . toBeInTheDocument ( )
167+ const titleElement = screen . getAllByText ( / T e s t C h a t / i)
168+ expect ( titleElement . length ) . toBeGreaterThan ( 1 )
167169 } )
168170 // test('calls onSelect when a chat history item is clicked', async () => {
169171 // renderWithContext(<ChatHistoryListItemCell item={conversation} onSelect={mockOnSelect} />, mockAppState)
@@ -192,7 +194,7 @@ describe('ChatHistoryListItemCell', () => {
192194
193195 renderWithContext ( < ChatHistoryListItemCell item = { conversation } onSelect = { mockOnSelect } /> , mockAppState ) ;
194196
195- fireEvent . click ( screen . getByText ( / T e s t C h a t / i) ) ;
197+ fireEvent . click ( screen . getAllByText ( / T e s t C h a t / i) [ 0 ] ) ;
196198
197199 await waitFor ( ( ) => {
198200 expect ( mockOnSelect ) . toHaveBeenCalledWith ( { ...conversation , messages : mockMessages } ) ;
@@ -202,12 +204,12 @@ describe('ChatHistoryListItemCell', () => {
202204 test ( 'truncates long title' , ( ) => {
203205 const longTitleConversation = {
204206 ...conversation ,
205- title : 'A very long title that should be truncated after 28 characters'
207+ title : 'A very long title that should be truncated after 24 characters'
206208 }
207209
208210 renderWithContext ( < ChatHistoryListItemCell item = { longTitleConversation } onSelect = { mockOnSelect } /> , mockAppState )
209211
210- const truncatedTitle = screen . getByText ( / A v e r y l o n g t i t l e t h a t s h o u l .../ i)
212+ const truncatedTitle = screen . getByText ( / A v e r y l o n g t i t l e t h a t s .../ i)
211213 expect ( truncatedTitle ) . toBeInTheDocument ( )
212214 } )
213215
0 commit comments