Skip to content

Commit

Permalink
(test) Fix failing tests due to importDynamic initialization error (#…
Browse files Browse the repository at this point in the history
…1952)

* (test) Fix failing tests due to importDynamic initialization error

* Bump core tooling and framework

* Add es2022 to lib targets in Form Entry tsconfig
  • Loading branch information
denniskigen authored Aug 6, 2024
1 parent 30e1310 commit 431a673
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 212 deletions.
3 changes: 2 additions & 1 deletion packages/esm-form-entry-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"webpack-env"
],
"lib": [
"dom",
"es2015",
"dom"
"es2022",
],
"skipLibCheck": true,
"useDefineForClassFields": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ const mockUseConfig = jest.mocked(useConfig<ChartConfig>);
const mockUsePatient = jest.mocked(usePatient);
const mockUseVisit = jest.mocked(useVisit);

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
createGlobalStore: jest.fn(),
createUseStore: jest.fn(),
getGlobalStore: jest.fn(),
}));

jest.mock('@openmrs/esm-patient-common-lib', () => {
const originalModule = jest.requireActual('@openmrs/esm-patient-common-lib');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import { screen, render } from '@testing-library/react';
import { useExtensionSlotMeta, useExtensionStore } from '@openmrs/esm-framework';
import {
type AssignedExtension,
type ExtensionSlotState,
useExtensionStore,
useExtensionSlotMeta,
} from '@openmrs/esm-framework';
import { mockPatient } from 'tools';
import ChartReview from './chart-review.component';

const mockUseExtensionStore = useExtensionStore as jest.Mock;
const mockUseExtensionSlotMeta = useExtensionSlotMeta as jest.Mock;
const mockUseExtensionStore = jest.mocked(useExtensionStore);
const mockUseExtensionSlotMeta = jest.mocked(useExtensionSlotMeta);

jest.mock('@openmrs/esm-patient-common-lib', () => {
return {
useNavGroups: jest.fn().mockReturnValue({ navGroups: [] }),
};
});
jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
useExtensionStore: jest.fn(),
useExtensionSlotMeta: jest.fn(),
}));

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand All @@ -39,7 +39,7 @@ function slotMetaFromStore(store, slotName) {
}

describe('ChartReview', () => {
test(`renders a grid-based layout`, () => {
test('renders a grid-based layout', () => {
const mockStore = {
slots: {
'patient-chart-dashboard-slot': {
Expand All @@ -60,14 +60,15 @@ describe('ChartReview', () => {
title: 'Test Results',
},
},
],
] as unknown as AssignedExtension[],
},
'patient-chart-summary-dashboard-slot': {
assignedExtensions: [],
},
},
} as Record<string, ExtensionSlotState>,
};
mockUseExtensionStore.mockReturnValue(mockStore);

mockUseExtensionStore.mockReturnValue(mockStore as unknown as ReturnType<typeof useExtensionStore>);
mockUseExtensionSlotMeta.mockImplementation((slotName) => slotMetaFromStore(mockStore, slotName));

render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ const mockUseVisit = jest.mocked(useVisit);
const mockUseLayoutType = jest.mocked(useLayoutType);
const mockShowModal = jest.mocked(showModal);
const mockGetHistory = jest.mocked(getHistory);
const mockGoBackInHistory = jest.mocked(goBackInHistory);

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
translateFrom: (module, key, defaultValue, options) => defaultValue,
}));

