@openmrs/esm-appointments-app 9.2.1-pre.7279 → 9.2.1-pre.7288
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 +3 -3
- package/dist/1431.js +1 -1
- package/dist/1431.js.map +1 -1
- package/dist/3092.js +1 -1
- package/dist/3092.js.map +1 -1
- package/dist/4889.js +1 -1
- package/dist/4889.js.map +1 -1
- package/dist/525.js +1 -1
- package/dist/525.js.map +1 -1
- package/dist/7026.js +1 -1
- package/dist/7026.js.map +1 -1
- package/dist/openmrs-esm-appointments-app.js.buildmanifest.json +15 -15
- package/dist/routes.json +1 -1
- package/package.json +1 -1
- package/src/appointments/common-components/appointments-table.component.tsx +3 -3
- package/src/form/appointments-form.test.tsx +56 -35
- package/src/form/appointments-form.workspace.tsx +427 -419
- package/src/metrics/metrics-header.component.tsx +2 -2
- package/src/patient-appointments/patient-appointments-action-menu.component.tsx +3 -3
- package/src/patient-appointments/patient-appointments-base.component.tsx +4 -4
- package/src/patient-search/patient-search.component.tsx +2 -2
- package/src/routes.json +14 -3
|
@@ -2,13 +2,14 @@ import React from 'react';
|
|
|
2
2
|
import userEvent from '@testing-library/user-event';
|
|
3
3
|
import { fireEvent, screen } from '@testing-library/react';
|
|
4
4
|
import {
|
|
5
|
-
type FetchResponse,
|
|
6
5
|
getDefaultsFromConfigSchema,
|
|
7
6
|
openmrsFetch,
|
|
8
7
|
showSnackbar,
|
|
9
8
|
useConfig,
|
|
10
9
|
useLocations,
|
|
11
10
|
useSession,
|
|
11
|
+
type FetchResponse,
|
|
12
|
+
type Workspace2DefinitionProps,
|
|
12
13
|
} from '@openmrs/esm-framework';
|
|
13
14
|
import { configSchema, type ConfigObject } from '../config-schema';
|
|
14
15
|
import { mockUseAppointmentServiceData, mockSession, mockLocations, mockProviders } from '__mocks__';
|
|
@@ -16,15 +17,33 @@ import { mockPatient, renderWithSwr, waitForLoadingToFinish } from 'tools';
|
|
|
16
17
|
import { saveAppointment, checkAppointmentConflict } from './appointments-form.resource';
|
|
17
18
|
import { useProviders } from '../hooks/useProviders';
|
|
18
19
|
import type { AppointmentKind, AppointmentStatus } from '../types';
|
|
19
|
-
import AppointmentForm from './appointments-form.workspace';
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
import AppointmentForm, { type AppointmentsFormProps } from './appointments-form.workspace';
|
|
21
|
+
|
|
22
|
+
const renderAppointmentsForm = (props: Partial<Workspace2DefinitionProps<AppointmentsFormProps>> = {}) => {
|
|
23
|
+
const closeWorkspace = props.closeWorkspace || jest.fn();
|
|
24
|
+
const workspaceProps: AppointmentsFormProps = {
|
|
25
|
+
context: props.workspaceProps?.context || 'creating',
|
|
26
|
+
patientUuid: props.workspaceProps?.patientUuid || mockPatient.id,
|
|
27
|
+
appointment: props.workspaceProps?.appointment,
|
|
28
|
+
recurringPattern: props.workspaceProps?.recurringPattern,
|
|
29
|
+
|
|
30
|
+
...props.workspaceProps,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const defaultProps: Workspace2DefinitionProps<AppointmentsFormProps> = {
|
|
34
|
+
closeWorkspace,
|
|
35
|
+
workspaceProps,
|
|
36
|
+
groupProps: props.groupProps || { collapsed: false, name: 'appointmentsFormWorkspaceGroup', overlay: false },
|
|
37
|
+
windowProps: props.windowProps || { group: 'appointmentsFormWorkspaceGroup', name: 'appointments-form-window' },
|
|
38
|
+
workspaceName: props.workspaceName || 'appointments-form-workspace',
|
|
39
|
+
launchChildWorkspace: jest.fn(),
|
|
40
|
+
windowName: 'appointments-form-window',
|
|
41
|
+
|
|
42
|
+
isRootWorkspace: false,
|
|
43
|
+
...props,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return renderWithSwr(<AppointmentForm {...defaultProps} />);
|
|
28
47
|
};
|
|
29
48
|
|
|
30
49
|
const mockOpenmrsFetch = jest.mocked(openmrsFetch);
|
|
@@ -57,7 +76,7 @@ jest.mock('../workload/workload.resource', () => ({
|
|
|
57
76
|
}));
|
|
58
77
|
|
|
59
78
|
describe('AppointmentForm', () => {
|
|
60
|
-
const dateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3}Z
|
|
79
|
+
const dateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
61
80
|
|
|
62
81
|
beforeEach(() => {
|
|
63
82
|
mockUseConfig.mockReturnValue({
|
|
@@ -81,7 +100,7 @@ describe('AppointmentForm', () => {
|
|
|
81
100
|
it('renders the appointments form', async () => {
|
|
82
101
|
mockOpenmrsFetch.mockResolvedValue(mockUseAppointmentServiceData as unknown as FetchResponse);
|
|
83
102
|
|
|
84
|
-
|
|
103
|
+
renderAppointmentsForm();
|
|
85
104
|
|
|
86
105
|
await waitForLoadingToFinish();
|
|
87
106
|
|
|
@@ -104,17 +123,18 @@ describe('AppointmentForm', () => {
|
|
|
104
123
|
|
|
105
124
|
it('closes the workspace when the cancel button is clicked', async () => {
|
|
106
125
|
const user = userEvent.setup();
|
|
126
|
+
const mockCloseWorkspace = jest.fn();
|
|
107
127
|
|
|
108
128
|
mockOpenmrsFetch.mockResolvedValueOnce(mockUseAppointmentServiceData as unknown as FetchResponse);
|
|
109
129
|
|
|
110
|
-
|
|
130
|
+
renderAppointmentsForm({ closeWorkspace: mockCloseWorkspace });
|
|
111
131
|
|
|
112
132
|
await waitForLoadingToFinish();
|
|
113
133
|
|
|
114
134
|
const cancelButton = screen.getByRole('button', { name: /Discard/i });
|
|
115
135
|
await user.click(cancelButton);
|
|
116
136
|
|
|
117
|
-
expect(
|
|
137
|
+
expect(mockCloseWorkspace).toHaveBeenCalledTimes(1);
|
|
118
138
|
});
|
|
119
139
|
|
|
120
140
|
it('renders a success snackbar upon successfully scheduling an appointment', async () => {
|
|
@@ -124,7 +144,7 @@ describe('AppointmentForm', () => {
|
|
|
124
144
|
mockCheckAppointmentConflict.mockResolvedValue({ status: 204, data: {} } as FetchResponse);
|
|
125
145
|
mockSaveAppointment.mockResolvedValue({ status: 200, statusText: 'Ok' } as FetchResponse);
|
|
126
146
|
|
|
127
|
-
|
|
147
|
+
renderAppointmentsForm();
|
|
128
148
|
|
|
129
149
|
await waitForLoadingToFinish();
|
|
130
150
|
|
|
@@ -202,7 +222,7 @@ describe('AppointmentForm', () => {
|
|
|
202
222
|
mockCheckAppointmentConflict.mockResolvedValue({ status: 204, data: {} } as FetchResponse);
|
|
203
223
|
mockSaveAppointment.mockRejectedValue(error);
|
|
204
224
|
|
|
205
|
-
|
|
225
|
+
renderAppointmentsForm();
|
|
206
226
|
|
|
207
227
|
await waitForLoadingToFinish();
|
|
208
228
|
|
|
@@ -274,7 +294,7 @@ describe('AppointmentForm', () => {
|
|
|
274
294
|
});
|
|
275
295
|
mockOpenmrsFetch.mockResolvedValue(mockUseAppointmentServiceData as unknown as FetchResponse);
|
|
276
296
|
|
|
277
|
-
|
|
297
|
+
renderAppointmentsForm();
|
|
278
298
|
|
|
279
299
|
await waitForLoadingToFinish();
|
|
280
300
|
|
|
@@ -292,7 +312,7 @@ describe('AppointmentForm', () => {
|
|
|
292
312
|
|
|
293
313
|
mockOpenmrsFetch.mockResolvedValue(mockUseAppointmentServiceData as unknown as FetchResponse);
|
|
294
314
|
|
|
295
|
-
|
|
315
|
+
renderAppointmentsForm();
|
|
296
316
|
|
|
297
317
|
await waitForLoadingToFinish();
|
|
298
318
|
|
|
@@ -313,7 +333,7 @@ describe('AppointmentForm', () => {
|
|
|
313
333
|
const user = userEvent.setup();
|
|
314
334
|
mockOpenmrsFetch.mockResolvedValue(mockUseAppointmentServiceData as unknown as FetchResponse);
|
|
315
335
|
|
|
316
|
-
|
|
336
|
+
renderAppointmentsForm();
|
|
317
337
|
|
|
318
338
|
await waitForLoadingToFinish();
|
|
319
339
|
|
|
@@ -354,7 +374,7 @@ describe('AppointmentForm', () => {
|
|
|
354
374
|
mockCheckAppointmentConflict.mockResolvedValue({ status: 204, data: {} } as FetchResponse);
|
|
355
375
|
mockSaveAppointment.mockResolvedValue({ status: 200, statusText: 'Ok' } as FetchResponse);
|
|
356
376
|
|
|
357
|
-
|
|
377
|
+
renderAppointmentsForm();
|
|
358
378
|
|
|
359
379
|
await waitForLoadingToFinish();
|
|
360
380
|
|
|
@@ -395,7 +415,7 @@ describe('AppointmentForm', () => {
|
|
|
395
415
|
|
|
396
416
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
397
417
|
|
|
398
|
-
|
|
418
|
+
renderAppointmentsForm();
|
|
399
419
|
|
|
400
420
|
await waitForLoadingToFinish();
|
|
401
421
|
|
|
@@ -425,7 +445,7 @@ describe('AppointmentForm', () => {
|
|
|
425
445
|
|
|
426
446
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
427
447
|
|
|
428
|
-
|
|
448
|
+
renderAppointmentsForm();
|
|
429
449
|
|
|
430
450
|
await waitForLoadingToFinish();
|
|
431
451
|
|
|
@@ -457,7 +477,7 @@ describe('AppointmentForm', () => {
|
|
|
457
477
|
mockCheckAppointmentConflict.mockResolvedValue({ status: 204, data: {} } as FetchResponse);
|
|
458
478
|
mockSaveAppointment.mockResolvedValue({ status: 200, statusText: 'Ok' } as FetchResponse);
|
|
459
479
|
|
|
460
|
-
|
|
480
|
+
renderAppointmentsForm();
|
|
461
481
|
|
|
462
482
|
await waitForLoadingToFinish();
|
|
463
483
|
|
|
@@ -512,7 +532,7 @@ describe('AppointmentForm', () => {
|
|
|
512
532
|
|
|
513
533
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
514
534
|
|
|
515
|
-
|
|
535
|
+
renderAppointmentsForm();
|
|
516
536
|
|
|
517
537
|
await waitForLoadingToFinish();
|
|
518
538
|
|
|
@@ -548,7 +568,7 @@ describe('AppointmentForm', () => {
|
|
|
548
568
|
mockCheckAppointmentConflict.mockResolvedValue({ status: 204, data: {} } as FetchResponse);
|
|
549
569
|
mockSaveAppointment.mockResolvedValue({ status: 200, statusText: 'Ok' } as FetchResponse);
|
|
550
570
|
|
|
551
|
-
|
|
571
|
+
renderAppointmentsForm();
|
|
552
572
|
|
|
553
573
|
await waitForLoadingToFinish();
|
|
554
574
|
|
|
@@ -616,7 +636,7 @@ describe('AppointmentForm', () => {
|
|
|
616
636
|
|
|
617
637
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
618
638
|
|
|
619
|
-
|
|
639
|
+
renderAppointmentsForm();
|
|
620
640
|
|
|
621
641
|
await waitForLoadingToFinish();
|
|
622
642
|
|
|
@@ -649,7 +669,7 @@ describe('AppointmentForm', () => {
|
|
|
649
669
|
data: { SERVICE_UNAVAILABLE: true },
|
|
650
670
|
} as FetchResponse);
|
|
651
671
|
|
|
652
|
-
|
|
672
|
+
renderAppointmentsForm();
|
|
653
673
|
|
|
654
674
|
await waitForLoadingToFinish();
|
|
655
675
|
|
|
@@ -703,7 +723,7 @@ describe('AppointmentForm', () => {
|
|
|
703
723
|
data: { PATIENT_DOUBLE_BOOKING: true },
|
|
704
724
|
} as FetchResponse);
|
|
705
725
|
|
|
706
|
-
|
|
726
|
+
renderAppointmentsForm();
|
|
707
727
|
|
|
708
728
|
await waitForLoadingToFinish();
|
|
709
729
|
|
|
@@ -783,13 +803,13 @@ describe('AppointmentForm', () => {
|
|
|
783
803
|
|
|
784
804
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
785
805
|
|
|
786
|
-
|
|
806
|
+
renderAppointmentsForm({ workspaceProps: { appointment: existingAppointment, context: 'editing' } });
|
|
787
807
|
|
|
788
808
|
await waitForLoadingToFinish();
|
|
789
809
|
|
|
790
810
|
// Check that form fields are pre-populated
|
|
791
811
|
expect(screen.getByDisplayValue('Existing appointment note')).toBeInTheDocument();
|
|
792
|
-
expect(screen.
|
|
812
|
+
expect(screen.getByText('Outpatient')).toBeInTheDocument();
|
|
793
813
|
expect(screen.getByRole('combobox', { name: /select the type of appointment/i })).toHaveValue('Scheduled');
|
|
794
814
|
});
|
|
795
815
|
|
|
@@ -829,7 +849,7 @@ describe('AppointmentForm', () => {
|
|
|
829
849
|
mockCheckAppointmentConflict.mockResolvedValue({ status: 204, data: {} } as FetchResponse);
|
|
830
850
|
mockSaveAppointment.mockResolvedValue({ status: 200, statusText: 'Ok' } as FetchResponse);
|
|
831
851
|
|
|
832
|
-
|
|
852
|
+
renderAppointmentsForm({ workspaceProps: { appointment: existingAppointment, context: 'editing' } });
|
|
833
853
|
|
|
834
854
|
await waitForLoadingToFinish();
|
|
835
855
|
|
|
@@ -866,7 +886,7 @@ describe('AppointmentForm', () => {
|
|
|
866
886
|
|
|
867
887
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
868
888
|
|
|
869
|
-
|
|
889
|
+
renderAppointmentsForm();
|
|
870
890
|
|
|
871
891
|
await waitForLoadingToFinish();
|
|
872
892
|
|
|
@@ -882,10 +902,11 @@ describe('AppointmentForm', () => {
|
|
|
882
902
|
|
|
883
903
|
it('should warn before closing with unsaved changes', async () => {
|
|
884
904
|
const user = userEvent.setup();
|
|
905
|
+
const mockCloseWorkspace = jest.fn();
|
|
885
906
|
|
|
886
907
|
mockOpenmrsFetch.mockResolvedValue({ data: mockUseAppointmentServiceData } as unknown as FetchResponse);
|
|
887
908
|
|
|
888
|
-
|
|
909
|
+
renderAppointmentsForm({ closeWorkspace: mockCloseWorkspace });
|
|
889
910
|
|
|
890
911
|
await waitForLoadingToFinish();
|
|
891
912
|
|
|
@@ -898,8 +919,8 @@ describe('AppointmentForm', () => {
|
|
|
898
919
|
// Try to cancel
|
|
899
920
|
await user.click(cancelButton);
|
|
900
921
|
|
|
901
|
-
// Should call
|
|
902
|
-
expect(
|
|
922
|
+
// Should call closeWorkspace with discardUnsavedChanges
|
|
923
|
+
expect(mockCloseWorkspace).toHaveBeenCalledWith({ discardUnsavedChanges: false });
|
|
903
924
|
});
|
|
904
925
|
});
|
|
905
926
|
});
|