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 174742b8e..b7f892a83 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 @@ -19,10 +19,10 @@ export const AddressComponent: React.FC = () => { const [selected, setSelected] = useState(''); const { addressTemplate } = useContext(ResourcesContext); const addressLayout = useMemo(() => { - if (!addressTemplate) { + if (!addressTemplate?.lines) { return []; } - const allFields = addressTemplate.lines.flat(); + const allFields = addressTemplate?.lines?.flat(); const fields = allFields?.filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); return fields.map(({ displayText, codeName }) => ({ diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-hierarchy.test.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-hierarchy.test.tsx index 076eccbd8..ac7706102 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-hierarchy.test.tsx @@ -6,7 +6,7 @@ import { Resources, ResourcesContext } from '../../../../offline.resources'; import { PatientRegistrationContext } from '../../../patient-registration-context'; import { useConfig } from '@openmrs/esm-framework'; import { useOrderedAddressHierarchyLevels } from '../address-hierarchy.resource'; -import { mockResponse, mockedOrderedFields } from './mocks'; +import { mockedAddressTemplate, mockedOrderedFields } from './mocks'; // Mocking the AddressSearchComponent jest.mock('../address-search.component', () => jest.fn(() =>
)); @@ -29,7 +29,7 @@ jest.mock('../address-hierarchy.resource', () => ({ useOrderedAddressHierarchyLevels: jest.fn(), })); -async function renderAddressHierarchy(addressTemplate = mockResponse) { +async function renderAddressHierarchy(addressTemplate = mockedAddressTemplate) { await render( @@ -131,7 +131,7 @@ describe('Testing address hierarchy', () => { errorFetchingFieldOrder: null, })); renderAddressHierarchy(); - const allFields = mockResponse.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); + const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); allFields.forEach((field) => { const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`); expect(textFieldInput).toBeInTheDocument(); @@ -156,10 +156,11 @@ describe('Testing address hierarchy', () => { errorFetchingFieldOrder: null, })); renderAddressHierarchy(); - const allFields = mockResponse.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); + const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN'); const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx])); allFields.sort( - (existingField1, existingField2) => orderMap[existingField1.codeName] - orderMap[existingField2.codeName], + (existingField1, existingField2) => + orderMap[existingField1.codeName ?? 0] - orderMap[existingField2.codeName ?? 0], ); allFields.forEach((field) => { const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`); diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-search-component.test.tsx b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-search-component.test.tsx index 45b3e4329..3f1ccad76 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-search-component.test.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/address-search-component.test.tsx @@ -5,7 +5,7 @@ import { Resources, ResourcesContext } from '../../../../offline.resources'; import { PatientRegistrationContext } from '../../../patient-registration-context'; import { useConfig } from '@openmrs/esm-framework'; import { useAddressHierarchy, useOrderedAddressHierarchyLevels } from '../address-hierarchy.resource'; -import { mockResponse, mockedAddressOptions, mockedOrderedFields } from './mocks'; +import { mockedAddressTemplate, mockedAddressOptions, mockedOrderedFields } from './mocks'; import AddressSearchComponent from '../address-search.component'; import userEvent from '@testing-library/user-event'; @@ -31,7 +31,7 @@ jest.mock('formik', () => ({ useFormikContext: jest.fn(() => ({})), })); -const allFields = mockResponse.lines +const allFields = mockedAddressTemplate.lines .flat() .filter((field) => field.isToken === 'IS_ADDR_TOKEN') .map(({ codeName, displayText }) => ({ @@ -42,7 +42,7 @@ const allFields = mockResponse.lines const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx])); allFields.sort((existingField1, existingField2) => orderMap[existingField1.name] - orderMap[existingField2.name]); -async function renderAddressHierarchy(addressTemplate = mockResponse) { +async function renderAddressHierarchy(addressTemplate = mockedAddressTemplate) { await render( diff --git a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts index 6a2872755..d554f96b6 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts +++ b/packages/esm-patient-registration-app/src/patient-registration/field/address/tests/mocks.ts @@ -1,6 +1,6 @@ import { AddressTemplate } from '../../../patient-registration-types'; -export const mockResponse: AddressTemplate = { +export const mockedAddressTemplate: AddressTemplate = { displayName: null, codeName: 'default', country: null, diff --git a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx index 6c9904afb..10cb3186d 100644 --- a/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx +++ b/packages/esm-patient-registration-app/src/patient-registration/patient-registration.test.tsx @@ -10,6 +10,7 @@ import { Encounter } from './patient-registration-types'; import { Resources, ResourcesContext } from '../offline.resources'; import { PatientRegistration } from './patient-registration.component'; import { RegistrationConfig } from '../config-schema'; +import { mockedAddressTemplate } from './field/address/tests/mocks'; const mockedUseConfig = useConfig as jest.Mock; const mockedUsePatient = usePatient as jest.Mock; @@ -56,17 +57,8 @@ jest.mock('@openmrs/esm-framework', () => { }; }); -const predefinedAddressTemplate = { - results: [ - { - value: - '\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n address1 address2\r\n cityVillage stateProvince postalCode\r\n country\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n ', - }, - ], -}; - const mockResourcesContextValue = { - addressTemplate: predefinedAddressTemplate, + addressTemplate: mockedAddressTemplate, currentSession: { authenticated: true, sessionId: 'JSESSION', @@ -87,9 +79,11 @@ let mockOpenmrsConfig: RegistrationConfig = { fieldConfigurations: { name: { displayMiddleName: true, - unidentifiedPatient: true, + allowUnidentifiedPatients: true, defaultUnknownGivenName: 'UNKNOWN', defaultUnknownFamilyName: 'UNKNOWN', + displayReverseFieldOrder: false, + displayCapturePhoto: true, }, gender: [ {