@openmrs/esm-form-builder-app 2.2.2-pre.654 → 2.2.2-pre.658
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.
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { screen
|
|
2
|
+
import { screen } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
|
-
import { navigate, openmrsFetch, usePagination } from '@openmrs/esm-framework';
|
|
4
|
+
import { type FetchResponse, navigate, openmrsFetch, usePagination } from '@openmrs/esm-framework';
|
|
5
5
|
import { renderWithSwr, waitForLoadingToFinish } from '../../test-helpers';
|
|
6
6
|
import { deleteForm } from '../../forms.resource';
|
|
7
7
|
import Dashboard from './dashboard.component';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
type OpenmrsFetchResponse = Promise<
|
|
10
|
+
FetchResponse<{
|
|
11
|
+
results: unknown[];
|
|
12
|
+
}>
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
type PaginationData = {
|
|
16
|
+
currentPage: number;
|
|
17
|
+
goTo: (page: number) => void;
|
|
18
|
+
results: unknown[];
|
|
19
|
+
totalPages: number;
|
|
20
|
+
paginated: boolean;
|
|
21
|
+
showNextButton: boolean;
|
|
22
|
+
showPreviousButton: boolean;
|
|
23
|
+
goToNext: () => void;
|
|
24
|
+
goToPrevious: () => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const mockedOpenmrsFetch = jest.mocked(openmrsFetch);
|
|
28
|
+
const mockedDeleteForm = jest.mocked(deleteForm);
|
|
29
|
+
const mockUsePagination = jest.mocked(usePagination);
|
|
17
30
|
|
|
18
31
|
const formsResponse = [
|
|
19
32
|
{
|
|
@@ -37,6 +50,10 @@ const formsResponse = [
|
|
|
37
50
|
},
|
|
38
51
|
];
|
|
39
52
|
|
|
53
|
+
jest.mock('../../forms.resource', () => ({
|
|
54
|
+
deleteForm: jest.fn(),
|
|
55
|
+
}));
|
|
56
|
+
|
|
40
57
|
jest.mock('@openmrs/esm-framework', () => {
|
|
41
58
|
const originalModule = jest.requireActual('@openmrs/esm-framework');
|
|
42
59
|
|
|
@@ -51,9 +68,11 @@ jest.mock('@openmrs/esm-framework', () => {
|
|
|
51
68
|
};
|
|
52
69
|
});
|
|
53
70
|
|
|
71
|
+
global.window.URL.createObjectURL = jest.fn();
|
|
72
|
+
|
|
54
73
|
describe('Dashboard', () => {
|
|
55
74
|
it('renders an empty state view if no forms are available', async () => {
|
|
56
|
-
mockedOpenmrsFetch.mockReturnValueOnce({ data: { results: [] } });
|
|
75
|
+
mockedOpenmrsFetch.mockReturnValueOnce({ data: { results: [] } } as unknown as OpenmrsFetchResponse);
|
|
57
76
|
|
|
58
77
|
renderDashboard();
|
|
59
78
|
|
|
@@ -73,7 +92,7 @@ describe('Dashboard', () => {
|
|
|
73
92
|
data: {
|
|
74
93
|
results: formsResponse,
|
|
75
94
|
},
|
|
76
|
-
});
|
|
95
|
+
} as unknown as OpenmrsFetchResponse);
|
|
77
96
|
|
|
78
97
|
renderDashboard();
|
|
79
98
|
|
|
@@ -81,17 +100,20 @@ describe('Dashboard', () => {
|
|
|
81
100
|
|
|
82
101
|
const searchbox = screen.getByRole('searchbox') as HTMLInputElement;
|
|
83
102
|
|
|
84
|
-
await
|
|
103
|
+
await user.type(searchbox, 'COVID');
|
|
85
104
|
|
|
86
105
|
expect(searchbox.value).toBe('COVID');
|
|
87
106
|
|
|
88
|
-
mockUsePagination.mockImplementation(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
mockUsePagination.mockImplementation(
|
|
108
|
+
() =>
|
|
109
|
+
({
|
|
110
|
+
currentPage: 1,
|
|
111
|
+
goTo: () => {},
|
|
112
|
+
results: formsResponse.filter((form) => form.name === searchbox.value),
|
|
113
|
+
}) as unknown as PaginationData,
|
|
114
|
+
);
|
|
93
115
|
|
|
94
|
-
await
|
|
116
|
+
await expect(screen.queryByText(/Test Form 1/i)).not.toBeInTheDocument();
|
|
95
117
|
expect(screen.getByText(/no matching forms to display/i)).toBeInTheDocument();
|
|
96
118
|
});
|
|
97
119
|
|
|
@@ -102,7 +124,7 @@ describe('Dashboard', () => {
|
|
|
102
124
|
data: {
|
|
103
125
|
results: formsResponse,
|
|
104
126
|
},
|
|
105
|
-
});
|
|
127
|
+
} as unknown as OpenmrsFetchResponse);
|
|
106
128
|
|
|
107
129
|
renderDashboard();
|
|
108
130
|
|
|
@@ -112,14 +134,17 @@ describe('Dashboard', () => {
|
|
|
112
134
|
name: /filter by/i,
|
|
113
135
|
});
|
|
114
136
|
|
|
115
|
-
await
|
|
116
|
-
await
|
|
137
|
+
await user.click(publishStatusFilter);
|
|
138
|
+
await user.click(screen.getByRole('option', { name: /unpublished/i }));
|
|
117
139
|
|
|
118
|
-
mockUsePagination.mockImplementation(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
140
|
+
mockUsePagination.mockImplementation(
|
|
141
|
+
() =>
|
|
142
|
+
({
|
|
143
|
+
currentPage: 1,
|
|
144
|
+
goTo: () => {},
|
|
145
|
+
results: formsResponse.filter((form) => !form.published),
|
|
146
|
+
}) as unknown as PaginationData,
|
|
147
|
+
);
|
|
123
148
|
|
|
124
149
|
expect(screen.queryByText(/Test Form 1/i)).not.toBeInTheDocument();
|
|
125
150
|
expect(screen.getByText(/no matching forms to display/i)).toBeInTheDocument();
|
|
@@ -130,13 +155,16 @@ describe('Dashboard', () => {
|
|
|
130
155
|
data: {
|
|
131
156
|
results: formsResponse,
|
|
132
157
|
},
|
|
133
|
-
});
|
|
158
|
+
} as unknown as OpenmrsFetchResponse);
|
|
134
159
|
|
|
135
|
-
mockUsePagination.mockImplementation(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
160
|
+
mockUsePagination.mockImplementation(
|
|
161
|
+
() =>
|
|
162
|
+
({
|
|
163
|
+
currentPage: 1,
|
|
164
|
+
goTo: () => {},
|
|
165
|
+
results: formsResponse,
|
|
166
|
+
}) as unknown as PaginationData,
|
|
167
|
+
);
|
|
140
168
|
|
|
141
169
|
renderDashboard();
|
|
142
170
|
|
|
@@ -159,13 +187,16 @@ describe('Dashboard', () => {
|
|
|
159
187
|
data: {
|
|
160
188
|
results: formsResponse,
|
|
161
189
|
},
|
|
162
|
-
});
|
|
190
|
+
} as unknown as OpenmrsFetchResponse);
|
|
163
191
|
|
|
164
|
-
mockUsePagination.mockImplementation(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
192
|
+
mockUsePagination.mockImplementation(
|
|
193
|
+
() =>
|
|
194
|
+
({
|
|
195
|
+
currentPage: 1,
|
|
196
|
+
goTo: () => {},
|
|
197
|
+
results: formsResponse,
|
|
198
|
+
}) as unknown as PaginationData,
|
|
199
|
+
);
|
|
169
200
|
|
|
170
201
|
renderDashboard();
|
|
171
202
|
|
|
@@ -187,13 +218,16 @@ describe('Dashboard', () => {
|
|
|
187
218
|
data: {
|
|
188
219
|
results: formsResponse,
|
|
189
220
|
},
|
|
190
|
-
});
|
|
221
|
+
} as unknown as OpenmrsFetchResponse);
|
|
191
222
|
|
|
192
|
-
mockUsePagination.mockImplementation(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
223
|
+
mockUsePagination.mockImplementation(
|
|
224
|
+
() =>
|
|
225
|
+
({
|
|
226
|
+
currentPage: 1,
|
|
227
|
+
goTo: () => {},
|
|
228
|
+
results: formsResponse,
|
|
229
|
+
}) as unknown as PaginationData,
|
|
230
|
+
);
|
|
197
231
|
|
|
198
232
|
renderDashboard();
|
|
199
233
|
|
|
@@ -210,13 +244,16 @@ describe('Dashboard', () => {
|
|
|
210
244
|
data: {
|
|
211
245
|
results: formsResponse,
|
|
212
246
|
},
|
|
213
|
-
});
|
|
247
|
+
} as unknown as OpenmrsFetchResponse);
|
|
214
248
|
|
|
215
|
-
mockUsePagination.mockImplementation(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
249
|
+
mockUsePagination.mockImplementation(
|
|
250
|
+
() =>
|
|
251
|
+
({
|
|
252
|
+
currentPage: 1,
|
|
253
|
+
goTo: () => {},
|
|
254
|
+
results: formsResponse,
|
|
255
|
+
}) as unknown as PaginationData,
|
|
256
|
+
);
|
|
220
257
|
|
|
221
258
|
renderDashboard();
|
|
222
259
|
|
|
@@ -226,7 +263,7 @@ describe('Dashboard', () => {
|
|
|
226
263
|
name: /edit schema/i,
|
|
227
264
|
});
|
|
228
265
|
|
|
229
|
-
await
|
|
266
|
+
await user.click(editSchemaButton);
|
|
230
267
|
|
|
231
268
|
expect(navigate).toHaveBeenCalledWith({
|
|
232
269
|
to: expect.stringMatching(/form\-builder\/edit/),
|
|
@@ -240,13 +277,17 @@ describe('Dashboard', () => {
|
|
|
240
277
|
data: {
|
|
241
278
|
results: formsResponse,
|
|
242
279
|
},
|
|
243
|
-
});
|
|
280
|
+
} as unknown as OpenmrsFetchResponse);
|
|
281
|
+
|
|
282
|
+
mockUsePagination.mockImplementation(
|
|
283
|
+
() =>
|
|
284
|
+
({
|
|
285
|
+
currentPage: 1,
|
|
286
|
+
goTo: () => {},
|
|
287
|
+
results: formsResponse,
|
|
288
|
+
}) as unknown as PaginationData,
|
|
289
|
+
);
|
|
244
290
|
|
|
245
|
-
mockUsePagination.mockImplementation(() => ({
|
|
246
|
-
currentPage: 1,
|
|
247
|
-
goTo: () => {},
|
|
248
|
-
results: formsResponse,
|
|
249
|
-
}));
|
|
250
291
|
renderDashboard();
|
|
251
292
|
|
|
252
293
|
await waitForLoadingToFinish();
|
|
@@ -255,7 +296,7 @@ describe('Dashboard', () => {
|
|
|
255
296
|
name: /download schema/i,
|
|
256
297
|
});
|
|
257
298
|
|
|
258
|
-
await
|
|
299
|
+
await user.click(downloadSchemaButton);
|
|
259
300
|
|
|
260
301
|
expect(window.URL.createObjectURL).toHaveBeenCalled();
|
|
261
302
|
});
|
|
@@ -267,14 +308,18 @@ describe('Dashboard', () => {
|
|
|
267
308
|
data: {
|
|
268
309
|
results: formsResponse,
|
|
269
310
|
},
|
|
270
|
-
});
|
|
271
|
-
mockedDeleteForm.mockResolvedValue({});
|
|
311
|
+
} as unknown as OpenmrsFetchResponse);
|
|
272
312
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
313
|
+
mockedDeleteForm.mockResolvedValue({} as FetchResponse<Record<string, never>>);
|
|
314
|
+
|
|
315
|
+
mockUsePagination.mockImplementation(
|
|
316
|
+
() =>
|
|
317
|
+
({
|
|
318
|
+
currentPage: 1,
|
|
319
|
+
goTo: () => {},
|
|
320
|
+
results: formsResponse,
|
|
321
|
+
}) as unknown as PaginationData,
|
|
322
|
+
);
|
|
278
323
|
|
|
279
324
|
renderDashboard();
|
|
280
325
|
|
|
@@ -283,7 +328,7 @@ describe('Dashboard', () => {
|
|
|
283
328
|
const deleteButton = screen.getByRole('button', { name: /delete schema/i });
|
|
284
329
|
expect(deleteButton).toBeInTheDocument();
|
|
285
330
|
|
|
286
|
-
await
|
|
331
|
+
await user.click(deleteButton);
|
|
287
332
|
|
|
288
333
|
const modal = screen.getByRole('presentation');
|
|
289
334
|
expect(modal).toBeInTheDocument();
|
|
@@ -292,7 +337,7 @@ describe('Dashboard', () => {
|
|
|
292
337
|
expect(screen.getByRole('button', { name: /cancel/i })).toBeInTheDocument();
|
|
293
338
|
expect(screen.getByRole('button', { name: /danger delete/i })).toBeInTheDocument();
|
|
294
339
|
|
|
295
|
-
await
|
|
340
|
+
await user.click(screen.getByRole('button', { name: /danger delete/i }));
|
|
296
341
|
});
|
|
297
342
|
});
|
|
298
343
|
|