Skip to content

Commit d0bf09b

Browse files
author
Shreyas-Microsoft
committed
fix chatHistoryListItem tests
1 parent 1b79655 commit d0bf09b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frontend/src/components/ChatHistory/chatHistoryListItem.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/Test Chat/i)
166-
expect(titleElement).toBeInTheDocument()
167+
const titleElement = screen.getAllByText(/Test Chat/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(/Test Chat/i));
197+
fireEvent.click(screen.getAllByText(/Test Chat/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 very long title that shoul .../i)
212+
const truncatedTitle = screen.getByText(/A very long title that s .../i)
211213
expect(truncatedTitle).toBeInTheDocument()
212214
})
213215

0 commit comments

Comments
 (0)