@kenyaemr/esm-patient-registration-app 7.0.3-pre.88 → 7.0.3-pre.94

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/.turbo/turbo-build.log +15 -14
  2. package/dist/130.js +1 -1
  3. package/dist/130.js.map +1 -1
  4. package/dist/271.js +1 -1
  5. package/dist/319.js +1 -1
  6. package/dist/460.js +1 -1
  7. package/dist/564.js +1 -0
  8. package/dist/564.js.map +1 -0
  9. package/dist/623.js +1 -0
  10. package/dist/623.js.map +1 -0
  11. package/dist/644.js +1 -1
  12. package/dist/757.js +1 -1
  13. package/dist/788.js +1 -1
  14. package/dist/807.js +1 -1
  15. package/dist/831.js +2 -0
  16. package/dist/831.js.map +1 -0
  17. package/dist/833.js +1 -1
  18. package/dist/kenyaemr-esm-patient-registration-app.js +1 -1
  19. package/dist/kenyaemr-esm-patient-registration-app.js.buildmanifest.json +99 -99
  20. package/dist/main.js +1 -1
  21. package/dist/main.js.map +1 -1
  22. package/dist/routes.json +1 -1
  23. package/package.json +1 -1
  24. package/src/add-patient-link.test.tsx +5 -9
  25. package/src/config-schema.ts +2 -0
  26. package/src/nav-link.test.tsx +3 -3
  27. package/src/patient-registration/field/address/address-field.component.tsx +2 -2
  28. package/src/patient-registration/field/address/address-hierarchy-levels.component.tsx +16 -18
  29. package/src/patient-registration/field/address/address-search.scss +5 -5
  30. package/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +165 -95
  31. package/src/patient-registration/field/address/tests/address-search-component.test.tsx +18 -17
  32. package/src/patient-registration/field/dob/dob.component.tsx +3 -6
  33. package/src/patient-registration/field/dob/dob.test.tsx +69 -53
  34. package/src/patient-registration/field/field.scss +30 -25
  35. package/src/patient-registration/field/field.test.tsx +50 -52
  36. package/src/patient-registration/field/gender/gender-field.component.tsx +2 -2
  37. package/src/patient-registration/field/gender/gender-field.test.tsx +45 -27
  38. package/src/patient-registration/field/id/id-field.component.tsx +11 -12
  39. package/src/patient-registration/field/id/id-field.test.tsx +64 -49
  40. package/src/patient-registration/field/id/identifier-selection.scss +12 -8
  41. package/src/patient-registration/field/name/name-field.component.tsx +1 -1
  42. package/src/patient-registration/field/obs/obs-field.component.tsx +7 -12
  43. package/src/patient-registration/field/obs/obs-field.test.tsx +98 -62
  44. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +9 -6
  45. package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +49 -51
  46. package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +2 -0
  47. package/src/patient-registration/input/basic-input/select/select-input.test.tsx +1 -1
  48. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.scss +5 -5
  49. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +75 -33
  50. package/src/patient-registration/input/custom-input/identifier/identifier-input.component.tsx +3 -1
  51. package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +9 -12
  52. package/src/patient-registration/input/dummy-data/dummy-data-input.test.tsx +2 -11
  53. package/src/patient-registration/input/input.scss +12 -12
  54. package/src/patient-registration/patient-registration-context.ts +6 -6
  55. package/src/patient-registration/patient-registration-utils.ts +4 -5
  56. package/src/patient-registration/patient-registration.component.tsx +4 -14
  57. package/src/patient-registration/patient-registration.resource.test.tsx +0 -4
  58. package/src/patient-registration/patient-registration.scss +11 -25
  59. package/src/patient-registration/patient-registration.test.tsx +75 -85
  60. package/src/patient-registration/patient-registration.types.ts +18 -18
  61. package/src/patient-registration/section/death-info/death-info-section.test.tsx +1 -10
  62. package/src/patient-registration/section/demographics/demographics-section.test.tsx +32 -29
  63. package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +16 -6
  64. package/src/patient-registration/section/patient-relationships/relationships.scss +4 -4
  65. package/src/patient-registration/section/section-wrapper.component.tsx +1 -1
  66. package/src/patient-registration/section/section.scss +16 -1
  67. package/src/patient-registration/ui-components/overlay/overlay.scss +8 -8
  68. package/src/patient-registration/validation/patient-registration-validation.test.tsx +35 -10
  69. package/src/patient-verification/patient-verification-utils.ts +0 -1
  70. package/src/widgets/cancel-patient-edit.test.tsx +0 -4
  71. package/src/widgets/delete-identifier-confirmation.scss +8 -8
  72. package/src/widgets/delete-identifier-confirmation.test.tsx +0 -4
  73. package/src/widgets/edit-patient-details-button.test.tsx +2 -8
  74. package/translations/am.json +4 -0
  75. package/translations/ar.json +4 -0
  76. package/translations/es.json +4 -0
  77. package/translations/fr.json +4 -0
  78. package/translations/he.json +4 -0
  79. package/translations/km.json +4 -0
  80. package/translations/zh.json +4 -0
  81. package/translations/zh_CN.json +4 -0
  82. package/dist/266.js +0 -2
  83. package/dist/266.js.map +0 -1
  84. package/dist/453.js +0 -1
  85. package/dist/453.js.map +0 -1
  86. package/dist/975.js +0 -1
  87. package/dist/975.js.map +0 -1
  88. package/src/root.test.tsx +0 -32
  89. /package/dist/{266.js.LICENSE.txt → 831.js.LICENSE.txt} +0 -0
