Skip to content

Commit a086559

Browse files
committed
Fix failed unit tests
Signed-off-by: Lin Wang <[email protected]>
1 parent 09b9f43 commit a086559

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/plugins/chat/public/plugin.test.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import React from 'react';
76
import { ChatPlugin } from './plugin';
87
import { ChatService } from './services/chat_service';
98
import { toMountPoint } from '../../opensearch_dashboards_react/public';
@@ -255,17 +254,11 @@ describe('ChatPlugin', () => {
255254
);
256255
});
257256

258-
it('should call startNewConversation when global search action is triggered', async () => {
259-
const mockStartNewConversation = jest.fn().mockResolvedValue(undefined);
260-
261-
// Mock React.createRef to return a ref with our mock function
262-
const mockRef = {
263-
current: {
264-
startNewConversation: mockStartNewConversation,
265-
},
266-
};
267-
jest.spyOn(React, 'createRef').mockReturnValue(mockRef as any);
268-
257+
it('should call sendMessageWithWindow when global search action is triggered', async () => {
258+
const sendMessageWithWindowMock = jest.fn();
259+
jest
260+
.spyOn(ChatService.prototype, 'sendMessageWithWindow')
261+
.mockImplementationOnce(sendMessageWithWindowMock);
269262
plugin.start(mockCoreStart, mockDeps);
270263

271264
const registerCall = (mockCoreStart.chrome.globalSearch.registerSearchCommand as jest.Mock)
@@ -275,7 +268,9 @@ describe('ChatPlugin', () => {
275268
// Trigger the action
276269
await commandConfig.action({ content: 'test query' });
277270

278-
expect(mockStartNewConversation).toHaveBeenCalledWith({ content: 'test query' });
271+
expect(sendMessageWithWindowMock).toHaveBeenCalledWith('test query', [], {
272+
clearConversation: true,
273+
});
279274
});
280275
});
281276

0 commit comments

Comments
 (0)