Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(test) O3-2227 & O3-2228: Add Test for display-photo.component.tsx and edit-patient-details-button.component #751

Merged
merged 18 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import DisplayPatientPhoto from './display-photo.component';
import { mockPatient } from '../../../../__mocks__/appointments.mock';

jest.mock('../patient-registration/patient-registration.resource', () => ({
usePatientPhoto: jest.fn().mockReturnValue({ data: { imageSrc: 'test-image-src' } }),
Piumal1999 marked this conversation as resolved.
Show resolved Hide resolved
}));

jest.mock('geopattern', () => ({
generate: jest.fn().mockReturnValue({
toDataUri: jest.fn().mockReturnValue('test-pattern-url'),
Piumal1999 marked this conversation as resolved.
Show resolved Hide resolved
}),
}));

const patientUuid = mockPatient.uuid;
const patientName = mockPatient.name;

describe('DisplayPatientPhoto Component', () => {
it('should render the component with the patient photo and size should not be small', () => {
render(<DisplayPatientPhoto patientUuid={patientUuid} patientName={patientName} />);

const avatarImage = screen.getByTitle(`${patientName}`);

expect(avatarImage).toBeInTheDocument();
expect(avatarImage).toHaveAttribute('style', expect.stringContaining('width: 80px; height: 80px'));
});

it('should render the component with the patient photo and size should be small i.e. 48px', () => {
render(<DisplayPatientPhoto patientUuid={patientUuid} patientName={patientName} size="small" />);

const avatarImage = screen.getByTitle(`${patientName}`);

expect(avatarImage).toBeInTheDocument();
expect(avatarImage).toHaveAttribute('style', expect.stringContaining('width: 48px; height: 48px'));
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import { render, fireEvent, screen } from '@testing-library/react';
import EditPatientDetailsButton from './edit-patient-details-button.component';
import { navigate } from '@openmrs/esm-framework';
import { mockPatient } from '../../../../__mocks__/appointments.mock';

describe('EditPatientDetailsButton', () => {
const patientUuid = mockPatient.uuid;
it('should navigate to the edit page when clicked', () => {
const mockNavigate = navigate as jest.Mock;

jest.mock('@openmrs/esm-framework', () => {
const originalModule = jest.requireActual('@openmrs/esm-framework');
return {
...originalModule,
};
});

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

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

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

it('should call the onTransition function when provided', () => {
const onTransitionMock = jest.fn();
render(<EditPatientDetailsButton patientUuid={patientUuid} onTransition={onTransitionMock} />);

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

expect(onTransitionMock).toHaveBeenCalled();
});
});
Loading