@openmrs/esm-form-engine-lib 2.1.0-pre.1462 → 2.1.0-pre.1466
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/package.json +1 -1
- package/src/api/index.ts +8 -4
- package/src/components/inputs/multi-select/multi-select.test.tsx +9 -11
- package/src/hooks/useFormJson.test.tsx +26 -5
- package/src/hooks/useFormJson.tsx +1 -1
- package/5bad9d4a3f2bed27/5bad9d4a3f2bed27.gz +0 -0
- package/8f9d17c6bed90e8b/8f9d17c6bed90e8b.gz +0 -0
- package/9b51d62ae699c65c/9b51d62ae699c65c.gz +0 -0
- package/cfeaf25d976dbd2e/cfeaf25d976dbd2e.gz +0 -0
package/package.json
CHANGED
package/src/api/index.ts
CHANGED
@@ -106,9 +106,13 @@ export async function fetchOpenMRSForm(nameOrUUID: string): Promise<OpenmrsForm
|
|
106
106
|
return openmrsFormResponse;
|
107
107
|
}
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
109
|
+
if (openmrsFormResponse.results?.length) {
|
110
|
+
const form = openmrsFormResponse.results.find((form) => form.retired === false);
|
111
|
+
if (form) {
|
112
|
+
return form;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
throw new Error(`Form with ID "${nameOrUUID}" was not found`);
|
112
116
|
}
|
113
117
|
|
114
118
|
/**
|
@@ -121,7 +125,7 @@ export async function fetchClobData(form: OpenmrsForm): Promise<any | null> {
|
|
121
125
|
return null;
|
122
126
|
}
|
123
127
|
|
124
|
-
const jsonSchemaResource = form.resources
|
128
|
+
const jsonSchemaResource = form.resources?.find(({ name }) => name === 'JSON schema');
|
125
129
|
if (!jsonSchemaResource) {
|
126
130
|
return null;
|
127
131
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { act, render, screen } from '@testing-library/react';
|
3
|
-
import
|
3
|
+
import userEvent from '@testing-library/user-event'; // Correct import for userEvent
|
4
4
|
import { type FetchResponse, openmrsFetch, usePatient, useSession } from '@openmrs/esm-framework';
|
5
5
|
import { type FormSchema } from '../../../types';
|
6
6
|
import { mockPatient } from '__mocks__/patient.mock';
|
@@ -31,7 +31,7 @@ jest.mock('../../../api', () => {
|
|
31
31
|
});
|
32
32
|
|
33
33
|
const renderForm = async () => {
|
34
|
-
await act(() =>
|
34
|
+
await act(async () => {
|
35
35
|
render(
|
36
36
|
<FormEngine
|
37
37
|
formJson={multiSelectFormSchema as unknown as FormSchema}
|
@@ -40,11 +40,11 @@ const renderForm = async () => {
|
|
40
40
|
formSessionIntent={undefined}
|
41
41
|
visit={visit}
|
42
42
|
/>,
|
43
|
-
)
|
44
|
-
);
|
43
|
+
);
|
44
|
+
});
|
45
45
|
};
|
46
46
|
|
47
|
-
describe
|
47
|
+
describe('MultiSelect Component', () => {
|
48
48
|
beforeEach(() => {
|
49
49
|
mockOpenmrsFetch.mockResolvedValue({
|
50
50
|
data: { results: [{ ...multiSelectFormSchema }] },
|
@@ -69,22 +69,20 @@ describe.skip('MultiSelect Component', () => {
|
|
69
69
|
it('should disable checkbox option if the field value depends on evaluates the expression to true', async () => {
|
70
70
|
const user = userEvent.setup();
|
71
71
|
await renderForm();
|
72
|
-
|
73
72
|
await user.click(screen.getByRole('combobox', { name: /Patient covered by NHIF/i }));
|
74
73
|
await user.click(screen.getByRole('option', { name: /no/i }));
|
75
|
-
|
76
74
|
await user.click(screen.getByText('Was this visit scheduled?'));
|
77
|
-
|
75
|
+
const unscheduledVisitOption = screen.getByRole('option', { name: /Unscheduled visit early/i });
|
76
|
+
expect(unscheduledVisitOption).toHaveAttribute('disabled');
|
78
77
|
});
|
79
78
|
|
80
79
|
it('should enable checkbox option if the field value depends on evaluates the expression to false', async () => {
|
81
80
|
const user = userEvent.setup();
|
82
81
|
await renderForm();
|
83
|
-
|
84
82
|
await user.click(screen.getByRole('combobox', { name: /patient covered by nhif/i }));
|
85
83
|
await user.click(screen.getByRole('option', { name: /yes/i }));
|
86
|
-
|
87
84
|
await user.click(screen.getByText('Was this visit scheduled?'));
|
88
|
-
|
85
|
+
const unscheduledVisitOption = screen.getByRole('option', { name: /Unscheduled visit early/i });
|
86
|
+
expect(unscheduledVisitOption).not.toBeDisabled();
|
89
87
|
});
|
90
88
|
});
|
@@ -36,6 +36,7 @@ const COMPONENT_ART_SCHEMA_VALUE_REF = '74d06044-850f-11ee-b9d1-0242ac120003';
|
|
36
36
|
const COMPONENT_PRECLINIC_REVIEW = 'component_preclinic-review';
|
37
37
|
const COMPONENT_PRECLINIC_REVIEW_UUID = '2f063f32-7f8a-11ee-b962-0242ac120004';
|
38
38
|
const COMPONENT_PRECLINIC_REVIEW_SCHEMA_VALUE_REF = '74d06044-850f-11ee-b9d1-0242ac120004';
|
39
|
+
const NON_EXISTENT_FORM_NAME = 'non-existent-form';
|
39
40
|
|
40
41
|
// Base setup
|
41
42
|
const mockOpenmrsFetch = openmrsFetch as jest.Mock;
|
@@ -74,6 +75,7 @@ when(mockOpenmrsFetch)
|
|
74
75
|
when(mockOpenmrsFetch)
|
75
76
|
.calledWith(buildPath(COMPONENT_ART))
|
76
77
|
.mockResolvedValue({ data: { results: [artComponentSkeleton] } });
|
78
|
+
|
77
79
|
when(mockOpenmrsFetch).calledWith(buildPath(COMPONENT_ART_UUID)).mockResolvedValue({ data: artComponentSkeleton });
|
78
80
|
when(mockOpenmrsFetch)
|
79
81
|
.calledWith(buildPath(COMPONENT_ART_SCHEMA_VALUE_REF))
|
@@ -82,6 +84,7 @@ when(mockOpenmrsFetch)
|
|
82
84
|
when(mockOpenmrsFetch)
|
83
85
|
.calledWith(buildPath(COMPONENT_PRECLINIC_REVIEW))
|
84
86
|
.mockResolvedValue({ data: { results: [preclinicReviewComponentSkeleton] } });
|
87
|
+
|
85
88
|
when(mockOpenmrsFetch)
|
86
89
|
.calledWith(buildPath(COMPONENT_PRECLINIC_REVIEW_UUID))
|
87
90
|
.mockResolvedValue({ data: preclinicReviewComponentSkeleton });
|
@@ -89,6 +92,10 @@ when(mockOpenmrsFetch)
|
|
89
92
|
.calledWith(buildPath(COMPONENT_PRECLINIC_REVIEW_SCHEMA_VALUE_REF))
|
90
93
|
.mockResolvedValue({ data: preclinicReviewComponentBody });
|
91
94
|
|
95
|
+
when(mockOpenmrsFetch)
|
96
|
+
.calledWith(buildPath(NON_EXISTENT_FORM_NAME))
|
97
|
+
.mockResolvedValue({ data: { results: [] } });
|
98
|
+
|
92
99
|
describe('useFormJson', () => {
|
93
100
|
it('should fetch basic form by name', async () => {
|
94
101
|
let hook = null;
|
@@ -97,7 +104,7 @@ describe('useFormJson', () => {
|
|
97
104
|
});
|
98
105
|
|
99
106
|
expect(hook.result.current.isLoading).toBe(false);
|
100
|
-
expect(hook.result.current.
|
107
|
+
expect(hook.result.current.formError).toBe(undefined);
|
101
108
|
expect(hook.result.current.formJson.name).toBe(MINI_FORM_NAME);
|
102
109
|
});
|
103
110
|
|
@@ -108,7 +115,7 @@ describe('useFormJson', () => {
|
|
108
115
|
});
|
109
116
|
|
110
117
|
expect(hook.result.current.isLoading).toBe(false);
|
111
|
-
expect(hook.result.current.
|
118
|
+
expect(hook.result.current.formError).toBe(undefined);
|
112
119
|
expect(hook.result.current.formJson.name).toBe(MINI_FORM_NAME);
|
113
120
|
});
|
114
121
|
|
@@ -119,7 +126,7 @@ describe('useFormJson', () => {
|
|
119
126
|
});
|
120
127
|
|
121
128
|
expect(hook.result.current.isLoading).toBe(false);
|
122
|
-
expect(hook.result.current.
|
129
|
+
expect(hook.result.current.formError).toBe(undefined);
|
123
130
|
expect(hook.result.current.formJson.name).toBe(PARENT_FORM_NAME);
|
124
131
|
|
125
132
|
// verify subforms
|
@@ -133,7 +140,7 @@ describe('useFormJson', () => {
|
|
133
140
|
});
|
134
141
|
|
135
142
|
expect(hook.result.current.isLoading).toBe(false);
|
136
|
-
expect(hook.result.current.
|
143
|
+
expect(hook.result.current.formError).toBe(undefined);
|
137
144
|
expect(hook.result.current.formJson.name).toBe(PARENT_FORM_NAME);
|
138
145
|
|
139
146
|
// verify subforms
|
@@ -146,12 +153,26 @@ describe('useFormJson', () => {
|
|
146
153
|
hook = renderHook(() => useFormJson(null, formComponentBody, null, null));
|
147
154
|
});
|
148
155
|
expect(hook.result.current.isLoading).toBe(false);
|
149
|
-
expect(hook.result.current.
|
156
|
+
expect(hook.result.current.formError).toBe(undefined);
|
150
157
|
expect(hook.result.current.formJson.name).toBe(COMPONENT_FORM_NAME);
|
151
158
|
|
152
159
|
// verify form components have been loaded
|
153
160
|
verifyFormComponents(hook.result.current.formJson);
|
154
161
|
});
|
162
|
+
|
163
|
+
it('should return an error when the form is not found', async () => {
|
164
|
+
// setup and execute
|
165
|
+
let hook = null;
|
166
|
+
await act(async () => {
|
167
|
+
hook = renderHook(() => useFormJson(NON_EXISTENT_FORM_NAME, null, null, null));
|
168
|
+
});
|
169
|
+
// verify
|
170
|
+
expect(hook.result.current.isLoading).toBe(false);
|
171
|
+
expect(hook.result.current.formError.message).toBe(
|
172
|
+
'Error loading form JSON: Form with ID "non-existent-form" was not found',
|
173
|
+
);
|
174
|
+
expect(hook.result.current.formJson).toBe(null);
|
175
|
+
});
|
155
176
|
});
|
156
177
|
|
157
178
|
function buildPath(path: string) {
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|