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 8 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,36 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import DisplayPatientPhoto from './display-photo.component';

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', () => ({
Piumal1999 marked this conversation as resolved.
Show resolved Hide resolved
generate: jest.fn().mockReturnValue({
toDataUri: jest.fn().mockReturnValue('test-pattern-url'),
Piumal1999 marked this conversation as resolved.
Show resolved Hide resolved
}),
}));

describe('DisplayPatientPhoto Component', () => {
it('should render the component with the patient photo and size should not be small', () => {
const patientUuid = '12345';
const patientName = 'John Doe';
Piumal1999 marked this conversation as resolved.
Show resolved Hide resolved
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', () => {
const patientUuid = '12345';
const patientName = 'John Doe';
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,35 @@
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';

describe('EditPatientDetailsButton', () => {
it('should navigate to the edit page when clicked', () => {
const mockNavigate = navigate as jest.Mock;
jest.mock('@openmrs/esm-framework', () => {
Piumal1999 marked this conversation as resolved.
Show resolved Hide resolved
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(mockNavigate).toHaveBeenCalledWith({ to: expect.stringContaining(`/patient/${patientUuid}/edit`) });
});

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

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

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