@ampath/esm-patient-registration-app 6.0.1-pre.7 → 6.0.1-pre.72
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.
- package/.turbo/turbo-build.log +23 -24
- package/dist/132.js +1 -0
- package/dist/197.js +1 -0
- package/dist/236.js +1 -0
- package/dist/{735.js.map → 236.js.map} +1 -1
- package/dist/300.js +1 -0
- package/dist/335.js +1 -0
- package/dist/372.js +1 -0
- package/dist/372.js.map +1 -0
- package/dist/41.js +2 -0
- package/dist/41.js.map +1 -0
- package/dist/449.js +1 -0
- package/dist/449.js.map +1 -0
- package/dist/464.js +1 -0
- package/dist/464.js.map +1 -0
- package/dist/495.js +1 -0
- package/dist/495.js.map +1 -0
- package/dist/55.js +1 -0
- package/dist/56.js +1 -0
- package/dist/56.js.map +1 -0
- package/dist/621.js +1 -1
- package/dist/621.js.map +1 -1
- package/dist/629.js +2 -0
- package/dist/629.js.LICENSE.txt +24 -0
- package/dist/629.js.map +1 -0
- package/dist/652.js +1 -0
- package/dist/661.js +1 -0
- package/dist/757.js +1 -1
- package/dist/757.js.map +1 -0
- package/dist/828.js +1 -0
- package/dist/828.js.map +1 -0
- package/dist/830.js +1 -0
- package/dist/830.js.map +1 -0
- package/dist/831.js +2 -0
- package/dist/831.js.map +1 -0
- package/dist/876.js +2 -0
- package/dist/876.js.map +1 -0
- package/dist/879.js +1 -1
- package/dist/913.js +2 -0
- package/dist/{591.js.LICENSE.txt → 913.js.LICENSE.txt} +23 -3
- package/dist/913.js.map +1 -0
- package/dist/927.js +1 -0
- package/dist/927.js.map +1 -0
- package/dist/99.js +1 -0
- package/dist/ampath-esm-patient-registration-app.js +1 -1
- package/dist/ampath-esm-patient-registration-app.js.buildmanifest.json +236 -191
- package/dist/ampath-esm-patient-registration-app.js.map +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.LICENSE.txt +0 -32
- package/dist/main.js.map +1 -1
- package/dist/routes.json +1 -1
- package/package.json +6 -9
- package/src/config-schema.ts +19 -10
- package/src/index.ts +11 -4
- package/src/offline.resources.ts +13 -18
- package/src/offline.ts +6 -4
- package/src/patient-photo.extension.tsx +9 -0
- package/src/patient-registration/field/address/custom-address-field.component.tsx +1 -0
- package/src/patient-registration/field/custom-field.component.tsx +6 -0
- package/src/patient-registration/field/dob/dob.component.tsx +17 -14
- package/src/patient-registration/field/field.resource.ts +3 -3
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.component.tsx +4 -0
- package/src/patient-registration/field/person-attributes/custom-person-attribute-field.component.tsx +56 -0
- package/src/patient-registration/field/person-attributes/person-attribute-field.component.tsx +22 -7
- package/src/patient-registration/field/person-attributes/person-attributes.resource.ts +2 -2
- package/src/patient-registration/field/phone/phone-field.component.tsx +1 -0
- package/src/patient-registration/form-manager.ts +13 -6
- package/src/patient-registration/patient-registration-hooks.ts +91 -9
- package/src/patient-registration/patient-registration.component.tsx +55 -13
- package/src/patient-registration/{patient-registration.resource.test.tsx → patient-registration.resource.testt.tsx} +3 -3
- package/src/patient-registration/patient-registration.resource.ts +15 -75
- package/src/patient-registration/patient-registration.scss +0 -8
- package/src/patient-registration/patient-registration.types.ts +7 -1
- package/src/patient-registration/section/patient-relationships/relationships-section.component.tsx +5 -1
- package/src/patient-registration/section/patient-relationships/relationships.resource.tsx +2 -2
- package/src/patient-verification/assets/counties.json +236 -0
- package/src/patient-verification/assets/verification-assets.ts +11 -0
- package/src/patient-verification/patient-verification-hook.tsx +176 -0
- package/src/patient-verification/patient-verification-utils.ts +179 -0
- package/src/patient-verification/patient-verification.component.tsx +124 -0
- package/src/patient-verification/patient-verification.scss +25 -0
- package/src/patient-verification/verification-modal/confirm-prompt.component.tsx +72 -0
- package/src/patient-verification/verification-modal/empty-prompt.component.tsx +35 -0
- package/src/patient-verification/verification-types.ts +50 -0
- package/src/routes.json +12 -3
- package/translations/am.json +26 -12
- package/translations/ar.json +26 -12
- package/translations/en.json +19 -5
- package/translations/es.json +10 -0
- package/translations/fr.json +6 -0
- package/translations/he.json +18 -0
- package/translations/km.json +18 -0
- package/translations/zh.json +30 -22
- package/translations/zh_CN.json +30 -22
- package/dist/130.js +0 -2
- package/dist/130.js.map +0 -1
- package/dist/152.js +0 -1
- package/dist/152.js.map +0 -1
- package/dist/249.js +0 -2
- package/dist/249.js.LICENSE.txt +0 -46
- package/dist/249.js.map +0 -1
- package/dist/255.js +0 -2
- package/dist/255.js.map +0 -1
- package/dist/271.js +0 -1
- package/dist/303.js +0 -1
- package/dist/303.js.map +0 -1
- package/dist/319.js +0 -1
- package/dist/365.js +0 -1
- package/dist/365.js.map +0 -1
- package/dist/460.js +0 -1
- package/dist/525.js +0 -1
- package/dist/525.js.map +0 -1
- package/dist/537.js +0 -1
- package/dist/537.js.map +0 -1
- package/dist/574.js +0 -1
- package/dist/591.js +0 -2
- package/dist/591.js.map +0 -1
- package/dist/644.js +0 -1
- package/dist/729.js +0 -1
- package/dist/729.js.map +0 -1
- package/dist/735.js +0 -1
- package/dist/784.js +0 -2
- package/dist/784.js.map +0 -1
- package/dist/788.js +0 -1
- package/dist/807.js +0 -1
- package/dist/833.js +0 -1
- package/dist/879.js.map +0 -1
- package/src/patient-registration/field/address/tests/address-hierarchy.test.tsx +0 -214
- package/src/patient-registration/field/address/tests/address-search-component.test.tsx +0 -135
- package/src/patient-registration/field/dob/dob.test.tsx +0 -75
- package/src/patient-registration/field/field.test.tsx +0 -294
- package/src/patient-registration/field/id/id-field.test.tsx +0 -107
- package/src/patient-registration/field/person-attributes/coded-attributes.component.tsx +0 -60
- package/src/patient-registration/field/person-attributes/coded-person-attribute-field.test.tsx +0 -127
- package/src/patient-registration/field/person-attributes/person-attribute-field.test.tsx +0 -187
- package/src/patient-registration/field/person-attributes/text-person-attribute-field.test.tsx +0 -88
- package/src/patient-registration/form-manager.test.ts +0 -67
- package/src/patient-registration/input/basic-input/select/select-input.test.tsx +0 -49
- package/src/patient-registration/input/custom-input/autosuggest/autosuggest.test.tsx +0 -132
- package/src/patient-registration/input/custom-input/identifier/identifier-input.test.tsx +0 -107
- package/src/patient-registration/patient-registration.test.tsx +0 -471
- package/src/patient-registration/section/death-info/death-info-section.test.tsx +0 -64
- package/src/patient-registration/section/demographics/demographics-section.test.tsx +0 -83
- package/src/patient-registration/section/patient-relationships/relationships-section.test.tsx +0 -100
- package/src/patient-verification/client-registry-constants.ts +0 -13
- package/src/patient-verification/client-registry.component.tsx +0 -66
- package/src/patient-verification/client-registry.scss +0 -1
- package/src/patient-verification/utils.tsx +0 -56
- package/src/patient-verification/verification-modal.scss +0 -20
- package/src/patient-verification/verification.component.tsx +0 -48
- package/src/root.test.tsx +0 -32
- package/src/widgets/cancel-patient-edit.test.tsx +0 -27
- package/src/widgets/display-photo.component.tsx +0 -30
- package/src/widgets/display-photo.test.tsx +0 -37
- package/src/widgets/edit-patient-details-button.test.tsx +0 -41
- /package/dist/{784.js.LICENSE.txt → 41.js.LICENSE.txt} +0 -0
- /package/dist/{130.js.LICENSE.txt → 831.js.LICENSE.txt} +0 -0
- /package/dist/{255.js.LICENSE.txt → 876.js.LICENSE.txt} +0 -0
- /package/src/patient-registration/input/custom-input/identifier/{utils.test.ts → utils.testt.ts} +0 -0
- /package/src/widgets/{delete-identifier-confirmation-modal.test.tsx → delete-identifier-confirmation-modal.testt.tsx} +0 -0
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { cleanup, render, screen } from '@testing-library/react';
|
|
3
|
-
import { AddressComponent } from '../address-field.component';
|
|
4
|
-
import { Formik, Form } from 'formik';
|
|
5
|
-
import { type Resources, ResourcesContext } from '../../../../offline.resources';
|
|
6
|
-
import { PatientRegistrationContext } from '../../../patient-registration-context';
|
|
7
|
-
import { useConfig } from '@openmrs/esm-framework';
|
|
8
|
-
import { useOrderedAddressHierarchyLevels } from '../address-hierarchy.resource';
|
|
9
|
-
import { mockedAddressTemplate, mockedOrderedFields } from '__mocks__';
|
|
10
|
-
|
|
11
|
-
// Mocking the AddressSearchComponent
|
|
12
|
-
jest.mock('../address-search.component', () => jest.fn(() => <div data-testid="address-search-bar" />));
|
|
13
|
-
// Mocking the AddressHierarchyLevels
|
|
14
|
-
jest.mock('../address-hierarchy-levels.component', () => jest.fn(() => <div data-testid="address-hierarchy-levels" />));
|
|
15
|
-
// Mocking the SkeletonText
|
|
16
|
-
jest.mock('@carbon/react', () => ({
|
|
17
|
-
...jest.requireActual('@carbon/react'),
|
|
18
|
-
SkeletonText: jest.fn(() => <div data-testid="skeleton-text" />),
|
|
19
|
-
InlineNotification: jest.fn(() => <div data-testid="inline-notification" />),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
jest.mock('@openmrs/esm-framework', () => ({
|
|
23
|
-
...jest.requireActual('@openmrs/esm-framework'),
|
|
24
|
-
useConfig: jest.fn(),
|
|
25
|
-
}));
|
|
26
|
-
|
|
27
|
-
jest.mock('../address-hierarchy.resource', () => ({
|
|
28
|
-
...(jest.requireActual('../address-hierarchy.resource') as jest.Mock),
|
|
29
|
-
useOrderedAddressHierarchyLevels: jest.fn(),
|
|
30
|
-
}));
|
|
31
|
-
|
|
32
|
-
async function renderAddressHierarchy(addressTemplate = mockedAddressTemplate) {
|
|
33
|
-
await render(
|
|
34
|
-
<ResourcesContext.Provider value={{ addressTemplate } as unknown as Resources}>
|
|
35
|
-
<Formik initialValues={{}} onSubmit={null}>
|
|
36
|
-
<Form>
|
|
37
|
-
<PatientRegistrationContext.Provider value={{ setFieldValue: jest.fn() } as any}>
|
|
38
|
-
<AddressComponent />
|
|
39
|
-
</PatientRegistrationContext.Provider>
|
|
40
|
-
</Form>
|
|
41
|
-
</Formik>
|
|
42
|
-
</ResourcesContext.Provider>,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
describe('Testing address hierarchy', () => {
|
|
47
|
-
beforeEach(cleanup);
|
|
48
|
-
|
|
49
|
-
it('should render skeleton when address template is loading', () => {
|
|
50
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
51
|
-
fieldConfigurations: {
|
|
52
|
-
address: {
|
|
53
|
-
useAddressHierarchy: {
|
|
54
|
-
enabled: false,
|
|
55
|
-
useQuickSearch: false,
|
|
56
|
-
searchAddressByLevel: false,
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
}));
|
|
61
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
62
|
-
orderedFields: [],
|
|
63
|
-
isLoadingFieldOrder: false,
|
|
64
|
-
errorFetchingFieldOrder: null,
|
|
65
|
-
}));
|
|
66
|
-
// @ts-ignore
|
|
67
|
-
renderAddressHierarchy(null);
|
|
68
|
-
const skeletonText = screen.getByTestId('skeleton-text');
|
|
69
|
-
expect(skeletonText).toBeInTheDocument();
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('should render skeleton when address hierarchy is enabled and addresshierarchy order is loading', () => {
|
|
73
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
74
|
-
fieldConfigurations: {
|
|
75
|
-
address: {
|
|
76
|
-
useAddressHierarchy: {
|
|
77
|
-
enabled: true,
|
|
78
|
-
useQuickSearch: false,
|
|
79
|
-
searchAddressByLevel: false,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
}));
|
|
84
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
85
|
-
orderedFields: [],
|
|
86
|
-
isLoadingFieldOrder: true,
|
|
87
|
-
errorFetchingFieldOrder: null,
|
|
88
|
-
}));
|
|
89
|
-
renderAddressHierarchy();
|
|
90
|
-
const skeletonText = screen.getByTestId('skeleton-text');
|
|
91
|
-
expect(skeletonText).toBeInTheDocument();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('should render skeleton when address hierarchy is enabled and addresshierarchy order is loading', () => {
|
|
95
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
96
|
-
fieldConfigurations: {
|
|
97
|
-
address: {
|
|
98
|
-
useAddressHierarchy: {
|
|
99
|
-
enabled: true,
|
|
100
|
-
useQuickSearch: false,
|
|
101
|
-
searchAddressByLevel: false,
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
}));
|
|
106
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
107
|
-
orderedFields: [],
|
|
108
|
-
isLoadingFieldOrder: false,
|
|
109
|
-
errorFetchingFieldOrder: true,
|
|
110
|
-
}));
|
|
111
|
-
renderAddressHierarchy();
|
|
112
|
-
const inlineNotification = screen.getByTestId('inline-notification');
|
|
113
|
-
expect(inlineNotification).toBeInTheDocument();
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should render the address component with address hierarchy disabled', () => {
|
|
117
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
118
|
-
fieldConfigurations: {
|
|
119
|
-
address: {
|
|
120
|
-
useAddressHierarchy: {
|
|
121
|
-
enabled: false,
|
|
122
|
-
useQuickSearch: false,
|
|
123
|
-
searchAddressByLevel: false,
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
}));
|
|
128
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
129
|
-
orderedFields: [],
|
|
130
|
-
isLoadingFieldOrder: false,
|
|
131
|
-
errorFetchingFieldOrder: null,
|
|
132
|
-
}));
|
|
133
|
-
renderAddressHierarchy();
|
|
134
|
-
const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN');
|
|
135
|
-
allFields.forEach((field) => {
|
|
136
|
-
const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`);
|
|
137
|
-
expect(textFieldInput).toBeInTheDocument();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should render the fields in order if the address hierarcy is enabled', () => {
|
|
142
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
143
|
-
fieldConfigurations: {
|
|
144
|
-
address: {
|
|
145
|
-
useAddressHierarchy: {
|
|
146
|
-
enabled: true,
|
|
147
|
-
useQuickSearch: false,
|
|
148
|
-
searchAddressByLevel: false,
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
}));
|
|
153
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
154
|
-
orderedFields: [],
|
|
155
|
-
isLoadingFieldOrder: false,
|
|
156
|
-
errorFetchingFieldOrder: null,
|
|
157
|
-
}));
|
|
158
|
-
renderAddressHierarchy();
|
|
159
|
-
const allFields = mockedAddressTemplate.lines.flat().filter(({ isToken }) => isToken === 'IS_ADDR_TOKEN');
|
|
160
|
-
const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx]));
|
|
161
|
-
allFields.sort(
|
|
162
|
-
(existingField1, existingField2) =>
|
|
163
|
-
orderMap[existingField1.codeName ?? 0] - orderMap[existingField2.codeName ?? 0],
|
|
164
|
-
);
|
|
165
|
-
allFields.forEach((field) => {
|
|
166
|
-
const textFieldInput = screen.getByLabelText(`${field.displayText} (optional)`);
|
|
167
|
-
expect(textFieldInput).toBeInTheDocument();
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('should render quick search bar on above the fields when address hierarchy is enabled and quicksearch is set to true', () => {
|
|
172
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
173
|
-
fieldConfigurations: {
|
|
174
|
-
address: {
|
|
175
|
-
useAddressHierarchy: {
|
|
176
|
-
enabled: true,
|
|
177
|
-
useQuickSearch: true,
|
|
178
|
-
searchAddressByLevel: false,
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
}));
|
|
183
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
184
|
-
orderedFields: [],
|
|
185
|
-
isLoadingFieldOrder: false,
|
|
186
|
-
errorFetchingFieldOrder: null,
|
|
187
|
-
}));
|
|
188
|
-
renderAddressHierarchy();
|
|
189
|
-
const addressSearchBar = screen.getByTestId('address-search-bar');
|
|
190
|
-
expect(addressSearchBar).toBeInTheDocument();
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it('should render combo boxes fields when address hierarchy is enabled and searchAddressByLevel is set to true', () => {
|
|
194
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
195
|
-
fieldConfigurations: {
|
|
196
|
-
address: {
|
|
197
|
-
useAddressHierarchy: {
|
|
198
|
-
enabled: true,
|
|
199
|
-
useQuickSearch: false,
|
|
200
|
-
searchAddressByLevel: true,
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
}));
|
|
205
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
206
|
-
orderedFields: [],
|
|
207
|
-
isLoadingFieldOrder: false,
|
|
208
|
-
errorFetchingFieldOrder: null,
|
|
209
|
-
}));
|
|
210
|
-
renderAddressHierarchy();
|
|
211
|
-
const addressHierarchyLevels = screen.getByTestId('address-hierarchy-levels');
|
|
212
|
-
expect(addressHierarchyLevels).toBeInTheDocument();
|
|
213
|
-
});
|
|
214
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import userEvent from '@testing-library/user-event';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import { Formik, Form, useFormikContext } from 'formik';
|
|
5
|
-
import { type Resources, ResourcesContext } from '../../../../offline.resources';
|
|
6
|
-
import { PatientRegistrationContext } from '../../../patient-registration-context';
|
|
7
|
-
import { useConfig } from '@openmrs/esm-framework';
|
|
8
|
-
import { useAddressHierarchy, useOrderedAddressHierarchyLevels } from '../address-hierarchy.resource';
|
|
9
|
-
import { mockedAddressTemplate, mockedAddressOptions, mockedOrderedFields } from '__mocks__';
|
|
10
|
-
import AddressSearchComponent from '../address-search.component';
|
|
11
|
-
|
|
12
|
-
useAddressHierarchy;
|
|
13
|
-
jest.mock('@openmrs/esm-framework', () => ({
|
|
14
|
-
...jest.requireActual('@openmrs/esm-framework'),
|
|
15
|
-
useConfig: jest.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
jest.mock('../address-hierarchy.resource', () => ({
|
|
19
|
-
...(jest.requireActual('../address-hierarchy.resource') as jest.Mock),
|
|
20
|
-
useOrderedAddressHierarchyLevels: jest.fn(),
|
|
21
|
-
useAddressHierarchy: jest.fn(),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
jest.mock('../../../patient-registration.resource', () => ({
|
|
25
|
-
...(jest.requireActual('../../../../patient-registration.resource') as jest.Mock),
|
|
26
|
-
useAddressHierarchy: jest.fn(),
|
|
27
|
-
}));
|
|
28
|
-
|
|
29
|
-
jest.mock('formik', () => ({
|
|
30
|
-
...(jest.requireActual('formik') as jest.Mock),
|
|
31
|
-
useFormikContext: jest.fn(() => ({})),
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
const allFields = mockedAddressTemplate.lines
|
|
35
|
-
.flat()
|
|
36
|
-
.filter((field) => field.isToken === 'IS_ADDR_TOKEN')
|
|
37
|
-
.map(({ codeName, displayText }) => ({
|
|
38
|
-
id: codeName,
|
|
39
|
-
name: codeName,
|
|
40
|
-
label: displayText,
|
|
41
|
-
}));
|
|
42
|
-
const orderMap = Object.fromEntries(mockedOrderedFields.map((field, indx) => [field, indx]));
|
|
43
|
-
allFields.sort((existingField1, existingField2) => orderMap[existingField1.name] - orderMap[existingField2.name]);
|
|
44
|
-
|
|
45
|
-
async function renderAddressHierarchy(addressTemplate = mockedAddressTemplate) {
|
|
46
|
-
await render(
|
|
47
|
-
<ResourcesContext.Provider value={{ addressTemplate } as Resources}>
|
|
48
|
-
<Formik initialValues={{}} onSubmit={null}>
|
|
49
|
-
<Form>
|
|
50
|
-
<PatientRegistrationContext.Provider value={{ setFieldValue: jest.fn() } as any}>
|
|
51
|
-
<AddressSearchComponent addressLayout={allFields} />
|
|
52
|
-
</PatientRegistrationContext.Provider>
|
|
53
|
-
</Form>
|
|
54
|
-
</Formik>
|
|
55
|
-
</ResourcesContext.Provider>,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const setFieldValue = jest.fn();
|
|
60
|
-
|
|
61
|
-
describe('Testing address search bar', () => {
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
(useConfig as jest.Mock).mockImplementation(() => ({
|
|
64
|
-
fieldConfigurations: {
|
|
65
|
-
address: {
|
|
66
|
-
useAddressHierarchy: {
|
|
67
|
-
enabled: true,
|
|
68
|
-
useQuickSearch: true,
|
|
69
|
-
searchAddressByLevel: false,
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
}));
|
|
74
|
-
(useOrderedAddressHierarchyLevels as jest.Mock).mockImplementation(() => ({
|
|
75
|
-
orderedFields: mockedOrderedFields,
|
|
76
|
-
isLoadingFieldOrder: false,
|
|
77
|
-
errorFetchingFieldOrder: null,
|
|
78
|
-
}));
|
|
79
|
-
(useFormikContext as jest.Mock).mockImplementation(() => ({
|
|
80
|
-
setFieldValue,
|
|
81
|
-
}));
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('should render the search bar', () => {
|
|
85
|
-
(useAddressHierarchy as jest.Mock).mockImplementation(() => ({
|
|
86
|
-
addresses: [],
|
|
87
|
-
error: null,
|
|
88
|
-
isLoading: false,
|
|
89
|
-
}));
|
|
90
|
-
|
|
91
|
-
renderAddressHierarchy();
|
|
92
|
-
|
|
93
|
-
const searchbox = screen.getByRole('searchbox');
|
|
94
|
-
expect(searchbox).toBeInTheDocument();
|
|
95
|
-
|
|
96
|
-
const ul = screen.queryByRole('list');
|
|
97
|
-
expect(ul).not.toBeInTheDocument();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("should render only the results for the search term matched address' parents", async () => {
|
|
101
|
-
const user = userEvent.setup();
|
|
102
|
-
|
|
103
|
-
(useAddressHierarchy as jest.Mock).mockImplementation(() => ({
|
|
104
|
-
addresses: mockedAddressOptions,
|
|
105
|
-
error: null,
|
|
106
|
-
isLoading: false,
|
|
107
|
-
}));
|
|
108
|
-
|
|
109
|
-
renderAddressHierarchy();
|
|
110
|
-
|
|
111
|
-
const searchString = 'nea';
|
|
112
|
-
const separator = ' > ';
|
|
113
|
-
const options: Set<string> = new Set();
|
|
114
|
-
|
|
115
|
-
mockedAddressOptions.forEach((address) => {
|
|
116
|
-
const values = address.split(separator);
|
|
117
|
-
values.forEach((val, index) => {
|
|
118
|
-
if (val.toLowerCase().includes(searchString.toLowerCase())) {
|
|
119
|
-
options.add(values.slice(0, index + 1).join(separator));
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const addressOptions = [...options];
|
|
125
|
-
addressOptions.forEach(async (address) => {
|
|
126
|
-
const optionElement = screen.getByText(address);
|
|
127
|
-
expect(optionElement).toBeInTheDocument();
|
|
128
|
-
await user.click(optionElement);
|
|
129
|
-
const values = address.split(separator);
|
|
130
|
-
allFields.map(({ name }, index) => {
|
|
131
|
-
expect(setFieldValue).toHaveBeenCalledWith(`address.${name}`, values?.[index]);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Formik, Form } from 'formik';
|
|
3
|
-
import { render, screen } from '@testing-library/react';
|
|
4
|
-
import userEvent from '@testing-library/user-event';
|
|
5
|
-
import { DobField } from './dob.component';
|
|
6
|
-
import { PatientRegistrationContext } from '../../patient-registration-context';
|
|
7
|
-
import { initialFormValues } from '../../patient-registration.component';
|
|
8
|
-
import { type FormValues } from '../../patient-registration.types';
|
|
9
|
-
|
|
10
|
-
jest.mock('@openmrs/esm-framework', () => {
|
|
11
|
-
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
12
|
-
return {
|
|
13
|
-
...originalModule,
|
|
14
|
-
useConfig: jest.fn().mockImplementation(() => ({
|
|
15
|
-
fieldConfigurations: {
|
|
16
|
-
dateOfBirth: {
|
|
17
|
-
allowEstimatedDateOfBirth: true,
|
|
18
|
-
useEstimatedDateOfBirth: { enabled: true, dayOfMonth: 0, month: 0 },
|
|
19
|
-
},
|
|
20
|
-
},
|
|
21
|
-
})),
|
|
22
|
-
};
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('Dob', () => {
|
|
26
|
-
it('renders the fields in the birth section of the registration form', async () => {
|
|
27
|
-
renderDob();
|
|
28
|
-
|
|
29
|
-
expect(screen.getByRole('heading', { name: /birth/i })).toBeInTheDocument();
|
|
30
|
-
expect(screen.getByText(/date of birth known?/i)).toBeInTheDocument();
|
|
31
|
-
expect(screen.getByRole('tab', { name: /no/i })).toBeInTheDocument();
|
|
32
|
-
expect(screen.getByRole('tab', { name: /yes/i })).toBeInTheDocument();
|
|
33
|
-
expect(screen.getByRole('tab', { name: /yes/i })).toHaveAttribute('aria-selected', 'true');
|
|
34
|
-
expect(screen.getByRole('tab', { name: /no/i })).toHaveAttribute('aria-selected', 'false');
|
|
35
|
-
expect(screen.getByRole('textbox', { name: /date of birth/i })).toBeInTheDocument();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('typing in the date picker input sets the date of birth', async () => {
|
|
39
|
-
const user = userEvent.setup();
|
|
40
|
-
|
|
41
|
-
renderDob();
|
|
42
|
-
|
|
43
|
-
const dateInput = screen.getByRole('textbox', { name: /date of birth/i });
|
|
44
|
-
expect(dateInput).toBeInTheDocument();
|
|
45
|
-
|
|
46
|
-
await user.type(dateInput, '10/10/2022');
|
|
47
|
-
|
|
48
|
-
expect(screen.getByPlaceholderText('dd/mm/YYYY')).toHaveValue('10/10/2022');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
function renderDob() {
|
|
53
|
-
let formValues: FormValues = initialFormValues;
|
|
54
|
-
|
|
55
|
-
render(
|
|
56
|
-
<Formik initialValues={{ birthdate: '' }} onSubmit={() => {}}>
|
|
57
|
-
<Form>
|
|
58
|
-
<PatientRegistrationContext.Provider
|
|
59
|
-
value={{
|
|
60
|
-
identifierTypes: [],
|
|
61
|
-
values: formValues,
|
|
62
|
-
validationSchema: null,
|
|
63
|
-
inEditMode: false,
|
|
64
|
-
setFieldValue: () => {},
|
|
65
|
-
setCapturePhotoProps: (value) => {},
|
|
66
|
-
currentPhoto: '',
|
|
67
|
-
isOffline: false,
|
|
68
|
-
initialFormValues: formValues,
|
|
69
|
-
}}>
|
|
70
|
-
<DobField />
|
|
71
|
-
</PatientRegistrationContext.Provider>
|
|
72
|
-
</Form>
|
|
73
|
-
</Formik>,
|
|
74
|
-
);
|
|
75
|
-
}
|