Skip to content

Commit

Permalink
(fix) fix broken unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldkibet committed Oct 14, 2023
1 parent 88b336f commit 7b20b80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ 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 [];
}

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const AddressComboBox: React.FC<AddressComboBoxProps> = ({ 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) => {
Expand All @@ -63,7 +64,8 @@ const AddressComboBox: React.FC<AddressComboBoxProps> = ({ attribute }) => {
fieldProps={{
...field,
id: attribute.name,
labelText: `${t(attribute.label)} (${t('optional', 'optional')})`,
labelText: label,
required: attribute?.required,
}}
handleInputChange={handleInputChange}
/>
Expand Down

0 comments on commit 7b20b80

Please sign in to comment.