From 3dca4977e49d1d4ca754010d482142ddb8638bc8 Mon Sep 17 00:00:00 2001 From: William Wong Date: Tue, 14 Feb 2023 22:41:39 +0000 Subject: [PATCH] Fix tests --- __tests__/html/useTextBoxSubmit.true.html | 46 ------------------- __tests__/html/useTextBoxSubmit.true.js | 3 -- packages/component/src/BasicSendBox.tsx | 16 ++----- packages/component/src/Composer.tsx | 8 +++- .../internal/SendBox/SendBoxComposer.tsx | 13 ++++-- .../internal/SendBox/private/types.ts | 2 +- .../providers/internal/SendBox/useSubmit.ts | 2 +- 7 files changed, 20 insertions(+), 70 deletions(-) delete mode 100644 __tests__/html/useTextBoxSubmit.true.html delete mode 100644 __tests__/html/useTextBoxSubmit.true.js diff --git a/__tests__/html/useTextBoxSubmit.true.html b/__tests__/html/useTextBoxSubmit.true.html deleted file mode 100644 index d81350a1a3..0000000000 --- a/__tests__/html/useTextBoxSubmit.true.html +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - -
- - - diff --git a/__tests__/html/useTextBoxSubmit.true.js b/__tests__/html/useTextBoxSubmit.true.js deleted file mode 100644 index fdd4125b75..0000000000 --- a/__tests__/html/useTextBoxSubmit.true.js +++ /dev/null @@ -1,3 +0,0 @@ -/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ - -test('useTextBoxSubmit and set focus to true', () => runHTML('useTextBoxSubmit.true.html')); diff --git a/packages/component/src/BasicSendBox.tsx b/packages/component/src/BasicSendBox.tsx index 12fd192633..93362c69a9 100644 --- a/packages/component/src/BasicSendBox.tsx +++ b/packages/component/src/BasicSendBox.tsx @@ -6,7 +6,6 @@ import React, { FC } from 'react'; import DictationInterims from './SendBox/DictationInterims'; import MicrophoneButton from './SendBox/MicrophoneButton'; -import SendBoxComposer from './providers/internal/SendBox/SendBoxComposer'; import SendButton from './SendBox/SendButton'; import SuggestedActions from './SendBox/SuggestedActions'; import TextBox from './SendBox/TextBox'; @@ -53,7 +52,7 @@ type BasicSendBoxProps = { className?: string; }; -const BasicSendBoxCore: FC = ({ className }) => { +const BasicSendBox: FC = ({ className }) => { const [{ hideUploadButton, sendBoxButtonAlignment }] = useStyleOptions(); const [{ sendBox: sendBoxStyleSet }] = useStyleSet(); const [{ SpeechRecognition = undefined } = {}] = useWebSpeechPonyfill(); @@ -98,23 +97,14 @@ const BasicSendBoxCore: FC = ({ className }) => { ); }; -BasicSendBoxCore.defaultProps = { +BasicSendBox.defaultProps = { className: '' }; -BasicSendBoxCore.propTypes = { +BasicSendBox.propTypes = { className: PropTypes.string }; -const BasicSendBox: FC = (props: BasicSendBoxProps) => ( - - - -); - -BasicSendBox.defaultProps = BasicSendBoxCore.defaultProps; -BasicSendBox.propTypes = BasicSendBoxCore.propTypes; - export default BasicSendBox; export { useSendBoxSpeechInterimsVisible }; diff --git a/packages/component/src/Composer.tsx b/packages/component/src/Composer.tsx index 2aa602c89c..354478b457 100644 --- a/packages/component/src/Composer.tsx +++ b/packages/component/src/Composer.tsx @@ -27,6 +27,7 @@ import Dictation from './Dictation'; import downscaleImageToDataURL from './Utils/downscaleImageToDataURL'; import ErrorBox from './ErrorBox'; import mapMap from './Utils/mapMap'; +import SendBoxComposer from './providers/internal/SendBox/SendBoxComposer'; import UITracker from './hooks/internal/UITracker'; import WebChatUIContext from './hooks/internal/WebChatUIContext'; @@ -227,8 +228,11 @@ const ComposerCore: FC = ({ return ( - {children} - + {/* When is finalized, it will be using an independent instance that lives inside . */} + + {children} + + ); diff --git a/packages/component/src/providers/internal/SendBox/SendBoxComposer.tsx b/packages/component/src/providers/internal/SendBox/SendBoxComposer.tsx index bb251e3fcc..a36e29f0c8 100644 --- a/packages/component/src/providers/internal/SendBox/SendBoxComposer.tsx +++ b/packages/component/src/providers/internal/SendBox/SendBoxComposer.tsx @@ -39,8 +39,13 @@ const TIME_TO_RESET_ERROR_MESSAGE = 50; // This component is marked as internal because it is not fully implemented and is not ready to be consumed publicly. // When it is done, it should provide and replace all the functionalities we did in Redux, including but not limited to: -// - Speech interims -// - Maintain text box value + +// - Speech interims +// - Maintain text box value +// - Multiple in a single Web Chat instance +// - Web devs should be able to put an individual send box instance into an activity +// - The send box instance in the activity, should be separated from the bottommost send box +// - The valued typed inside the activity, should be separated from the value typed into the bottommost send box // In the old days, we use Redux to keep the send box state. // However, when web devs put 2 send box on their page, it makes things complex because both send boxes will interact with each other. @@ -88,8 +93,8 @@ const SendBoxComposer = ({ children }: PropsWithChildren<{}>) => { const submit = useCallback( ({ setFocus } = {}) => { - (setFocus === 'sendBox' || setFocus === 'sendBoxWithoutKeyboard') && - focusRef.current?.(setFocus === 'sendBox' ? 'sendBox' : 'sendBoxWithoutKeyboard'); + (setFocus === 'main' || setFocus === 'sendBox' || setFocus === 'sendBoxWithoutKeyboard') && + focusRef.current?.(setFocus === 'main' || setFocus === 'sendBox' ? setFocus : 'sendBoxWithoutKeyboard'); const { current: submitError } = submitErrorRef; diff --git a/packages/component/src/providers/internal/SendBox/private/types.ts b/packages/component/src/providers/internal/SendBox/private/types.ts index 4999411414..b192ec01fc 100644 --- a/packages/component/src/providers/internal/SendBox/private/types.ts +++ b/packages/component/src/providers/internal/SendBox/private/types.ts @@ -1,5 +1,5 @@ export type ContextType = { - submit: (options?: { setFocus?: 'sendBox' | 'sendBoxWithoutKeyboard' }) => void; + submit: (options?: { setFocus?: 'main' | 'sendBox' | 'sendBoxWithoutKeyboard' }) => void; submitErrorMessageIdState: readonly [string]; }; diff --git a/packages/component/src/providers/internal/SendBox/useSubmit.ts b/packages/component/src/providers/internal/SendBox/useSubmit.ts index 1e17ab1f4e..576f3b6357 100644 --- a/packages/component/src/providers/internal/SendBox/useSubmit.ts +++ b/packages/component/src/providers/internal/SendBox/useSubmit.ts @@ -1,7 +1,7 @@ import useSendBoxContext from './private/useContext'; type SubmitOptions = { - setFocus?: 'sendBox' | 'sendBoxWithoutKeyboard'; + setFocus?: 'main' | 'sendBox' | 'sendBoxWithoutKeyboard'; }; /**