@openmrs/esm-patient-vitals-app 11.3.1-pre.9452 → 11.3.1-pre.9455

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.
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { screen, render } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { type FetchResponse, showSnackbar, useConfig, getDefaultsFromConfigSchema } from '@openmrs/esm-framework';
5
+ import { type PatientWorkspace2DefinitionProps } from '@openmrs/esm-patient-common-lib';
5
6
  import { createOrUpdateVitalsAndBiometrics, useEncounterVitalsAndBiometrics } from '../common';
6
7
  import { type ConfigObject, configSchema } from '../config-schema';
7
8
  import { mockConceptUnits, mockVitalsConceptMetadata, mockVitalsConfig } from '__mocks__';
@@ -17,16 +18,22 @@ const weightValue = 62;
17
18
  const systolicBloodPressureValue = 120;
18
19
  const temperatureValue = 37;
19
20
 
20
- const testProps: VitalsAndBiometricsFormProps = {
21
- closeWorkspace: () => {},
22
- closeWorkspaceWithSavedChanges: jest.fn(),
23
- patientUuid: mockPatient.id,
24
- patient: mockPatient,
25
- promptBeforeClosing: () => {},
26
- formContext: 'creating' as 'creating' | 'editing',
27
- setTitle: jest.fn(),
28
- visitContext: null,
29
- mutateVisitContext: jest.fn(),
21
+ const defaultProps: PatientWorkspace2DefinitionProps<VitalsAndBiometricsFormProps, {}> = {
22
+ workspaceProps: {
23
+ formContext: 'creating',
24
+ },
25
+ windowProps: {},
26
+ groupProps: {
27
+ patientUuid: mockPatient.id,
28
+ patient: mockPatient,
29
+ visitContext: null,
30
+ mutateVisitContext: null,
31
+ },
32
+ workspaceName: '',
33
+ launchChildWorkspace: jest.fn(),
34
+ closeWorkspace: jest.fn(),
35
+ windowName: '',
36
+ isRootWorkspace: false,
30
37
  };
31
38
 
32
39
  const mockShowSnackbar = jest.mocked(showSnackbar);
@@ -147,10 +154,10 @@ function setupMockUseEncounterVitalsAndBiometrics() {
147
154
 
148
155
  describe('VitalsBiometricsForm', () => {
149
156
  it('renders the vitals and biometrics form', async () => {
150
- render(<VitalsAndBiometricsForm {...testProps} />);
157
+ renderVitalsAndBiometricsForm();
151
158
 
152
- expect(screen.getByText(/vitals/i)).toBeInTheDocument();
153
- expect(screen.getByText(/biometrics/i)).toBeInTheDocument();
159
+ expect(screen.getByText(/record vitals$/i)).toBeInTheDocument();
160
+ expect(screen.getByText(/record biometrics/i)).toBeInTheDocument();
154
161
  expect(screen.getByText(/blood pressure/i)).toBeInTheDocument();
155
162
  expect(screen.getByRole('spinbutton', { name: /systolic/i })).toBeInTheDocument();
156
163
  expect(screen.getByRole('spinbutton', { name: /diastolic/i })).toBeInTheDocument();
@@ -180,7 +187,7 @@ describe('VitalsBiometricsForm', () => {
180
187
  it("computes a patient's BMI from the given height and weight values", async () => {
181
188
  const user = userEvent.setup();
182
189
 
183
- render(<VitalsAndBiometricsForm {...testProps} />);
190
+ renderVitalsAndBiometricsForm();
184
191
 
185
192
  const heightInput = screen.getByRole('spinbutton', { name: /height/i });
186
193
  const weightInput = screen.getByRole('spinbutton', { name: /weight/i });
@@ -205,7 +212,7 @@ describe('VitalsBiometricsForm', () => {
205
212
  response as ReturnType<typeof createOrUpdateVitalsAndBiometrics>,
206
213
  );
207
214
 
208
- render(<VitalsAndBiometricsForm {...testProps} />);
215
+ renderVitalsAndBiometricsForm();
209
216
 
210
217
  const heightInput = screen.getByRole('spinbutton', { name: /height/i });
211
218
  const weightInput = screen.getByRole('spinbutton', { name: /weight/i });
@@ -274,7 +281,7 @@ describe('VitalsBiometricsForm', () => {
274
281
 
275
282
  it('correctly initializes the form with existing vitals and biometrics data while in edit mode', async () => {
276
283
  setupMockUseEncounterVitalsAndBiometrics();
277
- render(<VitalsAndBiometricsForm {...testProps} formContext="editing" editEncounterUuid="encounter-uuid" />);
284
+ renderVitalsAndBiometricsForm('editing', 'encounter-uuid');
278
285
 
279
286
  expect(screen.getByRole('spinbutton', { name: /height/i })).toHaveValue(170);
280
287
  expect(screen.getByRole('spinbutton', { name: /weight/i })).toHaveValue(65);
@@ -301,7 +308,7 @@ describe('VitalsBiometricsForm', () => {
301
308
  response as ReturnType<typeof createOrUpdateVitalsAndBiometrics>,
302
309
  );
303
310
 
304
- render(<VitalsAndBiometricsForm {...testProps} formContext="editing" editEncounterUuid="encounter-uuid" />);
311
+ renderVitalsAndBiometricsForm('editing', 'encounter-uuid');
305
312
 
306
313
  const weightInput = screen.getByRole('spinbutton', { name: /weight/i });
307
314
  const systolicInput = screen.getByRole('spinbutton', { name: /systolic/i });
@@ -370,7 +377,7 @@ describe('VitalsBiometricsForm', () => {
370
377
 
371
378
  mockCreateOrUpdateVitalsAndBiometrics.mockRejectedValueOnce(error);
372
379
 
373
- render(<VitalsAndBiometricsForm {...testProps} />);
380
+ renderVitalsAndBiometricsForm();
374
381
 
375
382
  const heightInput = screen.getByRole('spinbutton', { name: /height/i });
376
383
  const weightInput = screen.getByRole('spinbutton', { name: /weight/i });
@@ -403,3 +410,15 @@ describe('VitalsBiometricsForm', () => {
403
410
  });
404
411
  });
405
412
  });
413
+
414
+ function renderVitalsAndBiometricsForm(formContext?: 'creating' | 'editing', editEncounterUuid?: string) {
415
+ const props: PatientWorkspace2DefinitionProps<VitalsAndBiometricsFormProps, {}> = {
416
+ ...defaultProps,
417
+ workspaceProps: {
418
+ ...defaultProps.workspaceProps,
419
+ formContext: formContext ?? defaultProps.workspaceProps.formContext,
420
+ editEncounterUuid: editEncounterUuid ?? defaultProps.workspaceProps.editEncounterUuid,
421
+ },
422
+ };
423
+ return render(<VitalsAndBiometricsForm {...props} />);
424
+ }