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) Remove unnecessary partial mocks; improve typing in tests #1933

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
45 changes: 36 additions & 9 deletions __mocks__/patient-flags.mock.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
export const mockPatientFlags = [
{
uuid: '8ca6c08f-66d9-4a18-a233-4f658b1755bf',
flag: { display: 'Needs Follow Up' },
auditInfo: { dateCreated: '2024-03-01T00:00:00.000Z' },
flag: { display: 'Needs Follow Up', uuid: '98ca6c08f-66d9-4a18-a233-4f658b1755bf' },
message: 'Patient needs to be followed up',
tags: [{ display: 'flag tag - risk' }, { display: 'flag type - Social' }],
patient: {
uuid: '8ca6c08f-66d9-4a18-a233-4f658b1755bf',
display: 'John Doe',
},
tags: [
{ display: 'flag tag - risk', uuid: 'some-uuid' },
{ display: 'flag type - Social', uuid: 'some-other-uuid' },
],
uuid: '8ca6c08f-66d9-4a18-a233-4f658b1755bf',
voided: false,
},
{
uuid: '5fs6c08f-66d9-4a18-a233-5f658b1755bf',
flag: { display: 'Unknown Diagnosis' },
auditInfo: { dateCreated: '2024-03-01T00:00:00.000Z' },
flag: { display: 'Unknown Diagnosis', uuid: 'a4a4c08f-66d9-4a18-a233-5f658b1755bf' },
message: 'Diagnosis for the patient is unknown',
tags: [{ display: 'flag tag - info' }, { display: 'flag type - Clinical' }],
patient: {
uuid: '8ca6c08f-66d9-4a18-a233-4f658b1755bf',
display: 'John Doe',
},
tags: [
{ display: 'flag tag - info', uuid: 'another-uuid' },
{ display: 'flag type - Clinical', uuid: 'yet-another-uuid' },
],
uuid: '5fs6c08f-66d9-4a18-a233-5f658b1755bf',
voided: false,
},
{
uuid: '4da4c08f-66d9-4a18-a233-5f658b1755bf',
flag: { display: 'Future Appointment' },
auditInfo: { dateCreated: '2024-03-01T00:00:00.000Z' },
flag: { display: 'Future Appointment', uuid: 'cc6c08f-66d9-4a18-a233-5f658b1755bf' },
message: 'Patient has a future appointment scheduled',
tags: [{ display: 'flag tag - info' }, { display: 'flag type - Clinical' }],
patient: {
uuid: '8ca6c08f-66d9-4a18-a233-4f658b1755bf',
display: 'John Doe',
},
tags: [
{ display: 'flag tag - info', uuid: 'one-more-uuid' },
{ display: 'flag type - Clinical', uuid: 'yet-one-more-uuid' },
],
uuid: '4da4c08f-66d9-4a18-a233-5f658b1755bf',
voided: false,
},
];
10 changes: 10 additions & 0 deletions __mocks__/session.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const mockSessionDataResponse = {
address13: null,
address14: null,
address15: null,
links: [],
},
user: {
uuid: '45ce6c2e-dd5a-11e6-9d9c-0242ac150002',
Expand All @@ -77,31 +78,40 @@ export const mockSessionDataResponse = {
{
uuid: '62431c71-5244-11ea-a771-0242ac160002',
display: 'Manage Appointment Services',
links: [],
},
{
uuid: '6206682c-5244-11ea-a771-0242ac160002',
display: 'Manage Appointments',
links: [],
},
{
uuid: '6280ff58-5244-11ea-a771-0242ac160002',
display: 'Manage Appointment Specialities',
links: [],
},
],
roles: [
{
uuid: '8d94f852-c2cc-11de-8d13-0010c6dffd0f',
display: 'System Developer',
links: [],
},
{
uuid: '62c195c5-5244-11ea-a771-0242ac160002',
display: 'Bahmni Role',
links: [],
},
{
uuid: '8d94f280-c2cc-11de-8d13-0010c6dffd0f',
display: 'Provider',
links: [],
},
],
retired: false,
locale: 'en_GB',
allowedLocales: ['en_GB'],
},
sessionId: 'D4F7D4D4-6A6D-4D4D-8D4D-4D4D4D4D4D4D',
},
};
2 changes: 1 addition & 1 deletion __mocks__/visits.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const mockCurrentVisit = {
display: 'Facility Visit',
},
attributes: [],
startDatetime: new Date('2021-03-16T08:16:00.000+0000'),
startDatetime: new Date('2021-03-16T08:16:00.000+0000').toISOString(),
stopDatetime: null,
location: {
uuid: '6351fcf4-e311-4a19-90f9-35667d99a8af',
Expand Down
10 changes: 7 additions & 3 deletions __mocks__/vitals-and-biometrics.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5985,12 +5985,12 @@ export const mockFhirVitalsResponse = {
};

export const mockBiometricsConfig = {
biometrics: { bmiUnit: 'kg / m²' },
concepts: { heightUuid: '5090AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', weightUuid: '5089AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' },
biometrics: { bmiUnit: 'kg / m²' },
};

export const mockVitalsConfig = {
biometrics: { bmiUnit: 'kg / m²' },
biometrics: { bmiUnit: 'kg / m²', heightUnit: 'm', weightUnit: 'kg' },
concepts: {
diastolicBloodPressureUuid: '5086AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
generalPatientNoteUuid: '165095AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
Expand All @@ -6005,8 +6005,12 @@ export const mockVitalsConfig = {
},
vitals: {
encounterTypeUuid: '67a71486-1a54-468f-ac3e-7091a9a79584',
formUuid: 'a000cb34-9ec1-4344-a1c8-f692232f6edd',
formUuid: '9f26aad4-244a-46ca-be49-1196df1a8c9a',
useFormEngine: false,
logo: null,
showPrintButton: false,
formName: 'Vitals',
useMuacColors: false,
},
};

Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path');

module.exports = {
clearMocks: true,
transform: {
'^.+\\.(j|t)sx?$': '@swc/jest',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import userEvent from '@testing-library/user-event';
import { launchPatientWorkspace } from '@openmrs/esm-patient-common-lib';
import FormError from './form-error.component';

const mocklaunchPatientWorkspace = launchPatientWorkspace as jest.Mock;
const mocklaunchPatientWorkspace = jest.mocked(launchPatientWorkspace);

jest.mock('@openmrs/esm-patient-common-lib', () => ({
launchPatientWorkspace: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react';
import FormRenderer from './form-renderer.component';
import useFormSchema from '../hooks/useFormSchema';

const mockUseFormSchema = useFormSchema as jest.Mock;
const mockUseFormSchema = jest.mocked(useFormSchema);

jest.mock('@openmrs/openmrs-form-engine-lib', () => ({
FormEngine: jest
Expand Down Expand Up @@ -43,7 +43,9 @@ describe('FormRenderer', () => {
});

test('renders a form preview from the engine when a schema is available', async () => {
mockUseFormSchema.mockReturnValue({ schema: { id: 'test-schema' }, isLoading: false, error: null });
mockUseFormSchema.mockReturnValue({ schema: { uuid: 'test-schema' }, isLoading: false, error: null } as ReturnType<
typeof useFormSchema
>);

render(<FormRenderer {...defaultProps} />);
await expect(screen.getByText(/form engine lib/i)).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const AllergiesDetailedSummary: React.FC<AllergiesDetailedSummaryProps> = ({ pat
const { t } = useTranslation();
const displayText = t('allergyIntolerances', 'allergy intolerances');
const headerTitle = t('allergies', 'Allergies');
const { allergies, isError, isLoading, isValidating } = useAllergies(patient.id);
const { allergies, error, isLoading, isValidating } = useAllergies(patient.id);
const layout = useLayoutType();
const isTablet = layout === 'tablet';
const isDesktop = layout === 'small-desktop' || layout === 'large-desktop';
Expand Down Expand Up @@ -61,7 +61,7 @@ const AllergiesDetailedSummary: React.FC<AllergiesDetailedSummaryProps> = ({ pat
}, [allergies]);

if (isLoading) return <DataTableSkeleton role="progressbar" compact={isDesktop} zebra />;
if (isError) return <ErrorState error={isError} headerTitle={headerTitle} />;
if (error) return <ErrorState error={error} headerTitle={headerTitle} />;
if (allergies?.length) {
return (
<div className={styles.widgetCard}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const testProps = {
const mockOpenmrsFetch = openmrsFetch as jest.Mock;
mockOpenmrsFetch.mockImplementation(jest.fn());

describe('AllergiesDetailedSummary: ', () => {
describe('AllergiesDetailedSummary', () => {
it('renders an empty state view if allergy data is unavailable', async () => {
mockOpenmrsFetch.mockReturnValueOnce({ data: { entry: [] } });
renderAllergiesDetailedSummary();
Expand Down
Loading