Skip to content

Commit

Permalink
(fix) Fix some tests that were broken by f5d0aec #1247 (#1249)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandones authored Jul 25, 2024
1 parent 80ef84c commit 2686c0a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 24 deletions.
2 changes: 1 addition & 1 deletion __mocks__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
28 changes: 28 additions & 0 deletions __mocks__/inpatient-request.ts
Original file line number Diff line number Diff line change
@@ -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',
};
25 changes: 23 additions & 2 deletions __mocks__/patient.mock.ts
Original file line number Diff line number Diff line change
@@ -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,
},
};

Expand Down Expand Up @@ -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,
};
17 changes: 0 additions & 17 deletions __mocks__/ward-patient.ts

This file was deleted.

12 changes: 9 additions & 3 deletions packages/esm-ward-app/src/beds/occupied-bed.test.tsx
Original file line number Diff line number Diff line change
@@ -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);

Expand Down Expand Up @@ -41,7 +41,13 @@ describe('Occupied bed: ', () => {
<OccupiedBed
wardPatients={[
{ ...mockAdmittedPatient, admitted: true },
{ ...mockAdmittedPatient, admitted: true },
{
...{
...mockAdmittedPatient,
patient: { ...mockAdmittedPatient.patient, uuid: 'other-uuid' },
admitted: true,
},
},
]}
bed={mockBed}
/>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down

0 comments on commit 2686c0a

Please sign in to comment.