From 2686c0ab47edf5110c11da0310a3d3343a45ce47 Mon Sep 17 00:00:00 2001 From: Brandon Istenes Date: Thu, 25 Jul 2024 09:10:00 -0400 Subject: [PATCH] (fix) Fix some tests that were broken by f5d0aec #1247 (#1249) --- __mocks__/index.ts | 2 +- __mocks__/inpatient-request.ts | 28 +++++++++++++++++++ __mocks__/patient.mock.ts | 25 +++++++++++++++-- __mocks__/ward-patient.ts | 17 ----------- .../src/beds/occupied-bed.test.tsx | 12 ++++++-- .../admission-requests-bar.test.tsx | 2 +- 6 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 __mocks__/inpatient-request.ts delete mode 100644 __mocks__/ward-patient.ts diff --git a/__mocks__/index.ts b/__mocks__/index.ts index 765a26c74..b53afc7ef 100644 --- a/__mocks__/index.ts +++ b/__mocks__/index.ts @@ -14,5 +14,5 @@ export * from './queue-rooms.mock'; export * from './search.mock'; export * from './session.mock'; export * from './wards.mock'; -export * from './ward-patient'; +export * from './inpatient-request'; export * from './visits.mock'; diff --git a/__mocks__/inpatient-request.ts b/__mocks__/inpatient-request.ts new file mode 100644 index 000000000..78a639f26 --- /dev/null +++ b/__mocks__/inpatient-request.ts @@ -0,0 +1,28 @@ +import { type Patient, type PersonAddress } from '@openmrs/esm-framework'; +import type { AdmittedPatient, InpatientRequest } from '../packages/esm-ward-app/src/types'; +import { mockLocationInpatientWard } from './locations.mock'; +import { mockPastVisit } from './visits.mock'; +import { mockAddress } from './address.mock'; + +// As received by `useInpatientRequest` +export const mockPatientAlice: Patient = { + uuid: '00000000-0000-0001-0000-000000000000', + identifiers: [], + person: { + uuid: '00000000-0000-0001-0000-00000asdfasd', + display: 'Alice Johnson', + gender: 'F', + age: 24, + birthdate: '2000-01-01T00:00:00.000+0000', + birthtime: null, + dead: false, + deathDate: null, + preferredName: null, + preferredAddress: mockAddress as PersonAddress, + }, +}; + +export const mockInpatientRequest: InpatientRequest = { + patient: mockPatientAlice, + dispositionType: 'ADMIT', +}; diff --git a/__mocks__/patient.mock.ts b/__mocks__/patient.mock.ts index 6147186c9..2ceb69469 100644 --- a/__mocks__/patient.mock.ts +++ b/__mocks__/patient.mock.ts @@ -1,20 +1,33 @@ import { type Patient, type PersonAddress } from '@openmrs/esm-framework'; import { mockAddress } from './address.mock'; +import { type AdmittedPatient } from '../packages/esm-ward-app/src/types'; +import { mockPastVisit } from './visits.mock'; +import { mockLocationInpatientWard } from './locations.mock'; + +/* Patients as returned by `usePatient` and the service queues endpoints */ export const mockPatientAlice: Patient = { uuid: '00000000-0000-0001-0000-000000000000', + display: 'Alice Johnson', identifiers: [], person: { - uuid: '00000000-0000-0001-0000-00000asdfasd', + uuid: '00000000-0001-0000-0000-000000000000', display: 'Alice Johnson', gender: 'F', age: 24, birthdate: '2000-01-01T00:00:00.000+0000', - birthtime: null, + birthdateEstimated: false, dead: false, deathDate: null, + causeOfDeath: null, preferredName: null, preferredAddress: mockAddress as PersonAddress, + names: [null], + addresses: [], + attributes: [], + birthtime: null, + deathdateEstimated: null, + causeOfDeathNonCoded: null, }, }; @@ -42,3 +55,11 @@ export const mockPatientBrian: Patient = { causeOfDeathNonCoded: null, }, }; + +export const mockAdmittedPatient: AdmittedPatient = { + patient: mockPatientAlice, + visit: mockPastVisit.data.results[0], + currentLocation: mockLocationInpatientWard, + timeAtInpatientLocationInMinutes: 100, + timeSinceAdmissionInMinutes: 500, +}; diff --git a/__mocks__/ward-patient.ts b/__mocks__/ward-patient.ts deleted file mode 100644 index 717e36004..000000000 --- a/__mocks__/ward-patient.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { AdmittedPatient, InpatientRequest } from '../packages/esm-ward-app/src/types'; -import { mockLocationInpatientWard } from './locations.mock'; -import { mockPatientAlice } from './patient.mock'; -import { mockPastVisit } from './visits.mock'; - -export const mockInpatientRequest: InpatientRequest = { - patient: mockPatientAlice, - dispositionType: 'ADMIT', -}; - -export const mockAdmittedPatient: AdmittedPatient = { - patient: mockPatientAlice, - visit: mockPastVisit.data.results[0], - currentLocation: mockLocationInpatientWard, - timeAtInpatientLocationInMinutes: 100, - timeSinceAdmissionInMinutes: 500, -}; diff --git a/packages/esm-ward-app/src/beds/occupied-bed.test.tsx b/packages/esm-ward-app/src/beds/occupied-bed.test.tsx index 36fd2db25..4361df963 100644 --- a/packages/esm-ward-app/src/beds/occupied-bed.test.tsx +++ b/packages/esm-ward-app/src/beds/occupied-bed.test.tsx @@ -1,11 +1,11 @@ import { render, screen } from '@testing-library/react'; import OccupiedBed from './occupied-bed.component'; import React from 'react'; -import { mockAdmissionLocation } from '../../../../__mocks__/wards.mock'; import { bedLayoutToBed, filterBeds } from '../ward-view/ward-view.resource'; import { getDefaultsFromConfigSchema, useConfig } from '@openmrs/esm-framework'; import { configSchema, defaultPatientCardElementConfig } from '../config-schema'; -import { mockAdmittedPatient } from '../../../../__mocks__/ward-patient'; +import { mockAdmissionLocation } from '../../../../__mocks__/wards.mock'; +import { mockAdmittedPatient } from '../../../../__mocks__/patient.mock'; const defaultConfig = getDefaultsFromConfigSchema(configSchema); @@ -41,7 +41,13 @@ describe('Occupied bed: ', () => { , diff --git a/packages/esm-ward-app/src/ward-view-header/admission-requests-bar.test.tsx b/packages/esm-ward-app/src/ward-view-header/admission-requests-bar.test.tsx index fc9f7dcca..f095ce901 100644 --- a/packages/esm-ward-app/src/ward-view-header/admission-requests-bar.test.tsx +++ b/packages/esm-ward-app/src/ward-view-header/admission-requests-bar.test.tsx @@ -4,7 +4,7 @@ import { renderWithSwr } from '../../../../tools/test-utils'; import { screen } from '@testing-library/react'; import { launchWorkspace } from '@openmrs/esm-framework'; import AdmissionRequestsBar from './admission-requests-bar.component'; -import { mockInpatientRequest } from '../../../../__mocks__/ward-patient'; +import { mockInpatientRequest } from '../../../../__mocks__/inpatient-request'; import { useInpatientRequest } from '../hooks/useInpatientRequest'; jest.mock('../hooks/useInpatientRequest', () => ({