From 7b20b8051ce41ac9d0bcc614c5862690cdb412fd Mon Sep 17 00:00:00 2001 From: Donald Kibet Date: Sat, 14 Oct 2023 16:47:21 +0300 Subject: [PATCH] (fix) fix broken unit test --- .../field/address/address-field.component.tsx | 17 +++++++++-------- .../address-hierarchy-levels.component.tsx | 4 +++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx index e2ee25ab1..b8253767b 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-field.component.tsx @@ -18,7 +18,6 @@ function parseString(xmlDockAsString: string) { export const AddressComponent: React.FC = () => { const [selected, setSelected] = useState(''); const { addressTemplate } = useContext(ResourcesContext); - const allRequiredFields = addressTemplate?.requiredElements?.reduce((acc, curr) => ({ ...acc, [curr]: curr }), {}); const addressLayout = useMemo(() => { if (!addressTemplate?.lines) { return []; @@ -26,13 +25,15 @@ export const AddressComponent: React.FC = () => { const allFields = addressTemplate?.lines?.flat(); const fields = allFields?.filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); - - return fields.map(({ displayText, codeName }) => ({ - id: codeName, - name: codeName, - label: displayText, - required: Boolean(allRequiredFields[codeName]), - })); + const allRequiredFields = Object.fromEntries(addressTemplate?.requiredElements?.map((curr) => [curr, curr]) || []); + return fields.map(({ displayText, codeName }) => { + return { + id: codeName, + name: codeName, + label: displayText, + required: Boolean(allRequiredFields[codeName]), + }; + }); }, [addressTemplate]); const { t } = useTranslation(); diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx index cafc78122..23ac24895 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/address-hierarchy-levels.component.tsx @@ -37,6 +37,7 @@ const AddressComboBox: React.FC = ({ attribute }) => { const [field, meta, { setValue }] = useField(`address.${attribute.name}`); const { fetchEntriesForField, searchString, updateChildElements } = useAddressEntryFetchConfig(attribute.name); const { entries } = useAddressEntries(fetchEntriesForField, searchString); + const label = t(attribute.label) + (attribute?.required ? '' : ` (${t('optional', 'optional')})`); const handleInputChange = useCallback( (newValue) => { @@ -63,7 +64,8 @@ const AddressComboBox: React.FC = ({ attribute }) => { fieldProps={{ ...field, id: attribute.name, - labelText: `${t(attribute.label)} (${t('optional', 'optional')})`, + labelText: label, + required: attribute?.required, }} handleInputChange={handleInputChange} />