@@ -1,68 +1,91 @@
1
1
  import React from 'react';
2
2
  import userEvent from '@testing-library/user-event';
3
3
  import { render, screen } from '@testing-library/react';
4
+ import { Form, Formik } from 'formik';
5
+ import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework';
4
6
  import { Identifiers } from './id-field.component';
7
+ import { mockOpenmrsId, mockIdentifierTypes, mockPatient, mockSession } from '__mocks__';
8
+ import { type RegistrationConfig, esmPatientRegistrationSchema } from '../../../config-schema';
5
9
  import { type Resources, ResourcesContext } from '../../../offline.resources';
6
- import { Form, Formik } from 'formik';
7
- import { PatientRegistrationContext } from '../../patient-registration-context';
8
- import { openmrsID, mockedIdentifierTypes } from '__mocks__';
10
+ import { PatientRegistrationContext, type PatientRegistrationContextProps } from '../../patient-registration-context';
11
+
12
+ const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
13
+
14
+ const mockResourcesContextValue = {
15
+ addressTemplate: null,
16
+ currentSession: mockSession.data,
17
+ identifierTypes: [],
18
+ relationshipTypes: [],
19
+ } as Resources;
20
+
21
+ const mockInitialFormValues = {
22
+ additionalFamilyName: '',
23
+ additionalGivenName: '',
24
+ additionalMiddleName: '',
25
+ addNameInLocalLanguage: false,
26
+ address: {},
27
+ birthdate: null,
28
+ birthdateEstimated: false,
29
+ deathCause: '',
30
+ deathDate: '',
31
+ familyName: 'Doe',
32
+ gender: 'male',
33
+ givenName: 'John',
34
+ identifiers: mockOpenmrsId,
35
+ isDead: false,
36
+ middleName: 'Test',
37
+ monthsEstimated: 0,
38
+ patientUuid: mockPatient.uuid,
39
+ relationships: [],
40
+ telephoneNumber: '',
41
+ yearsEstimated: 0,
42
+ };
9
43
 
10
- jest.mock('@openmrs/esm-framework', () => ({
11
- ...jest.requireActual('@openmrs/esm-framework'),
12
- useConfig: jest.fn().mockImplementation(() => ({
13
- defaultPatientIdentifierTypes: ['OpenMRS ID'],
14
- })),
15
- }));
44
+ const mockContextValues: PatientRegistrationContextProps = {
45
+ currentPhoto: null,
46
+ inEditMode: false,
47
+ identifierTypes: [],
48
+ initialFormValues: mockInitialFormValues,
49
+ isOffline: false,
50
+ setCapturePhotoProps: jest.fn(),
51
+ setFieldValue: jest.fn(),
52
+ setInitialFormValues: jest.fn(),
53
+ validationSchema: null,
54
+ values: mockInitialFormValues,
55
+ };
16
56
 
