From d3894081f63cef1845080603fdd6a652d65256dd Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 3 Mar 2023 21:12:24 -0500 Subject: [PATCH] fix(striker-ui): add input tests to CommonUpsInputGroup --- .../ManageUps/CommonUpsInputGroup.tsx | 131 ++++++++++++------ striker-ui/types/CommonUpsInputGroup.d.ts | 5 +- 2 files changed, 95 insertions(+), 41 deletions(-) diff --git a/striker-ui/components/ManageUps/CommonUpsInputGroup.tsx b/striker-ui/components/ManageUps/CommonUpsInputGroup.tsx index 6e1d49a9..7e744061 100644 --- a/striker-ui/components/ManageUps/CommonUpsInputGroup.tsx +++ b/striker-ui/components/ManageUps/CommonUpsInputGroup.tsx @@ -1,53 +1,104 @@ -import { FC } from 'react'; +import { ReactElement } from 'react'; import Grid from '../Grid'; import InputWithRef from '../InputWithRef'; import OutlinedInputWithLabel from '../OutlinedInputWithLabel'; +import { + buildIPAddressTestBatch, + buildPeacefulStringTestBatch, +} from '../../lib/test_input'; const INPUT_ID_UPS_IP = 'common-ups-input-ip-address'; const INPUT_ID_UPS_NAME = 'common-ups-input-host-name'; -const CommonUpsInputGroup: FC = ({ +const INPUT_LABEL_UPS_IP = 'IP address'; +const INPUT_LABEL_UPS_NAME = 'Host name'; + +const CommonUpsInputGroup = < + M extends { + [K in typeof INPUT_ID_UPS_IP | typeof INPUT_ID_UPS_NAME]: string; + }, +>({ + formUtils: { + buildFinishInputTestBatchFunction, + buildInputFirstRenderFunction, + msgSetters, + }, previous: { upsIPAddress: previousIpAddress, upsName: previousUpsName } = {}, -}) => ( - <> - - } - required - /> - ), - }, - 'common-ups-input-cell-ip-address': { - children: ( - - } - required - /> - ), - }, - }} - spacing="1em" - /> - +}: CommonUpsInputGroupProps): ReactElement => ( + + } + inputTestBatch={buildPeacefulStringTestBatch( + INPUT_LABEL_UPS_NAME, + () => { + msgSetters[INPUT_ID_UPS_NAME](); + }, + { + onFinishBatch: + buildFinishInputTestBatchFunction(INPUT_ID_UPS_NAME), + }, + (message) => { + msgSetters[INPUT_ID_UPS_NAME]({ + children: message, + }); + }, + )} + onFirstRender={buildInputFirstRenderFunction(INPUT_ID_UPS_NAME)} + required + /> + ), + }, + 'common-ups-input-cell-ip-address': { + children: ( + + } + inputTestBatch={buildIPAddressTestBatch( + INPUT_LABEL_UPS_IP, + () => { + msgSetters[INPUT_ID_UPS_IP](); + }, + { + onFinishBatch: + buildFinishInputTestBatchFunction(INPUT_ID_UPS_IP), + }, + (message) => { + msgSetters[INPUT_ID_UPS_IP]({ + children: message, + }); + }, + )} + onFirstRender={buildInputFirstRenderFunction(INPUT_ID_UPS_IP)} + required + /> + ), + }, + }} + spacing="1em" + /> ); -export { INPUT_ID_UPS_IP, INPUT_ID_UPS_NAME }; +export { + INPUT_ID_UPS_IP, + INPUT_ID_UPS_NAME, + INPUT_LABEL_UPS_IP, + INPUT_LABEL_UPS_NAME, +}; export default CommonUpsInputGroup; diff --git a/striker-ui/types/CommonUpsInputGroup.d.ts b/striker-ui/types/CommonUpsInputGroup.d.ts index da058a40..020f814f 100644 --- a/striker-ui/types/CommonUpsInputGroup.d.ts +++ b/striker-ui/types/CommonUpsInputGroup.d.ts @@ -5,4 +5,7 @@ type CommonUpsInputGroupOptionalProps = { }; }; -type CommonUpsInputGroupProps = CommonUpsInputGroupOptionalProps; +type CommonUpsInputGroupProps = + CommonUpsInputGroupOptionalProps & { + formUtils: FormUtils; + };