Skip to content

Commit 992d011

Browse files
committed
Fix unit tests
Signed-off-by: Lin Wang <[email protected]>
1 parent 4e43621 commit 992d011

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/plugins/chat/public/components/chat_suggestions.test.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('ChatSuggestions', () => {
1717
let mockSuggestedActionsService: any;
1818
let mockChatService: any;
1919
let mockMessages: Message[];
20+
let mockMessage: Message;
2021

2122
beforeEach(() => {
2223
jest.clearAllMocks();
@@ -35,6 +36,12 @@ describe('ChatSuggestions', () => {
3536
},
3637
] as Message[];
3738

39+
mockMessage = {
40+
id: 'msg-2',
41+
role: 'assistant',
42+
content: 'Hi there!',
43+
};
44+
3845
// Setup mock services
3946
mockChatService = {
4047
getThreadId: jest.fn().mockReturnValue('thread-123'),
@@ -67,7 +74,7 @@ describe('ChatSuggestions', () => {
6774

6875
mockSuggestedActionsService.getCustomSuggestions.mockResolvedValue(mockSuggestions);
6976

70-
render(<ChatSuggestions messages={mockMessages} />);
77+
render(<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />);
7178

7279
// Wait for suggestions to load
7380
await waitFor(() => {
@@ -83,7 +90,9 @@ describe('ChatSuggestions', () => {
8390
// Mock a promise that never resolves to simulate loading state
8491
mockSuggestedActionsService.getCustomSuggestions.mockReturnValue(new Promise(() => {}));
8592

86-
const { container } = render(<ChatSuggestions messages={mockMessages} />);
93+
const { container } = render(
94+
<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />
95+
);
8796

8897
// Component should render nothing while loading
8998
expect(container.firstChild).toBeNull();
@@ -92,7 +101,9 @@ describe('ChatSuggestions', () => {
92101
it('should not render anything when no custom suggestions are available', async () => {
93102
mockSuggestedActionsService.getCustomSuggestions.mockResolvedValue([]);
94103

95-
const { container } = render(<ChatSuggestions messages={mockMessages} />);
104+
const { container } = render(
105+
<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />
106+
);
96107

97108
// Wait for the async operation to complete
98109
await waitFor(() => {
@@ -109,7 +120,9 @@ describe('ChatSuggestions', () => {
109120
new Error('Failed to load suggestions')
110121
);
111122

112-
const { container } = render(<ChatSuggestions messages={mockMessages} />);
123+
const { container } = render(
124+
<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />
125+
);
113126

114127
// Wait for the async operation to complete
115128
await waitFor(() => {
@@ -128,7 +141,7 @@ describe('ChatSuggestions', () => {
128141
it('should call getCustomSuggestions with correct context', async () => {
129142
mockSuggestedActionsService.getCustomSuggestions.mockResolvedValue([]);
130143

131-
render(<ChatSuggestions messages={mockMessages} />);
144+
render(<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />);
132145

133146
await waitFor(() => {
134147
expect(mockSuggestedActionsService.getCustomSuggestions).toHaveBeenCalledWith({
@@ -151,7 +164,7 @@ describe('ChatSuggestions', () => {
151164

152165
mockSuggestedActionsService.getCustomSuggestions.mockResolvedValue(mockSuggestions);
153166

154-
render(<ChatSuggestions messages={mockMessages} />);
167+
render(<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />);
155168

156169
// Wait for suggestions to load
157170
await waitFor(() => {
@@ -177,7 +190,7 @@ describe('ChatSuggestions', () => {
177190

178191
mockSuggestedActionsService.getCustomSuggestions.mockResolvedValue(mockSuggestions);
179192

180-
render(<ChatSuggestions messages={mockMessages} />);
193+
render(<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />);
181194

182195
await waitFor(() => {
183196
expect(screen.getByText('Custom suggestion')).toBeInTheDocument();
@@ -200,7 +213,7 @@ describe('ChatSuggestions', () => {
200213

201214
mockSuggestedActionsService.getCustomSuggestions.mockResolvedValue(mockSuggestions);
202215

203-
render(<ChatSuggestions messages={mockMessages} />);
216+
render(<ChatSuggestions messages={mockMessages} currentMessage={mockMessage} />);
204217

205218
await waitFor(() => {
206219
expect(screen.getByText('Default suggestion')).toBeInTheDocument();

0 commit comments

Comments
 (0)