55import { createElement } from '@wordpress/element' ;
66import { createRoot } from 'react-dom/client' ;
77import { act } from 'react' ;
8- import { useDispatch , useSelect } from '@wordpress/data' ;
9-
10- import ChatRedesign from '../index' ;
11- import InputArea from '../InputArea' ;
12- import WidgetHeader from '../../chat-widget/widget-header' ;
138
149global . IS_REACT_ACT_ENVIRONMENT = true ;
1510
16- jest . mock ( '@wordpress/data' , ( ) => ( {
17- useDispatch : jest . fn ( ) ,
18- useSelect : jest . fn ( ) ,
11+ const useDispatch = jest . fn ( ) ;
12+ const useSelect = jest . fn ( ) ;
13+ const wordpressData = jest . requireActual ( '@wordpress/data' ) ;
14+
15+ jest . doMock ( '@wordpress/data' , ( ) => ( {
16+ ...wordpressData ,
17+ useDispatch,
18+ useSelect,
1919} ) ) ;
2020
21+ const ChatRedesign = require ( '../index' ) . default ;
22+ const InputArea = require ( '../InputArea' ) . default ;
23+ const WidgetHeader = require ( '../../chat-widget/widget-header' ) . default ;
24+
2125jest . mock ( '@wordpress/i18n' , ( ) => ( {
2226 __ : ( str ) => str ,
2327 _n : ( single , plural , count ) => ( count === 1 ? single : plural ) ,
@@ -35,19 +39,60 @@ jest.mock( '@wordpress/icons', () => ( {
3539 sidebar : 'sidebar' ,
3640} ) ) ;
3741
42+ jest . mock ( '@wordpress/components' , ( ) => {
43+ const React = require ( 'react' ) ;
44+ return {
45+ Button : ( { children, label, disabled, onClick, className } ) =>
46+ React . createElement (
47+ 'button' ,
48+ {
49+ type : 'button' ,
50+ className,
51+ 'aria-label' : label ,
52+ disabled,
53+ onClick,
54+ } ,
55+ children
56+ ) ,
57+ CheckboxControl : ( { label, checked, disabled, onChange } ) =>
58+ React . createElement ( 'input' , {
59+ type : 'checkbox' ,
60+ 'aria-label' : label ,
61+ checked,
62+ disabled,
63+ onChange : ( event ) => onChange ( event . target . checked ) ,
64+ } ) ,
65+ } ;
66+ } ) ;
67+
3868jest . mock ( '@wordpress/api-fetch' , ( ) => jest . fn ( ) ) ;
3969jest . mock ( '../../../store' , ( ) => 'sd-ai-agent' ) ;
4070jest . mock ( '../../../utils/branding' , ( ) => ( {
4171 getBranding : ( ) => ( { agentName : 'Docs Assistant' } ) ,
4272} ) ) ;
4373jest . mock ( '../../use-speech-recognition' , ( ) => ( ) => ( {
74+ cancelListening : jest . fn ( ) ,
75+ detectedLanguage : '' ,
76+ error : null ,
4477 isListening : false ,
4578 isSupported : false ,
79+ isTranscribing : false ,
80+ startListening : jest . fn ( ) ,
81+ status : 'idle' ,
82+ stopListening : jest . fn ( ) ,
4683 toggleListening : jest . fn ( ) ,
4784} ) ) ;
48- jest . mock ( '../../use-text-to-speech' , ( ) => ( {
49- isTTSSupported : false ,
50- } ) ) ;
85+ jest . mock ( '../../use-text-to-speech' , ( ) => {
86+ const useTextToSpeech = ( ) => ( {
87+ cancel : jest . fn ( ) ,
88+ isSpeaking : false ,
89+ isSupported : false ,
90+ speak : jest . fn ( ) ,
91+ } ) ;
92+ useTextToSpeech . isTTSSupported = false ;
93+
94+ return useTextToSpeech ;
95+ } ) ;
5196jest . mock (
5297 '../../slash-command-menu' ,
5398 ( ) => ( ) =>
0 commit comments