diff --git a/__mocks__/patient-note-config.mock.ts b/__mocks__/patient-note-config.mock.ts new file mode 100644 index 0000000000..c1f41b2bbc --- /dev/null +++ b/__mocks__/patient-note-config.mock.ts @@ -0,0 +1,10 @@ +export const ConfigMock = { + notesConfig: { + clinicianEncounterRole: '240b26f9-dd88-4172-823d-4a8bfeb7841f', + encounterNoteTextConceptUuid: '162169AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + encounterTypeUuid: 'd7151f82-c1f3-4152-a605-2f9ea7414a79', + formConceptUuid: 'c75f120a-04ec-11e3-8780-2b40bef9a44b', + visitDiagnosesConceptUuid: '159947AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + problemListConceptUuid: '1284AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', + }, +}; diff --git a/packages/esm-ward-app/src/ward-workspace/ward-patient-notes/form/notes-form.test.tsx b/packages/esm-ward-app/src/ward-workspace/ward-patient-notes/form/notes-form.test.tsx index cdeab05de1..e7bf9ae077 100644 --- a/packages/esm-ward-app/src/ward-workspace/ward-patient-notes/form/notes-form.test.tsx +++ b/packages/esm-ward-app/src/ward-workspace/ward-patient-notes/form/notes-form.test.tsx @@ -2,26 +2,22 @@ import React from 'react'; import userEvent from '@testing-library/user-event'; import { render, screen } from '@testing-library/react'; import { showSnackbar, useConfig, useSession } from '@openmrs/esm-framework'; -import { saveVisitNote } from '../visit-notes.resource'; -import { - ConfigMock, - mockFetchLocationByUuidResponse, - mockFetchProviderByUuidResponse, - mockSessionDataResponse, -} from '__mocks__'; -import { mockPatient } from 'tools'; -import WardPatientNotesForm from './notes-form.component'; +import { savePatientNote } from './notes-form.resource'; +import PatientNotesForm from './notes-form.component'; +import { mockPatient, mockSession } from '__mocks__'; +import { ConfigMock } from '../../../../../../__mocks__/patient-note-config.mock'; const testProps = { - patientUuid: mockPatient.id, + patientUuid: mockPatient.uuid, closeWorkspace: jest.fn(), closeWorkspaceWithSavedChanges: jest.fn(), promptBeforeClosing: jest.fn(), setTitle: jest.fn(), onWorkspaceClose: jest.fn(), + setOnCloseCallback: jest.fn(), }; -const mockSaveVisitNote = saveVisitNote as jest.Mock; +const mockSavePatientNote = savePatientNote as jest.Mock; const mockedShowSnackbar = jest.mocked(showSnackbar); const mockUseConfig = useConfig as jest.Mock; const mockUseSession = useSession as jest.Mock; @@ -34,25 +30,12 @@ jest.mock('@openmrs/esm-framework', () => { createErrorHandler: jest.fn(), showSnackbar: jest.fn(), useConfig: jest.fn().mockReturnValue(() => ConfigMock), - useSession: jest.fn().mockReturnValue(() => mockSessionDataResponse), + useSession: jest.fn().mockReturnValue(() => mockSession), }; }); -jest.mock('../visit-notes.resource', () => ({ - fetchDiagnosisConceptsByName: jest.fn(), - useLocationUuid: jest.fn().mockImplementation(() => ({ - data: mockFetchLocationByUuidResponse.data.uuid, - })), - useProviderUuid: jest.fn().mockImplementation(() => ({ - data: mockFetchProviderByUuidResponse.data.uuid, - })), - saveVisitNote: jest.fn(), - useVisitNotes: jest.fn().mockImplementation(() => ({ - mutateVisitNotes: jest.fn(), - })), - useInfiniteVisits: jest.fn().mockImplementation(() => ({ - mutateVisits: jest.fn(), - })), +jest.mock('./notes-form.resource', () => ({ + savePatientNote: jest.fn(), })); test('renders the visit notes form with all the relevant fields and values', () => { @@ -66,11 +49,11 @@ test('renders a success snackbar upon successfully recording a visit note', asyn const successPayload = { encounterProviders: expect.arrayContaining([ { - encounterRole: ConfigMock.visitNoteConfig.clinicianEncounterRole, + encounterRole: ConfigMock.notesConfig.clinicianEncounterRole, provider: undefined, }, ]), - encounterType: ConfigMock.visitNoteConfig.encounterTypeUuid, + encounterType: ConfigMock.notesConfig.encounterTypeUuid, location: undefined, obs: expect.arrayContaining([ { @@ -78,10 +61,10 @@ test('renders a success snackbar upon successfully recording a visit note', asyn value: 'Sample clinical note', }, ]), - patient: mockPatient.id, + patient: mockPatient.uuid, }; - mockSaveVisitNote.mockResolvedValueOnce({ status: 201, body: 'Condition created' }); + mockSavePatientNote.mockResolvedValueOnce({ status: 201, body: 'Condition created' }); renderWardPatientNotesForm(); @@ -93,8 +76,8 @@ test('renders a success snackbar upon successfully recording a visit note', asyn const submitButton = screen.getByRole('button', { name: /Save/i }); await userEvent.click(submitButton); - expect(mockSaveVisitNote).toHaveBeenCalledTimes(1); - expect(mockSaveVisitNote).toHaveBeenCalledWith(new AbortController(), expect.objectContaining(successPayload)); + expect(mockSavePatientNote).toHaveBeenCalledTimes(1); + expect(mockSavePatientNote).toHaveBeenCalledWith(new AbortController(), expect.objectContaining(successPayload)); }); test('renders an error snackbar if there was a problem recording a visit note', async () => { @@ -106,7 +89,7 @@ test('renders an error snackbar if there was a problem recording a visit note', }, }; - mockSaveVisitNote.mockRejectedValueOnce(error); + mockSavePatientNote.mockRejectedValueOnce(error); renderWardPatientNotesForm(); const note = screen.getByRole('textbox', { name: /Write your notes/i }); @@ -122,12 +105,12 @@ test('renders an error snackbar if there was a problem recording a visit note', isLowContrast: false, kind: 'error', subtitle: 'Internal Server Error', - title: 'Error saving visit note', + title: 'Error saving patient note', }); }); function renderWardPatientNotesForm() { mockUseConfig.mockReturnValue(ConfigMock); - mockUseSession.mockReturnValue(mockSessionDataResponse); - render(); + mockUseSession.mockReturnValue(mockSession); + render(); }