@ampath/esm-patient-registration-app 6.0.1-pre.6 → 6.0.1-pre.66

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 (161) hide show
  1. package/.turbo/turbo-build.log +23 -24
  2. package/dist/132.js +1 -0
  3. package/dist/197.js +1 -0
  4. package/dist/236.js +1 -0
  5. package/dist/{735.js.map → 236.js.map} +1 -1
  6. package/dist/300.js +1 -0
  7. package/dist/335.js +1 -0
  8. package/dist/372.js +1 -0
  9. package/dist/372.js.map +1 -0
  10. package/dist/41.js +2 -0
  11. package/dist/41.js.map +1 -0
  12. package/dist/449.js +1 -0
  13. package/dist/449.js.map +1 -0
  14. package/dist/464.js +1 -0
  15. package/dist/464.js.map +1 -0
  16. package/dist/495.js +1 -0
  17. package/dist/495.js.map +1 -0
  18. package/dist/55.js +1 -0
  19. package/dist/56.js +1 -0
  20. package/dist/56.js.map +1 -0
  21. package/dist/621.js +1 -1
  22. package/dist/621.js.map +1 -1
  23. package/dist/629.js +2 -0
  24. package/dist/629.js.LICENSE.txt +24 -0
  25. package/dist/629.js.map +1 -0
  26. package/dist/652.js +1 -0
  27. package/dist/661.js +1 -0
  28. package/dist/757.js +1 -1
  29. package/dist/757.js.map +1 -0
  30. package/dist/828.js +1 -0
  31. package/dist/828.js.map +1 -0
  32. package/dist/830.js +1 -0
  33. package/dist/830.js.map +1 -0
  34. package/dist/831.js +2 -0
  35. package/dist/831.js.map +1 -0
  36. package/dist/876.js +2 -0
  37. package/dist/876.js.map +1 -0
  38. package/dist/879.js +1 -1
  39. package/dist/913.js +2 -0
  40. package/dist/{591.js.LICENSE.txt → 913.js.LICENSE.txt} +23 -3
  41. package/dist/913.js.map +1 -0
  42. package/dist/927.js +1 -0
  43. package/dist/927.js.map +1 -0
  44. package/dist/99.js +1 -0
  45. package/dist/ampath-esm-patient-registration-app.js +1 -1
  46. package/dist/ampath-esm-patient-registration-app.js.buildmanifest.json +236 -191
  47. package/dist/ampath-esm-patient-registration-app.js.map +1 -1
  48. package/dist/main.js +1 -1
  49. package/dist/main.js.LICENSE.txt +0 -32
  50. package/dist/main.js.map +1 -1
  51. package/dist/routes.json +1 -1
  52. package/package.json +6 -9
  53. package/src/config-schema.ts +19 -10
  54. package/src/constants.ts +1 -1
  55. package/src/index.ts +11 -4
  56. package/src/offline.resources.ts +13 -18
  57. package/src/offline.ts +6 -4
  58. package/src/patient-photo.extension.tsx +9 -0
  59. package/src/patient-registration/field/address/custom-address-field.component.tsx +1 -0
  60. package/src/patient-registration/field/custom-field.component.tsx +6 -0
  61. package/src/patient-registration/field/dob/dob.component.tsx +17 -14
  62. package/src/patient-registration/field/field.resource.ts +3 -3
  63. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +4 -0
  64. package/src/patient-registration/field/person-attributes/custom-person-attribute-field.component.tsx +56 -0
  65. package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +22 -7
  66. package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +2 -2
  67. package/src/patient-registration/field/phone/phone-field.component.tsx +1 -0
  68. package/src/patient-registration/form-manager.ts +13 -6
  69. package/src/patient-registration/patient-registration-hooks.ts +91 -9
  70. package/src/patient-registration/patient-registration.component.tsx +55 -13
  71. package/src/patient-registration/{patient-registration.resource.test.tsx → patient-registration.resource.testt.tsx} +3 -3
  72. package/src/patient-registration/patient-registration.resource.ts +14 -74
  73. package/src/patient-registration/patient-registration.scss +0 -8
  74. package/src/patient-registration/patient-registration.types.ts +7 -1
  75. package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +5 -1
  76. package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +2 -2
  77. package/src/patient-verification/assets/counties.json +236 -0
  78. package/src/patient-verification/assets/verification-assets.ts +11 -0
  79. package/src/patient-verification/patient-verification-hook.tsx +176 -0
  80. package/src/patient-verification/patient-verification-utils.ts +179 -0
  81. package/src/patient-verification/patient-verification.component.tsx +124 -0
  82. package/src/patient-verification/patient-verification.scss +25 -0
  83. package/src/patient-verification/verification-modal/confirm-prompt.component.tsx +72 -0
  84. package/src/patient-verification/verification-modal/empty-prompt.component.tsx +35 -0
  85. package/src/patient-verification/verification-types.ts +50 -0
  86. package/src/routes.json +12 -3
  87. package/translations/am.json +26 -12
  88. package/translations/ar.json +26 -12
  89. package/translations/en.json +19 -5
  90. package/translations/es.json +10 -0
  91. package/translations/fr.json +6 -0
  92. package/translations/he.json +18 -0
  93. package/translations/km.json +18 -0
  94. package/translations/zh.json +30 -22
  95. package/translations/zh_CN.json +30 -22
  96. package/dist/130.js +0 -2
  97. package/dist/130.js.map +0 -1
  98. package/dist/152.js +0 -1
  99. package/dist/152.js.map +0 -1
  100. package/dist/249.js +0 -2
  101. package/dist/249.js.LICENSE.txt +0 -46
  102. package/dist/249.js.map +0 -1
  103. package/dist/255.js +0 -2
  104. package/dist/255.js.map +0 -1
  105. package/dist/271.js +0 -1
  106. package/dist/303.js +0 -1
  107. package/dist/303.js.map +0 -1
  108. package/dist/319.js +0 -1
  109. package/dist/365.js +0 -1
  110. package/dist/365.js.map +0 -1
  111. package/dist/460.js +0 -1
  112. package/dist/525.js +0 -1
  113. package/dist/525.js.map +0 -1
  114. package/dist/537.js +0 -1
  115. package/dist/537.js.map +0 -1
  116. package/dist/574.js +0 -1
  117. package/dist/591.js +0 -2
  118. package/dist/591.js.map +0 -1
  119. package/dist/644.js +0 -1
  120. package/dist/729.js +0 -1
  121. package/dist/729.js.map +0 -1
  122. package/dist/735.js +0 -1
  123. package/dist/784.js +0 -2
  124. package/dist/784.js.map +0 -1
  125. package/dist/788.js +0 -1
  126. package/dist/807.js +0 -1
  127. package/dist/833.js +0 -1
  128. package/dist/879.js.map +0 -1
  129. package/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +0 -214
  130. package/src/patient-registration/field/address/tests/address-search-component.test.tsx +0 -135
  131. package/src/patient-registration/field/dob/dob.test.tsx +0 -75
  132. package/src/patient-registration/field/field.test.tsx +0 -294
  133. package/src/patient-registration/field/id/id-field.test.tsx +0 -107
  134. package/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +0 -60
  135. package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +0 -127
  136. package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +0 -187
  137. package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +0 -88
  138. package/src/patient-registration/form-manager.test.ts +0 -67
  139. package/src/patient-registration/input/basic-input/select/select-input.test.tsx +0 -49
  140. package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +0 -132
  141. package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +0 -107
  142. package/src/patient-registration/patient-registration.test.tsx +0 -471
  143. package/src/patient-registration/section/death-info/death-info-section.test.tsx +0 -64
  144. package/src/patient-registration/section/demographics/demographics-section.test.tsx +0 -83
  145. package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +0 -100
  146. package/src/patient-verification/client-registry-constants.ts +0 -13
  147. package/src/patient-verification/client-registry.component.tsx +0 -66
  148. package/src/patient-verification/client-registry.scss +0 -1
  149. package/src/patient-verification/utils.tsx +0 -56
  150. package/src/patient-verification/verification-modal.scss +0 -20
  151. package/src/patient-verification/verification.component.tsx +0 -48
  152. package/src/root.test.tsx +0 -32
  153. package/src/widgets/cancel-patient-edit.test.tsx +0 -27
  154. package/src/widgets/display-photo.component.tsx +0 -30
  155. package/src/widgets/display-photo.test.tsx +0 -37
  156. package/src/widgets/edit-patient-details-button.test.tsx +0 -41
  157. /package/dist/{784.js.LICENSE.txt → 41.js.LICENSE.txt} +0 -0
  158. /package/dist/{130.js.LICENSE.txt → 831.js.LICENSE.txt} +0 -0
  159. /package/dist/{255.js.LICENSE.txt → 876.js.LICENSE.txt} +0 -0
  160. /package/src/patient-registration/input/custom-input/identifier/{utils.test.ts → utils.testt.ts} +0 -0
  161. /package/src/widgets/{delete-identifier-confirmation-modal.test.tsx → delete-identifier-confirmation-modal.testt.tsx} +0 -0
