Skip to content

Commit

Permalink
changed the mock implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-AI committed Jul 13, 2023
1 parent df51065 commit a42e99a
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import EditPatientDetailsButton from './edit-patient-details-button.component';
import * as esmFramework from '@openmrs/esm-framework';
import { navigate } from '@openmrs/esm-framework';

describe('EditPatientDetailsButton', () => {
it('should navigate to the edit page when clicked', () => {
const navigateMock = jest.fn();
jest.spyOn(esmFramework, 'navigate').mockImplementation(navigateMock);
jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
...originalModule,
};
});

const patientUuid = '12345';
render(<EditPatientDetailsButton patientUuid={patientUuid} />);

const button = screen.getByRole('menuitem');
fireEvent.click(button);

expect(navigateMock).toHaveBeenCalledWith({ to: expect.stringContaining(`/patient/${patientUuid}/edit`) });
expect(navigate).toHaveBeenCalledWith({ to: expect.stringContaining(`/patient/${patientUuid}/edit`) });
});

it('should call the onTransition function when provided', () => {
Expand Down

0 comments on commit a42e99a

Please sign in to comment.