Skip to content

Commit fac68e4

Browse files
authored
test: preserve WordPress data exports in simple mode test (#2675)
1 parent deda60f commit fac68e4

1 file changed

Lines changed: 56 additions & 11 deletions

File tree

src/components/chat-redesign/__tests__/customer-simple-mode.test.js

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
import { createElement } from '@wordpress/element';
66
import { createRoot } from 'react-dom/client';
77
import { 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

149
global.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+
2125
jest.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+
3868
jest.mock( '@wordpress/api-fetch', () => jest.fn() );
3969
jest.mock( '../../../store', () => 'sd-ai-agent' );
4070
jest.mock( '../../../utils/branding', () => ( {
4171
getBranding: () => ( { agentName: 'Docs Assistant' } ),
4272
} ) );
4373
jest.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+
} );
5196
jest.mock(
5297
'../../slash-command-menu',
5398
() => () =>

0 commit comments

Comments
 (0)