@@ -1,187 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { usePersonAttributeType } from './person-attributes.resource';
4
- import { PersonAttributeField } from './person-attribute-field.component';
5
- import { useConceptAnswers } from '../field.resource';
6
- import { Form, Formik } from 'formik';
7
- import { type FieldDefinition } from '../../../config-schema';
8
-
9
- jest.mock('./person-attributes.resource'); // Mock the usePersonAttributeType hook
10
- jest.mock('../field.resource'); // Mock the useConceptAnswers hook
11
-
12
- jest.mock('formik', () => ({
13
- ...jest.requireActual('formik'),
14
- }));
15
-
16
- const mockedUsePersonAttributeType = usePersonAttributeType as jest.Mock;
17
- const mockedUseConceptAnswers = useConceptAnswers as jest.Mock;
18
-
19
- let fieldDefinition: FieldDefinition;
20
-
21
- describe('PersonAttributeField', () => {
22
- let mockPersonAttributeType = {
23
- format: 'java.lang.String',
24
- display: 'Referred by',
25
- uuid: '4dd56a75-14ab-4148-8700-1f4f704dc5b0',
26
- };
27
-
28
- beforeEach(() => {
29
- fieldDefinition = {
30
- id: 'referredby',
31
- name: 'Referred by',
32
- type: 'person attribute',
33
- uuid: '4dd56a75-14ab-4148-8700-1f4f704dc5b0',
34
- answerConceptSetUuid: '6682d17f-0777-45e4-a39b-93f77eb3531c',
35
- validation: {
36
- matches: '',
37
- required: true,
38
- },
39
- showHeading: true,
40
- };
41
- mockedUsePersonAttributeType.mockReturnValue({
42
- data: mockPersonAttributeType,
43
- isLoading: false,
44
- error: null,
45
- uuid: '14d4f066-15f5-102d-96e4-000c29c2a5d7d',
46
- });
47
- });
48
-
49
- afterEach(() => {
50
- jest.resetAllMocks();
51
- });
52
-
53
- it('renders the text input field for String format', () => {
54
- render(
55
- <Formik initialValues={{}} onSubmit={() => {}}>
56
- <Form>
57
- <PersonAttributeField fieldDefinition={fieldDefinition} />
58
- </Form>
59
- </Formik>,
60
- );
61
-
62
- const input = screen.getByLabelText(/Referred by/i) as HTMLInputElement;
63
- expect(screen.getByRole('heading')).toBeInTheDocument();
64
- expect(input).toBeInTheDocument();
65
- expect(input.type).toBe('text');
66
- });
67
-
68
- it('should not show heading if showHeading is false', () => {
69
- fieldDefinition = {
70
- ...fieldDefinition,
71
- showHeading: false,
72
- };
73
-
74
- render(
75
- <Formik initialValues={{}} onSubmit={() => {}}>
76
- <Form>
77
- <PersonAttributeField fieldDefinition={fieldDefinition} />
78
- </Form>
79
- </Formik>,
80
- );
81
- expect(screen.queryByRole('heading')).not.toBeInTheDocument();
82
- });
83
-
84
- it('renders the coded attribute field for Concept format', () => {
85
- mockedUsePersonAttributeType.mockReturnValue({
86
- data: { ...mockPersonAttributeType, format: 'org.openmrs.Concept' },
87
- isLoading: false,
88
- error: null,
89
- });
90
-
91
- fieldDefinition = {
92
- id: 'referredby',
93
- ...fieldDefinition,
94
- label: 'Referred by',
95
- };
96
-
97
- mockedUseConceptAnswers.mockReturnValueOnce({
98
- data: [
99
- { uuid: '1', display: 'Option 1' },
100
- { uuid: '2', display: 'Option 2' },
101
- ],
102
- isLoading: false,
103
- });
104
-
105
- render(
106
- <Formik initialValues={{}} onSubmit={() => {}}>
107
- <Form>
108
- <PersonAttributeField fieldDefinition={fieldDefinition} />
109
- </Form>
110
- </Formik>,
111
- );
112
-
113
- const input = screen.getByLabelText(/Referred by/i) as HTMLInputElement;
114
- expect(input).toBeInTheDocument();
115
- expect(input.type).toBe('select-one');
116
- expect(screen.getByText('Option 1')).toBeInTheDocument();
117
- expect(screen.getByText('Option 2')).toBeInTheDocument();
118
- });
119
-
120
- it('renders an error notification if attribute type has unknown format', () => {
121
- mockedUsePersonAttributeType.mockReturnValue({
122
- data: { ...mockPersonAttributeType, format: 'unknown' },
123
- isLoading: false,
124
- error: null,
125
- });
126
-
127
- render(
128
- <Formik initialValues={{}} onSubmit={() => {}}>
129
- <Form>
130
- <PersonAttributeField fieldDefinition={fieldDefinition} />
131
- </Form>
132
- </Formik>,
133
- );
134
-
135
- expect(screen.getByText('Error')).toBeInTheDocument();
136
- expect(screen.getByText(/Patient attribute type has unknown format/i)).toBeInTheDocument();
137
- });
138
- it('renders an error notification if unable to fetch attribute type', () => {
139
- mockedUsePersonAttributeType.mockReturnValue({
140
- data: null,
141
- isLoading: false,
142
- error: new Error('Failed to fetch attribute type'),
143
- });
144
-
145
- fieldDefinition = {
146
- uuid: 'attribute-uuid',
147
- label: 'Attribute',
148
- showHeading: false,
149
- };
150
-
151
- render(
152
- <Formik initialValues={{}} onSubmit={() => {}}>
153
- <Form>
154
- <PersonAttributeField fieldDefinition={fieldDefinition} />
155
- </Form>
156
- </Formik>,
157
- );
158
-
159
- expect(screen.getByText('Error')).toBeInTheDocument();
160
- expect(screen.getByText(/Unable to fetch person attribute type/i)).toBeInTheDocument();
161
- });
162
-
163
- it('renders a skeleton if attribute type is loading', () => {
164
- mockedUsePersonAttributeType.mockReturnValue({
165
- data: null,
166
- isLoading: true,
167
- error: null,
168
- });
169
-
170
- fieldDefinition = {
171
- uuid: 'attribute-uuid',
172
- label: 'Attribute',
173
- showHeading: true,
174
- };
175
-
176
- render(
177
- <Formik initialValues={{}} onSubmit={() => {}}>
178
- <Form>
179
- <PersonAttributeField fieldDefinition={fieldDefinition} />
180
- </Form>
181
- </Formik>,
182
- );
183
- const input = screen.findByLabelText(/Reffered by/i);
184
- expect(screen.getByText(/Attribute/i)).toBeInTheDocument();
185
- expect(input).not.toBeNull(); // checks that the input is not rendered when the attribute type is loading
186
- });
187
- });
@@ -1,88 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { Form, Formik } from 'formik';
5
- import { TextPersonAttributeField } from './text-person-attribute-field.component';
6
-
7
- describe('TextPersonAttributeField', () => {
8
- const mockPersonAttributeType = {
9
- format: 'java.lang.String',
10
- display: 'Referred by',
11
- uuid: '4dd56a75-14ab-4148-8700-1f4f704dc5b0',
12
- };
13
-
14
- it('renders the input field with a label', () => {
15
- render(
16
- <Formik initialValues={{}} onSubmit={() => {}}>
17
- <Form>
18
- <TextPersonAttributeField
19
- id="attributeId"
20
- personAttributeType={mockPersonAttributeType}
21
- label="Custom Label"
22
- />
23
- </Form>
24
- </Formik>,
25
- );
26
-
27
- expect(screen.getByRole('textbox', { name: /custom label \(optional\)/i })).toBeInTheDocument();
28
- });
29
-
30
- it('renders the input field with the default label if label prop is not provided', () => {
31
- render(
32
- <Formik initialValues={{}} onSubmit={() => {}}>
33
- <Form>
34
- <TextPersonAttributeField id="attributeId" personAttributeType={mockPersonAttributeType} />
35
- </Form>
36
- </Formik>,
37
- );
38
-
39
- expect(screen.getByRole('textbox', { name: /referred by \(optional\)/i })).toBeInTheDocument();
40
- });
41
-
42
- it('validates the input with the provided validationRegex', async () => {
43
- const user = userEvent.setup();
44
- const validationRegex = '^[A-Z]+$'; // Accepts only uppercase letters
45
-
46
- render(
47
- <Formik initialValues={{}} onSubmit={() => {}}>
48
- <Form>
49
- <TextPersonAttributeField
50
- id="attributeId"
51
- personAttributeType={mockPersonAttributeType}
52
- validationRegex={validationRegex}
53
- />
54
- </Form>
55
- </Formik>,
56
- );
57
-
58
- const textbox = screen.getByRole('textbox', { name: /referred by \(optional\)/i });
59
- expect(textbox).toBeInTheDocument();
60
-
61
- // Valid input: "ABC"
62
- await user.type(textbox, 'ABC');
63
- await user.tab();
64
-
65
- expect(screen.queryByText(/invalid input/i)).not.toBeInTheDocument();
66
- await user.clear(textbox);
67
-
68
- // // Invalid input: "abc" (contains lowercase letters)
69
- await user.type(textbox, 'abc');
70
- await user.tab();
71
- expect(screen.getByText(/invalid input/i)).toBeInTheDocument();
72
- });
73
-
74
- it('renders the input field as required when required prop is true', () => {
75
- render(
76
- <Formik initialValues={{}} onSubmit={() => {}}>
77
- <Form>
78
- <TextPersonAttributeField id="attributeId" personAttributeType={mockPersonAttributeType} required />
79
- </Form>
80
- </Formik>,
81
- );
82
- const textbox = screen.getByRole('textbox', { name: /referred by/i });
83
-
84
- // Required attribute should be truthy on the input element
85
- expect(textbox).toBeInTheDocument();
86
- expect(textbox).toBeRequired();
87
- });
88
- });
@@ -1,67 +0,0 @@
1
- import { FormManager } from './form-manager';
2
- import { type FormValues } from './patient-registration.types';
3
-
4
- jest.mock('./patient-registration.resource');
5
-
6
- const formValues: FormValues = {
7
- patientUuid: '',
8
- givenName: '',
9
- middleName: '',
10
- familyName: '',
11
- additionalGivenName: '',
12
- additionalMiddleName: '',
13
- additionalFamilyName: '',
14
- addNameInLocalLanguage: false,
15
- gender: '',
16
- birthdate: '',
17
- yearsEstimated: 1000,
18
- monthsEstimated: 11,
19
- birthdateEstimated: false,
20
- telephoneNumber: '',
21
- isDead: false,
22
- deathDate: 'string',
23
- deathCause: 'string',
24
- relationships: [],
25
- address: {
26
- address1: '',
27
- address2: '',
28
- cityVillage: '',
29
- stateProvince: 'New York',
30
- country: 'string',
31
- postalCode: 'string',
32
- },
33
- identifiers: {
34
- foo: {
35
- identifierUuid: 'aUuid',
36
- identifierName: 'Foo',
37
- required: false,
38
- initialValue: 'foo',
39
- identifierValue: 'foo',
40
- identifierTypeUuid: 'identifierType',
41
- preferred: true,
42
- autoGeneration: false,
43
- selectedSource: {
44
- uuid: 'some-uuid',
45
- name: 'unique',
46
- autoGenerationOption: { manualEntryEnabled: true, automaticGenerationEnabled: false },
47
- },
48
- },
49
- },
50
- };
51
-
52
- describe('FormManager', () => {
53
- describe('createIdentifiers', () => {
54
- it('uses the uuid of a field name if it exists', async () => {
55
- const result = await FormManager.savePatientIdentifiers(true, undefined, formValues.identifiers, {}, 'Nyc');
56
- expect(result).toEqual([
57
- {
58
- uuid: 'aUuid',
59
- identifier: 'foo',
60
- identifierType: 'identifierType',
61
- location: 'Nyc',
62
- preferred: true,
63
- },
64
- ]);
65
- });
66
- });
67
- });
@@ -1,49 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import userEvent from '@testing-library/user-event';
4
- import { Formik, Form } from 'formik';
5
- import { SelectInput } from './select-input.component';
6
-
7
- describe('the select input', () => {
8
- const setupSelect = async () => {
9
- render(
10
- <Formik initialValues={{ select: '' }} onSubmit={null}>
11
- <Form>
12
- <SelectInput label="Select" name="select" options={['A Option', 'B Option']} required />
13
- </Form>
14
- </Formik>,
15
- );
16
- return screen.getByLabelText('Select') as HTMLInputElement;
17
- };
18
-
19
- it('exists', async () => {
20
- const input = await setupSelect();
21
- expect(input.type).toEqual('select-one');
22
- });
23
-
24
- it('can input data', async () => {
25
- const user = userEvent.setup();
26
- const input = await setupSelect();
27
- const expected = 'A Option';
28
-
29
- await user.selectOptions(input, expected);
30
-
31
- await expect(input.value).toEqual(expected);
32
- });
33
-
34
- it('should show optional label if the input is not required', async () => {
35
- render(
36
- <Formik initialValues={{ select: '' }} onSubmit={null}>
37
- <Form>
38
- <SelectInput label="Select" name="select" options={['A Option', 'B Option']} />
39
- </Form>
40
- </Formik>,
41
- );
42
-
43
- await expect(screen.findByRole('combobox'));
44
-
45
- const selectInput = screen.getByRole('combobox', { name: 'Select (optional)' }) as HTMLSelectElement;
46
- expect(selectInput.labels).toHaveLength(1);
47
- expect(selectInput.labels[0]).toHaveTextContent('Select (optional)');
48
- });
49
- });
@@ -1,132 +0,0 @@
1
- import React from 'react';
2
- import { Autosuggest } from './autosuggest.component';
3
- import { BrowserRouter } from 'react-router-dom';
4
- import { render, screen } from '@testing-library/react';
5
- import userEvent from '@testing-library/user-event';
6
-
7
- const mockPersons = [
8
- {
9
- uuid: 'randomuuid1',
10
- display: 'John Doe',
11
- },
12
- {
13
- uuid: 'randomuuid2',
14
- display: 'John Smith',
15
- },
16
- {
17
- uuid: 'randomuuid3',
18
- display: 'James Smith',
19
- },
20
- {
21
- uuid: 'randomuuid4',
22
- display: 'Spider Man',
23
- },
24
- ];
25
-
26
- const mockedGetSearchResults = async (query: string) => {
27
- return mockPersons.filter((person) => {
28
- return person.display.toUpperCase().includes(query.toUpperCase());
29
- });
30
- };
31
-
32
- const mockedHandleSuggestionSelected = jest.fn((field, value) => [field, value]);
33
-
34
- describe('Autosuggest', () => {
35
- afterEach(() => mockedHandleSuggestionSelected.mockClear());
36
-
37
- it('renders a search box', () => {
38
- renderAutosuggest();
39
-
40
- expect(screen.getByRole('searchbox')).toBeInTheDocument();
41
- expect(screen.queryByRole('list')).toBeNull();
42
- });
43
-
44
- it('renders matching search results in a list when the user types a query', async () => {
45
- const user = userEvent.setup();
46
-
47
- renderAutosuggest();
48
-
49
- const searchbox = screen.getByRole('searchbox');
50
- await user.type(searchbox, 'john');
51
-
52
- const list = screen.getByRole('list');
53
-
54
- expect(list).toBeInTheDocument();
55
- expect(list.children).toHaveLength(2);
56
- expect(screen.getAllByRole('listitem')[0]).toHaveTextContent('John Doe');
57
- expect(screen.getAllByRole('listitem')[1]).toHaveTextContent('John Smith');
58
- });
59
-
60
- it('clears the list of suggestions when a suggestion is selected', async () => {
61
- const user = userEvent.setup();
62
-
63
- renderAutosuggest();
64
-
65
- let list = screen.queryByRole('list');
66
- expect(list).toBeNull();
67
-
68
- const searchbox = screen.getByRole('searchbox');
69
- await user.type(searchbox, 'john');
70
-
71
- list = screen.getByRole('list');
72
- expect(list).toBeInTheDocument();
73
-
74
- const listitems = screen.getAllByRole('listitem');
75
- await user.click(listitems[0]);
76
-
77
- expect(mockedHandleSuggestionSelected).toHaveBeenLastCalledWith('person', 'randomuuid1');
78
-
79
- list = screen.queryByRole('list');
80
- expect(list).toBeNull();
81
- });
82
-
83
- it('changes suggestions when a search input is changed', async () => {
84
- const user = userEvent.setup();
85
-
86
- renderAutosuggest();
87
-
88
- let list = screen.queryByRole('list');
89
- expect(list).toBeNull();
90
-
91
- const searchbox = screen.getByRole('searchbox');
92
- await user.type(searchbox, 'john');
93
-
94
- const suggestion = await screen.findByText('John Doe');
95
- expect(suggestion).toBeInTheDocument();
96
-
97
- await user.clear(searchbox);
98
-
99
- list = screen.queryByRole('list');
100
- expect(list).toBeNull();
101
- });
102
-
103
- it('hides the list of suggestions when the user clicks outside of the component', async () => {
104
- const user = userEvent.setup();
105
-
106
- renderAutosuggest();
107
-
108
- const input = screen.getByRole('searchbox');
109
-
110
- await user.type(input, 'john');
111
- await screen.findByText('John Doe');
112
- await user.click(document.body);
113
-
114
- expect(screen.queryByText('John Doe')).not.toBeInTheDocument();
115
- });
116
- });
117
-
118
- function renderAutosuggest() {
119
- render(
120
- <BrowserRouter>
121
- <Autosuggest
122
- getSearchResults={mockedGetSearchResults}
123
- getDisplayValue={(item) => item.display}
124
- getFieldValue={(item) => item.uuid}
125
- id="person"
126
- labelText=""
127
- onSuggestionSelected={mockedHandleSuggestionSelected}
128
- placeholder="Find Person"
129
- />
130
- </BrowserRouter>,
131
- );
132
- }
@@ -1,107 +0,0 @@
1
- import React from 'react';
2
- import { render, screen } from '@testing-library/react';
3
- import { Formik, Form } from 'formik';
4
- import { IdentifierInput } from './identifier-input.component';
5
- import { initialFormValues } from '../../../patient-registration.component';
6
- import { type PatientIdentifierType } from '../../../patient-registration-types';
7
-
8
- jest.mock('@openmrs/esm-framework', () => {
9
- const originalModule = jest.requireActual('@openmrs/esm-framework');
10
-
11
- return {
12
- ...originalModule,
13
- validator: jest.fn(),
14
- };
15
- });
16
-
17
- describe.skip('identifier input', () => {
18
- const openmrsID = {
19
- name: 'OpenMRS ID',
20
- fieldName: 'openMrsId',
21
- required: true,
22
- uuid: '05a29f94-c0ed-11e2-94be-8c13b969e334',
23
- format: null,
24
- isPrimary: true,
25
- identifierSources: [
26
- {
27
- uuid: '691eed12-c0f1-11e2-94be-8c13b969e334',
28
- name: 'Generator 1 for OpenMRS ID',
29
- autoGenerationOption: {
30
- manualEntryEnabled: false,
31
- automaticGenerationEnabled: true,
32
- },
33
- },
34
- {
35
- uuid: '01af8526-cea4-4175-aa90-340acb411771',
36
- name: 'Generator 2 for OpenMRS ID',
37
- autoGenerationOption: {
38
- manualEntryEnabled: true,
39
- automaticGenerationEnabled: true,
40
- },
41
- },
42
- ],
43
- autoGenerationSource: null,
44
- };
45
- const setupIdentifierInput = async (identifierType: PatientIdentifierType) => {
46
- initialFormValues['source-for-' + identifierType.fieldName] = identifierType.identifierSources[0].name;
47
- render(
48
- <Formik initialValues={initialFormValues} onSubmit={null}>
49
- <Form>
50
- <IdentifierInput identifierType={identifierType} />
51
- </Form>
52
- </Formik>,
53
- );
54
- const identifierInput = screen.getByLabelText(identifierType.fieldName) as HTMLInputElement;
55
- let identifierSourceSelectInput = screen.getByLabelText('source-for-' + identifierType.fieldName);
56
- return {
57
- identifierInput,
58
- identifierSourceSelectInput,
59
- };
60
- };
61
-
62
- it('exists', async () => {
63
- const { identifierInput, identifierSourceSelectInput } = await setupIdentifierInput(openmrsID);
64
- expect(identifierInput.type).toBe('text');
65
- expect(identifierSourceSelectInput.type).toBe('select-one');
66
- });
67
-
68
- it('has correct props for identifier source select input', async () => {
69
- const { identifierSourceSelectInput } = await setupIdentifierInput(openmrsID);
70
- expect(identifierSourceSelectInput.childElementCount).toBe(3);
71
- expect(identifierSourceSelectInput.value).toBe('Generator 1 for OpenMRS ID');
72
- });
73
-
74
- it('has correct props for identifier input', async () => {
75
- const { identifierInput } = await setupIdentifierInput(openmrsID);
76
- expect(identifierInput.placeholder).toBe('Auto-generated');
77
- expect(identifierInput.disabled).toBe(true);
78
- });
79
-
80
- it('text input should not be disabled if manual entry is enabled', async () => {
81
- // setup
82
- openmrsID.identifierSources[0].autoGenerationOption.manualEntryEnabled = true;
83
- // replay
84
- const { identifierInput } = await setupIdentifierInput(openmrsID);
85
- expect(identifierInput.placeholder).toBe('Auto-generated');
86
- expect(identifierInput.disabled).toBe(false);
87
- });
88
-
89
- it('should not render select widget if auto-entry is false', async () => {
90
- // setup
91
- openmrsID.identifierSources = [
92
- {
93
- uuid: '691eed12-c0f1-11e2-94be-8c13b969e334',
94
- name: 'Generator 1 for OpenMRS ID',
95
- autoGenerationOption: {
96
- manualEntryEnabled: true,
97
- automaticGenerationEnabled: false,
98
- },
99
- },
100
- ];
101
- // replay
102
- const { identifierInput, identifierSourceSelectInput } = await setupIdentifierInput(openmrsID);
103
- expect(identifierInput.placeholder).toBe('Enter identifier');
104
- expect(identifierInput.disabled).toBe(false);
105
- expect(identifierSourceSelectInput).toBe(undefined);
106
- });
107
- });