jest.mock('@openmrs/esm-patient-common-lib', () => ({
...jest.requireActual('@openmrs/esm-patient-common-lib'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ const mockUpdateVisit = jest.mocked(updateVisit);
const mockOpenmrsFetch = jest.mocked(openmrsFetch);
const mockUseConfig = jest.mocked(useConfig<ChartConfig>);
const mockUseVisitAttributeType = jest.mocked(useVisitAttributeType);
const mockGetStartedVisitGetter = jest.fn();
const mockUseVisitTypes = jest.mocked(useVisitTypes);
const mockUsePatient = jest.mocked(usePatient);

Expand All @@ -74,19 +73,6 @@ jest.mock('@openmrs/esm-patient-common-lib', () => ({
}),
}));

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
get getStartedVisit() {
return mockGetStartedVisitGetter();
},
restBaseUrl: '/ws/rest/v1',
saveVisit: jest.fn(),
updateVisit: jest.fn(),
toOmrsIsoString: jest.fn(),
toDateObjectStrict: jest.fn(),
usePatient: jest.fn().mockImplementation((patientUuid) => ({ patientUuid, patient: {} })),
}));

jest.mock('../hooks/useVisitAttributeType', () => ({
useVisitAttributeType: jest.fn((attributeUuid) => {
if (attributeUuid === visitAttributes.punctuality.uuid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const mockShowSnackbar = jest.mocked(showSnackbar);
const mockUseVisit = jest.mocked(useVisit);
const mockUseVisitQueueEntry = jest.mocked(useVisitQueueEntry);

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
restBaseUrl: '/ws/rest/v1',
}));

jest.mock('../queue-entry/queue.resource', () => ({
...jest.requireActual('../queue-entry/queue.resource'),
useVisitQueueEntry: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ const mockShowSnackbar = jest.mocked(showSnackbar);
const mockUseVisit = jest.mocked(useVisit);
const mockUpdateVisit = jest.mocked(updateVisit);

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
updateVisit: jest.fn(),
}));

describe('End visit dialog', () => {
beforeEach(() => {
mockUseVisit.mockReturnValue({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ import { useVisit, getConfig } from '@openmrs/esm-framework';
import { waitForLoadingToFinish } from 'tools';
import CurrentVisitSummary from './current-visit-summary.component';

const mockUseVisits = jest.mocked(useVisit);
const mockGetConfig = jest.mocked(getConfig);

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework/mock'),
useVisits: jest.fn(),
getConfig: jest.fn(),
}));
const mockUseVisits = jest.mocked(useVisit);

describe('CurrentVisitSummary', () => {
test('renders an empty state when there is no active visit', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ const mockShowModal = jest.mocked(showModal);
const mockGetConfig = getConfig as jest.Mock;
const mockUserHasAccess = userHasAccess as jest.Mock;

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
getConfig: jest.fn().mockResolvedValue({ htmlFormEntryForms: [] }),
userHasAccess: jest.fn().mockImplementation((privilege, _) => (privilege ? false : true)),
}));

describe('EncounterList', () => {
it('renders an empty state when no encounters are available', async () => {
mockGetConfig.mockResolvedValue({ htmlFormEntryForms: [] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ const mockGetConfig = getConfig as jest.Mock;
const mockOpenmrsFetch = openmrsFetch as jest.Mock;
const mockUseConfig = jest.mocked(useConfig<ChartConfig>);

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
getVisitsForPatient: jest.fn(),
userHasAccess: jest.fn().mockImplementation((privilege, _) => (privilege ? false : true)),
}));

mockUseConfig.mockReturnValue({
...getDefaultsFromConfigSchema(esmPatientChartSchema),
numberOfVisitsToLoad: 5,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import React from 'react';
import dayjs from 'dayjs';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { getDefaultsFromConfigSchema, showSnackbar, useConfig, useSession, useVisit } from '@openmrs/esm-framework';
import {
getDefaultsFromConfigSchema,
showSnackbar,
toDateObjectStrict,
toOmrsIsoString,
useConfig,
useSession,
useVisit,
} from '@openmrs/esm-framework';
import { configSchema } from '../config-schema';
import { type ImmunizationWidgetConfigObject } from '../types/fhir-immunization-domain';
import { immunizationFormSub } from './utils';
Expand All @@ -19,12 +28,8 @@ const mockUseConfig = jest.mocked<() => { immunizationsConfig: ImmunizationWidge
const mockUseSession = jest.mocked(useSession);
const mockUseVisit = jest.mocked(useVisit);
const mockMutate = jest.fn();

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
toOmrsIsoString: jest.fn(),
toDateObjectStrict: jest.fn(),
}));
const mockToOmrsIsoString = jest.mocked(toOmrsIsoString);
const mockToDateObjectStrict = jest.mocked(toDateObjectStrict);

jest.mock('../hooks/useImmunizationsConceptSet', () => ({
useImmunizationsConceptSet: jest.fn(() => ({
Expand Down Expand Up @@ -102,6 +107,15 @@ mockUseVisit.mockReturnValue({
});

describe('Immunizations Form', () => {
const dateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
const isoFormat = 'YYYY-MM-DDTHH:mm:ss.SSSZZ';
const mockVaccinationDate = new Date('2024-01-03T15:44:17');

beforeEach(() => {
mockToOmrsIsoString.mockReturnValue(mockVaccinationDate.toISOString());
mockToDateObjectStrict.mockImplementation((dateString) => dayjs(dateString, isoFormat).toDate());
});

it('should render ImmunizationsForm component', () => {
render(<ImmunizationsForm {...testProps} />);

Expand Down Expand Up @@ -179,14 +193,14 @@ describe('Immunizations Form', () => {

expect(mockSavePatientImmunization).toHaveBeenCalledTimes(1);
expect(mockSavePatientImmunization).toHaveBeenCalledWith(
{
expect.objectContaining({
encounter: { reference: 'Encounter/17f512b4-d264-4113-a6fe-160cb38cb46e', type: 'Encounter' },
expirationDate: null,
id: undefined,
location: { reference: 'Location/b1a8b05e-3542-4037-bbd3-998ee9c40574', type: 'Location' },
lotNumber: '',
manufacturer: { display: 'Pfizer' },
occurrenceDateTime: undefined,
occurrenceDateTime: mockVaccinationDate,
patient: { reference: 'Patient/8673ee4f-e2ab-4077-ba55-4980f408773e', type: 'Patient' },
performer: [
{ actor: { reference: 'Practitioner/b1a8b05e-3542-4037-bbd3-998ee9c4057z', type: 'Practitioner' } },
Expand All @@ -195,7 +209,7 @@ describe('Immunizations Form', () => {
resourceType: 'Immunization',
status: 'completed',
vaccineCode: { coding: [{ code: '782AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', display: 'Hepatitis B vaccination' }] },
},
}),
undefined,
new AbortController(),
);
Expand Down Expand Up @@ -260,10 +274,11 @@ describe('Immunizations Form', () => {
expect.objectContaining({
encounter: { reference: 'Encounter/ce589c9c-2f30-42ec-b289-a153f812ea5e', type: 'Encounter' },
id: '0a6ca2bb-a317-49d8-bd6b-dabb658840d2',
expirationDate: dayjs(new Date('2024-05-19T21:00:00'), isoFormat).toDate(),
location: { reference: 'Location/b1a8b05e-3542-4037-bbd3-998ee9c40574', type: 'Location' },
lotNumber: 'A123456',
manufacturer: { display: 'Merck & Co., Inc.' },
occurrenceDateTime: undefined,
occurrenceDateTime: dayjs(mockVaccinationDate, isoFormat).toDate(),
patient: { reference: 'Patient/8673ee4f-e2ab-4077-ba55-4980f408773e', type: 'Patient' },
performer: [
{ actor: { reference: 'Practitioner/b1a8b05e-3542-4037-bbd3-998ee9c4057z', type: 'Practitioner' } },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Fragment, useEffect, useMemo, useState, useCallback } from 'react';
import React, { useEffect, useMemo, useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import dayjs from 'dayjs';
import {
Button,
ButtonSet,
Expand Down Expand Up @@ -29,15 +30,14 @@ import { zodResolver } from '@hookform/resolvers/zod';
import { z } from 'zod';
import { type DefaultPatientWorkspaceProps, type amPm, convertTime12to24 } from '@openmrs/esm-patient-common-lib';
import { savePatientImmunization } from './immunizations.resource';
import styles from './immunizations-form.scss';
import { useImmunizationsConceptSet } from '../hooks/useImmunizationsConceptSet';
import { mapToFHIRImmunizationResource } from './immunization-mapper';
import { type ConfigObject } from '../config-schema';
import { type ImmunizationFormData } from '../types';
import dayjs from 'dayjs';
import { immunizationFormSub } from './utils';
import { DoseInput } from './components/dose-input.component';
import { useImmunizations } from '../hooks/useImmunizations';
import styles from './immunizations-form.scss';

interface ResponsiveWrapperProps {
children: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { useTestTypes } from './useTestTypes';

jest.mock('swr/immutable');

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
restBaseUrl: '/ws/rest/v1',
}));

const mockOpenrsFetch = openmrsFetch as jest.Mock;
const mockUseConfig = jest.mocked(useConfig<ConfigObject>);
const mockUseSWRImmutable = useSWRImmutable as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { type FetchResponse, showSnackbar } from '@openmrs/esm-framework';
import { type FetchResponse, showSnackbar, useLocations } from '@openmrs/esm-framework';
import { mockCareProgramsResponse, mockEnrolledProgramsResponse, mockLocationsResponse } from '__mocks__';
import { mockPatient } from 'tools';
import {
Expand All @@ -17,7 +17,7 @@ const mockUseEnrollments = jest.mocked(useEnrollments);
const mockCreateProgramEnrollment = jest.mocked(createProgramEnrollment);
const mockUpdateProgramEnrollment = jest.mocked(updateProgramEnrollment);
const mockShowSnackbar = jest.mocked(showSnackbar);

const mockUseLocations = jest.mocked(useLocations);
const mockCloseWorkspace = jest.fn();
const mockCloseWorkspaceWithSavedChanges = jest.fn();
const mockPromptBeforeClosing = jest.fn();
Expand All @@ -30,18 +30,15 @@ const testProps = {
setTitle: jest.fn(),
};

jest.mock('@openmrs/esm-framework', () => ({
...jest.requireActual('@openmrs/esm-framework'),
useLocations: jest.fn().mockImplementation(() => mockLocationsResponse),
}));

jest.mock('./programs.resource', () => ({
createProgramEnrollment: jest.fn(),
updateProgramEnrollment: jest.fn(),
useAvailablePrograms: jest.fn(),
useEnrollments: jest.fn(),
}));

mockUseLocations.mockReturnValue(mockLocationsResponse);

mockUseAvailablePrograms.mockReturnValue({
data: mockCareProgramsResponse,
eligiblePrograms: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './biometrics-chart.scss';

enum ScaleTypes {
LABELS = 'labels',
LABELS_RATIO = 'labels_ratio',
LABELS_RATIO = 'labels-ratio',
LINEAR = 'linear',
LOG = 'log',
TIME = 'time',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styles from './vitals-chart.scss';

enum ScaleTypes {
LABELS = 'labels',
LABELS_RATIO = 'labels_ratio',
LABELS_RATIO = 'labels-ratio',
LINEAR = 'linear',
LOG = 'log',
TIME = 'time',
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-vitals-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"vitalsAndBiometricsRecorded": "Vitals and Biometrics saved",
"vitalsAndBiometricsSaveError": "Error saving vitals and biometrics",
"vitalsHistory": "Vitals history",
"vitalSignDisplayed": "Vital Sign Displayed",
"vitalSignDisplayed": "Vital sign displayed",
"vitalSigns": "Vital signs",
"weight": "Weight"
}
Loading

0 comments on commit 431a673

Please sign in to comment.