17
57
  describe('Identifiers', () => {
18
- const mockResourcesContextValue = {
19
- addressTemplate: {},
20
- currentSession: {
21
- authenticated: true,
22
- sessionId: 'JSESSION',
23
- currentProvider: { uuid: 'provider-uuid', identifier: 'PRO-123' },
24
- },
25
- relationshipTypes: [],
26
- identifierTypes: [...mockedIdentifierTypes],
27
- } as Resources;
58
+ beforeEach(() => {
59
+ mockUseConfig.mockReturnValue({
60
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
61
+ defaultPatientIdentifierTypes: ['OpenMRS ID'],
62
+ });
63
+ });
28
64
 
29
65
  it('should render loading skeleton when identifier types are loading', () => {
30
66
  render(
31
- <ResourcesContext.Provider value={[]}>
67
+ <ResourcesContext.Provider value={mockResourcesContextValue}>
32
68
  <Formik initialValues={{}} onSubmit={null}>
33
69
  <Form>
34
- <PatientRegistrationContext.Provider
35
- value={{
36
- setFieldValue: jest.fn(),
37
- initialFormValues: { identifiers: { ...mockedIdentifierTypes[0] } },
38
- setInitialFormValues: jest.fn(),
39
- values: {
40
- identifiers: { openmrsID },
41
- },
42
- }}>
70
+ <PatientRegistrationContext.Provider value={mockContextValues}>
43
71
  <Identifiers />
44
72
  </PatientRegistrationContext.Provider>
45
73
  </Form>
46
74
  </Formik>
47
75
  </ResourcesContext.Provider>,
48
76
  );
49
- expect(screen.getByTestId('loading-skeleton')).toBeInTheDocument();
77
+
78
+ expect(screen.getByRole('progressbar')).toBeInTheDocument();
50
79
  });
51
80
 
52
81
  it('should render identifier inputs when identifier types are loaded', () => {
82
+ mockResourcesContextValue.identifierTypes = mockIdentifierTypes;
83
+
53
84
  render(
54
85
  <ResourcesContext.Provider value={mockResourcesContextValue}>
55
86
  <Formik initialValues={{}} onSubmit={null}>
56
87
  <Form>
57
- <PatientRegistrationContext.Provider
58
- value={{
59
- setFieldValue: jest.fn(),
60
- initialFormValues: { identifiers: { ...mockedIdentifierTypes[0] } },
61
- setInitialFormValues: jest.fn(),
62
- values: {
63
- identifiers: { openmrsID },
64
- },
65
- }}>
88
+ <PatientRegistrationContext.Provider value={mockContextValues}>
66
89
  <Identifiers />
67
90
  </PatientRegistrationContext.Provider>
68
91
  </Form>
@@ -78,20 +101,12 @@ describe('Identifiers', () => {
78
101
 
79
102
  it('should open identifier selection overlay when "Configure" button is clicked', async () => {
80
103
  const user = userEvent.setup();
81
-
104
+ mockResourcesContextValue.identifierTypes = mockIdentifierTypes;
82
105
  render(
83
106
  <ResourcesContext.Provider value={mockResourcesContextValue}>
84
107
  <Formik initialValues={{}} onSubmit={null}>
85
108
  <Form>
86
- <PatientRegistrationContext.Provider
87
- value={{
88
- setFieldValue: jest.fn(),
89
- initialFormValues: { identifiers: { ...mockedIdentifierTypes[0] } },
90
- setInitialFormValues: jest.fn(),
91
- values: {
92
- identifiers: { openmrsID },
93
- },
94
- }}>
109
+ <PatientRegistrationContext.Provider value={mockContextValues}>
95
110
  <Identifiers />
96
111
  </PatientRegistrationContext.Provider>
97
112
  </Form>
@@ -1,8 +1,8 @@
1
- @use '@carbon/styles/scss/spacing';
2
- @import '../../patient-registration.scss';
1
+ @use '@carbon/layout';
2
+ @use '@openmrs/esm-styleguide/src/vars' as *;
3
3
 
4
4
  .button {
5
- height: 4rem;
5
+ height: layout.$spacing-10;
6
6
  display: flex;
7
7
  align-content: flex-start;
8
8
  align-items: baseline;
@@ -10,28 +10,32 @@
10
10
  }
11
11
 
12
12
  .tablet {
13
- padding: 1.5rem 1rem;
13
+ padding: layout.$spacing-06 layout.$spacing-05;
14
14
  background-color: $ui-02;
15
15
  }
16
16
 
17
17
  .desktop {
18
- padding: 0rem;
18
+ padding: 0;
19
19
  }
20
20
 
21
21
  .radioGroup {
22
22
  background-color: $ui-01;
23
- padding: spacing.$spacing-05;
23
+ padding: layout.$spacing-05;
24
24
  }
25
25
 
26
26
  .radioButton {
27
27
  margin: 0 !important;
28
28
  label {
29
- height: spacing.$spacing-07;
29
+ height: layout.$spacing-07;
30
30
  }
31
31
  }
32
32
 
33
+ .space05 {
34
+ margin: layout.$spacing-05 0;
35
+ }
36
+
33
37
  :global(.omrs-breakpoint-lt-desktop) {
34
38
  .radioButton label {
35
- height: spacing.$spacing-09 !important;
39
+ height: layout.$spacing-09 !important;
36
40
  }
37
41
  }
@@ -5,8 +5,8 @@ import { useField } from 'formik';
5
5
  import { ExtensionSlot, useConfig } from '@openmrs/esm-framework';
6
6
  import { Input } from '../../input/basic-input/input/input.component';
7
7
  import { PatientRegistrationContext } from '../../patient-registration-context';
8
- import styles from '../field.scss';
9
8
  import { type RegistrationConfig } from '../../../config-schema';
9
+ import styles from '../field.scss';
10
10
 
11
11
  export const unidentifiedPatientAttributeTypeUuid = '8b56eac7-5c76-4b9c-8c6f-1deab8d3fc47';
12
12
  const containsNoNumbers = /^([^0-9]*)$/;
@@ -1,16 +1,15 @@
1
- import React, { useCallback, useContext, useMemo } from 'react';
1
+ import React, { useContext, useMemo } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import { Field } from 'formik';
4
4
  import { useTranslation } from 'react-i18next';
5
5
  import { InlineNotification, Layer, Select, SelectItem } from '@carbon/react';
6
- import { OpenmrsDatePicker, parseDate, useConfig } from '@openmrs/esm-framework';
6
+ import { OpenmrsDatePicker, useConfig } from '@openmrs/esm-framework';
7
7
  import { type ConceptResponse } from '../../patient-registration.types';
8
8
  import { type FieldDefinition, type RegistrationConfig } from '../../../config-schema';
9
9
  import { Input } from '../../input/basic-input/input/input.component';
10
10
  import { useConcept, useConceptAnswers } from '../field.resource';
11
- import styles from './../field.scss';
12
11
  import { PatientRegistrationContext } from '../../patient-registration-context';
13
- import { type CalendarDate, getLocalTimeZone } from '@internationalized/date';
12
+ import styles from './../field.scss';
14
13
 
15
14
  export interface ObsFieldProps {
16
15
  fieldDefinition: FieldDefinition;
@@ -19,7 +18,6 @@ export interface ObsFieldProps {
19
18
  export function ObsField({ fieldDefinition }: ObsFieldProps) {
20
19
  const { t } = useTranslation();
21
20
  const { data: concept, isLoading } = useConcept(fieldDefinition.uuid);
22
-
23
21
  const config = useConfig<RegistrationConfig>();
24
22
 
25
23
  if (!config.registrationObs.encounterTypeUuid) {
@@ -170,9 +168,8 @@ function DateObsField({ concept, label, required, placeholder }: DateObsFieldPro
170
168
  const fieldName = `obs.${concept.uuid}`;
171
169
  const { setFieldValue } = useContext(PatientRegistrationContext);
172
170
 
173
- const onDateChange = ([date]) => {
174
- const refinedDate = date instanceof Date ? new Date(date.setHours(0, 0, 0, 0)) : new Date(date);
175
- setFieldValue(fieldName, refinedDate);
171
+ const onDateChange = (date: Date) => {
172
+ setFieldValue(fieldName, date);
176
173
  };
177
174
 
178
175
  return (
@@ -186,14 +183,12 @@ function DateObsField({ concept, label, required, placeholder }: DateObsFieldPro
186
183
  id={fieldName}
187
184
  {...field}
188
185
  isRequired={required}
189
- onChange={(date) => onDateChange([date])}
186
+ onChange={onDateChange}
190
187
  labelText={label ?? concept.display}
191
188
  isInvalid={errors[fieldName] && touched[fieldName]}
189
+ invalidText={t(meta.error)}
192
190
  value={field.value}
193
191
  />
194
- {errors[fieldName] && touched[fieldName] && (
195
- <div className={styles.radioFieldError}>{meta.error && t(meta.error)}</div>
196
- )}
197
192
  </>
198
193
  );
199
194
  }}
@@ -1,39 +1,36 @@
1
1
  import React from 'react';
2
- import { render, screen } from '@testing-library/react';
2
+ import dayjs from 'dayjs';
3
3
  import userEvent from '@testing-library/user-event';
4
- import { useConfig } from '@openmrs/esm-framework';
5
- import { type FieldDefinition } from '../../../config-schema';
4
+ import { render, screen } from '@testing-library/react';
5
+ import { getDefaultsFromConfigSchema, OpenmrsDatePicker, useConfig } from '@openmrs/esm-framework';
6
+ import { esmPatientRegistrationSchema, type FieldDefinition, type RegistrationConfig } from '../../../config-schema';
6
7
  import { useConcept, useConceptAnswers } from '../field.resource';
7
8
  import { ObsField } from './obs-field.component';
8
- import { PatientRegistrationContext } from '../../patient-registration-context';
9
- import dayjs from 'dayjs';
9
+ import { PatientRegistrationContext, type PatientRegistrationContextProps } from '../../patient-registration-context';
10
+ import { mockOpenmrsId, mockPatient } from '__mocks__';
10
11
 
11
- const mockUseConfig = useConfig as jest.Mock;
12
+ const mockOpenmrsDatePicker = jest.mocked(OpenmrsDatePicker);
13
+ const mockUseConcept = jest.mocked(useConcept);
14
+ const mockUseConceptAnswers = jest.mocked(useConceptAnswers);
15
+ const mockUseConfig = jest.mocked(useConfig<RegistrationConfig>);
12
16
 
13
- jest.mock('../field.resource'); // Mock the useConceptAnswers hook
17
+ jest.mock('../field.resource');
14
18
 
15
- jest.mock('@openmrs/esm-framework', () => {
16
- const originalModule = jest.requireActual('@openmrs/esm-framework');
17
- return {
18
- ...originalModule,
19
- OpenmrsDatePicker: jest.fn().mockImplementation(({ id, labelText, value, onChange }) => {
20
- return (
21
- <>
22
- <label htmlFor={id}>{labelText}</label>
23
- <input
24
- id={id}
25
- value={value ? dayjs(value).format('DD/MM/YYYY') : undefined}
26
- onChange={(evt) => onChange(dayjs(evt.target.value).toDate())}
27
- />
28
- </>
29
- );
30
- }),
31
- };
19
+ mockOpenmrsDatePicker.mockImplementation(({ id, labelText, value, onChange }) => {
20
+ return (
21
+ <>
22
+ <label htmlFor={id}>{labelText}</label>
23
+ <input
24
+ id={id}
25
+ // @ts-ignore
26
+ value={value ? dayjs(value).format('DD/MM/YYYY') : ''}
27
+ onChange={(evt) => {
28
+ onChange(dayjs(evt.target.value).toDate());
29
+ }}
30
+ />
31
+ </>
32
+ );
32
33
  });
33
-
34
- const mockedUseConcept = useConcept as jest.Mock;
35
- const mockedUseConceptAnswers = useConceptAnswers as jest.Mock;
36
-
37
34
  const useConceptMockImpl = (uuid: string) => {
38
35
  let data;
39
36
  if (uuid == 'weight-uuid') {
@@ -122,7 +119,7 @@ jest.mock('formik', () => ({
122
119
  const textFieldDef: FieldDefinition = {
123
120
  id: 'chief-complaint',
124
121
  type: 'obs',
125
- label: '',
122
+ label: 'Chief complaint',
126
123
  placeholder: '',
127
124
  showHeading: false,
128
125
  uuid: 'chief-complaint-uuid',
@@ -137,7 +134,7 @@ const textFieldDef: FieldDefinition = {
137
134
  const numberFieldDef: FieldDefinition = {
138
135
  id: 'weight',
139
136
  type: 'obs',
140
- label: '',
137
+ label: 'Weight',
141
138
  placeholder: '',
142
139
  showHeading: false,
143
140
  uuid: 'weight-uuid',
@@ -152,7 +149,7 @@ const numberFieldDef: FieldDefinition = {
152
149
  const dateFieldDef: FieldDefinition = {
153
150
  id: 'vac_date',
154
151
  type: 'obs',
155
- label: '',
152
+ label: 'Vaccination date',
156
153
  placeholder: '',
157
154
  showHeading: false,
158
155
  uuid: 'vaccination-date-uuid',
@@ -167,7 +164,7 @@ const dateFieldDef: FieldDefinition = {
167
164
  const codedFieldDef: FieldDefinition = {
168
165
  id: 'nationality',
169
166
  type: 'obs',
170
- label: '',
167
+ label: 'Nationality',
171
168
  placeholder: '',
172
169
  showHeading: false,
173
170
  uuid: 'nationality-uuid',
@@ -179,41 +176,82 @@ const codedFieldDef: FieldDefinition = {
179
176
  customConceptAnswers: [],
180
177
  };
181
178
 
179
+ const mockInitialFormValues = {
180
+ additionalFamilyName: '',
181
+ additionalGivenName: '',
182
+ additionalMiddleName: '',
183
+ addNameInLocalLanguage: false,
184
+ address: {},
185
+ birthdate: null,
186
+ birthdateEstimated: false,
187
+ deathCause: '',
188
+ deathDate: '',
189
+ familyName: 'Doe',
190
+ gender: 'male',
191
+ givenName: 'John',
192
+ identifiers: mockOpenmrsId,
193
+ isDead: false,
194
+ middleName: 'Test',
195
+ monthsEstimated: 0,
196
+ patientUuid: mockPatient.uuid,
197
+ relationships: [],
198
+ telephoneNumber: '',
199
+ yearsEstimated: 0,
200
+ };
201
+
202
+ const initialContextValues: PatientRegistrationContextProps = {
203
+ currentPhoto: null,
204
+ inEditMode: false,
205
+ identifierTypes: [],
206
+ initialFormValues: mockInitialFormValues,
207
+ isOffline: false,
208
+ setCapturePhotoProps: jest.fn(),
209
+ setFieldValue: jest.fn(),
210
+ setInitialFormValues: jest.fn(),
211
+ validationSchema: null,
212
+ values: mockInitialFormValues,
213
+ };
214
+
182
215
  describe('ObsField', () => {
183
216
  beforeEach(() => {
184
- mockUseConfig.mockReturnValue({ registrationObs: { encounterTypeUuid: 'reg-enc-uuid' } });
185
- mockedUseConcept.mockImplementation(useConceptMockImpl);
186
- mockedUseConceptAnswers.mockImplementation(useConceptAnswersMockImpl);
217
+ mockUseConfig.mockReturnValue({
218
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
219
+ registrationObs: { encounterTypeUuid: 'reg-enc-uuid' },
220
+ } as RegistrationConfig);
221
+ mockUseConcept.mockImplementation(useConceptMockImpl);
222
+ mockUseConceptAnswers.mockImplementation(useConceptAnswersMockImpl);
187
223
  });
188
224
 
189
225
  it("logs an error and doesn't render if no registration encounter type is provided", () => {
190
- mockUseConfig.mockReturnValue({ registrationObs: { encounterTypeUuid: null } });
226
+ mockUseConfig.mockReturnValue({
227
+ ...getDefaultsFromConfigSchema(esmPatientRegistrationSchema),
228
+ registrationObs: { encounterTypeUuid: null },
229
+ } as RegistrationConfig);
230
+
191
231
  console.error = jest.fn();
192
232
  render(<ObsField fieldDefinition={textFieldDef} />);
193
233
  expect(console.error).toHaveBeenCalledWith(
194
234
  expect.stringMatching(/no registration encounter type has been configured/i),
195
235
  );
196
- expect(screen.queryByRole('textbox')).toBeNull();
236
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
197
237
  });
198
238
 
199
239
  it('renders a text box for text concept', () => {
200
240
  render(<ObsField fieldDefinition={textFieldDef} />);
201
- // I don't know why the labels aren't in the DOM, but they aren't
202
- // expect(screen.getByLabelText("Chief Complaint")).toBeInTheDocument();
203
- expect(screen.getByRole('textbox')).toBeInTheDocument();
241
+
242
+ expect(screen.getByRole('textbox', { name: 'Chief complaint (optional)' })).toBeInTheDocument();
204
243
  });
205
244
 
206
245
  it('renders a number box for number concept', () => {
207
246
  render(<ObsField fieldDefinition={numberFieldDef} />);
208
- // expect(screen.getByLabelText("Weight (kg)")).toBeInTheDocument();
209
- expect(screen.getByRole('spinbutton')).toBeInTheDocument();
247
+
248
+ expect(screen.getByRole('spinbutton', { name: 'Weight (optional)' })).toBeInTheDocument();
210
249
  });
211
250
 
212
- // TODO O3-3482: Fix this test case.
213
- // Disabling this test case for now as it doesn't work as expected when mocking the date picker
214
- it.skip('renders a datepicker for date concept', async () => {
251
+ // TODO: Fix this test
252
+ xit('renders a datepicker for date concept', async () => {
215
253
  render(
216
- <PatientRegistrationContext.Provider value={{ setFieldValue: jest.fn() }}>
254
+ <PatientRegistrationContext.Provider value={initialContextValues}>
217
255
  <ObsField fieldDefinition={dateFieldDef} />
218
256
  </PatientRegistrationContext.Provider>,
219
257
  );
@@ -227,25 +265,23 @@ describe('ObsField', () => {
227
265
 
228
266
  it('renders a select for a coded concept', () => {
229
267
  render(<ObsField fieldDefinition={codedFieldDef} />);
230
- // expect(screen.getByLabelText("Nationality")).toBeInTheDocument();
231
- const select = screen.getByRole('combobox');
232
- expect(select).toBeInTheDocument();
233
- expect(select).toHaveDisplayValue('Select an option');
268
+
269
+ expect(screen.getByRole('combobox', { name: 'Nationality' })).toBeInTheDocument();
270
+ expect(screen.getByRole('option', { name: 'USA' })).toBeInTheDocument();
271
+ expect(screen.getByRole('option', { name: 'Mexico' })).toBeInTheDocument();
234
272
  });
235
273
 
236
274
  it('select uses answerConcept for answers when it is provided', async () => {
237
- const user = userEvent.setup();
238
-
239
275
  render(<ObsField fieldDefinition={{ ...codedFieldDef, answerConceptSetUuid: 'other-countries-uuid' }} />);
240
- // expect(screen.getByLabelText("Nationality")).toBeInTheDocument();
241
- const select = screen.getByRole('combobox');
242
- expect(select).toBeInTheDocument();
243
- await user.selectOptions(select, 'Kenya');
276
+
277
+ expect(screen.getByRole('combobox', { name: 'Nationality' })).toBeInTheDocument();
278
+ expect(screen.getByRole('option', { name: 'Kenya' })).toBeInTheDocument();
279
+ expect(screen.getByRole('option', { name: 'Uganda' })).toBeInTheDocument();
280
+ expect(screen.queryByRole('option', { name: 'USA' })).not.toBeInTheDocument();
281
+ expect(screen.queryByRole('option', { name: 'Mexico' })).not.toBeInTheDocument();
244
282
  });
245
283
 
246
284
  it('select uses customConceptAnswers for answers when provided', async () => {
247
- const user = userEvent.setup();
248
-
249
285
  render(
250
286
  <ObsField
251
287
  fieldDefinition={{
@@ -259,9 +295,9 @@ describe('ObsField', () => {
259
295
  }}
260
296
  />,
261
297
  );
262
- // expect(screen.getByLabelText("Nationality")).toBeInTheDocument();
263
- const select = screen.getByRole('combobox');
264
- expect(select).toBeInTheDocument();
265
- await user.selectOptions(select, 'Mozambique');
298
+
299
+ expect(screen.getByRole('combobox', { name: 'Nationality' })).toBeInTheDocument();
300
+ expect(screen.getByRole('option', { name: 'Mozambique' })).toBeInTheDocument();
301
+ expect(screen.queryByRole('option', { name: 'Uganda' })).not.toBeInTheDocument();
266
302
  });
267
303
  });
@@ -1,16 +1,16 @@
1
1
  import React from 'react';
2
+ import { Form, Formik } from 'formik';
2
3
  import { render, screen } from '@testing-library/react';
3
4
  import { useConceptAnswers } from '../field.resource';
4
5
  import { CodedPersonAttributeField } from './coded-person-attribute-field.component';
5
- import { Form, Formik } from 'formik';
6
6
 
7
7
  jest.mock('formik', () => ({
8
8
  ...jest.requireActual('formik'),
9
9
  }));
10
10
 
11
- jest.mock('../field.resource'); // Mock the useConceptAnswers hook
11
+ jest.mock('../field.resource');
12
12
 
13
- const mockedUseConceptAnswers = useConceptAnswers as jest.Mock;
13
+ const mockUseConceptAnswers = jest.mocked(useConceptAnswers);
14
14
 
15
15
  describe('CodedPersonAttributeField', () => {
16
16
  const conceptAnswers = [
@@ -27,8 +27,7 @@ describe('CodedPersonAttributeField', () => {
27
27
  const answerConceptSetUuid = '6682d17f-0777-45e4-a39b-93f77eb3531c';
28
28
 
29
29
  beforeEach(() => {
30
- jest.clearAllMocks();
31
- mockedUseConceptAnswers.mockReturnValue({
30
+ mockUseConceptAnswers.mockReturnValue({
32
31
  data: conceptAnswers,
33
32
  isLoading: false,
34
33
  });
@@ -45,6 +44,7 @@ describe('CodedPersonAttributeField', () => {
45
44
  answerConceptSetUuid={null}
46
45
  label={personAttributeType.display}
47
46
  customConceptAnswers={[]}
47
+ required={false}
48
48
  />
49
49
  </Form>
50
50
  </Formik>,
@@ -53,7 +53,7 @@ describe('CodedPersonAttributeField', () => {
53
53
  });
54
54
 
55
55
  it('shows error if the concept answer set does not have any concept answers', () => {
56
- mockedUseConceptAnswers.mockReturnValue({
56
+ mockUseConceptAnswers.mockReturnValue({
57
57
  data: [],
58
58
  isLoading: false,
59
59
  });
@@ -67,6 +67,7 @@ describe('CodedPersonAttributeField', () => {
67
67
  answerConceptSetUuid={answerConceptSetUuid}
68
68
  label={personAttributeType.display}
69
69
  customConceptAnswers={[]}
70
+ required={false}
70
71
  />
71
72
  </Form>
72
73
  </Formik>,
@@ -84,6 +85,7 @@ describe('CodedPersonAttributeField', () => {
84
85
  answerConceptSetUuid={answerConceptSetUuid}
85
86
  label={personAttributeType.display}
86
87
  customConceptAnswers={[]}
88
+ required={false}
87
89
  />
88
90
  </Form>
89
91
  </Formik>,
@@ -113,6 +115,7 @@ describe('CodedPersonAttributeField', () => {
113
115
  label: 'Special Option B',
114
116
  },
115
117
  ]}
118
+ required={false}
116
119
  />
117
120
  </Form>
118
121
  </Formik>,