33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6- import React from 'react' ;
76import { ChatPlugin } from './plugin' ;
87import { ChatService } from './services/chat_service' ;
98import { 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