Skip to content

Commit

Permalink
MF-764 : Fix Error on loading form widget
Browse files Browse the repository at this point in the history
  • Loading branch information
donaldkibet committed Sep 2, 2021
1 parent 1553450 commit 1c26f83
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 581 deletions.
45 changes: 24 additions & 21 deletions __mocks__/forms.mock.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
import { Form } from "../packages/esm-patient-forms-app/src/types";
import { Form } from '../packages/esm-patient-forms-app/src/types';

export const mockForms: Array<Form> = [
{
encounterTypeName: "Vitals",
encounterTypeUuid: "67a71486-1a54-468f-ac3e-7091a9a79584",
name: "Biometrics",
encounterTypeName: 'Vitals',
encounterTypeUuid: '67a71486-1a54-468f-ac3e-7091a9a79584',
name: 'Biometrics',
published: false,
retired: false,
uuid: "1dfe36b9-7a85-429a-b71d-008a6afca574",
uuid: '1dfe36b9-7a85-429a-b71d-008a6afca574',
lastCompleted: null,
},
{
encounterTypeName: "Admission",
encounterTypeUuid: "e22e39fd-7db2-45e7-80f1-60fa0d5a4378",
name: "Admission (Simple)",
encounterTypeName: 'Admission',
encounterTypeUuid: 'e22e39fd-7db2-45e7-80f1-60fa0d5a4378',
name: 'Admission (Simple)',
published: false,
retired: false,
uuid: "d2c7532c-fb01-11e2-8ff2-fd54ab5fdb2a",
uuid: 'd2c7532c-fb01-11e2-8ff2-fd54ab5fdb2a',
lastCompleted: null,
},
{
encounterTypeName: "Vitals",
encounterTypeUuid: "67a71486-1a54-468f-ac3e-7091a9a79584",
name: "POC Vitals v1.0",
encounterTypeName: 'Vitals',
encounterTypeUuid: '67a71486-1a54-468f-ac3e-7091a9a79584',
name: 'POC Vitals v1.0',
published: true,
retired: false,
uuid: "c51b0cbe-32d8-4ea5-81d2-8f3ade30c2de",
uuid: 'c51b0cbe-32d8-4ea5-81d2-8f3ade30c2de',
lastCompleted: null,
},
];

export const mockPatientEncounters = [
{
uuid: "5859f098-45d6-4c4e-9447-53dd4032d7d7",
encounterDateTime: "2021-03-16T08:17:34.000Z",
encounterTypeUuid: "67a71486-1a54-468f-ac3e-7091a9a79584",
encounterTypeName: "Vitals",
uuid: '5859f098-45d6-4c4e-9447-53dd4032d7d7',
encounterDateTime: '2021-03-16T08:17:34.000Z',
encounterTypeUuid: '67a71486-1a54-468f-ac3e-7091a9a79584',
encounterTypeName: 'Vitals',
form: {
uuid: "c51b0cbe-32d8-4ea5-81d2-8f3ade30c2de",
name: "POC Vitals v1.0",
uuid: 'c51b0cbe-32d8-4ea5-81d2-8f3ade30c2de',
name: 'POC Vitals v1.0',
published: true,
retired: false,
encounterTypeUuid: "67a71486-1a54-468f-ac3e-7091a9a79584",
encounterTypeName: "Vitals",
encounterTypeUuid: '67a71486-1a54-468f-ac3e-7091a9a79584',
encounterTypeName: 'Vitals',
checked: true,
},
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"babel-eslint": "^10.1.0",
"babel-jest": "^26.3.0",
"concurrently": "^5.3.0",
"d3-selection": "^3.0.0",
"dayjs": "^1.8.36",
"eslint": "^7.20.0",
"eslint-config-prettier": "^8.2.0",
Expand All @@ -55,6 +56,7 @@
"jest": "^26.4.2",
"jest-cli": "^26.4.2",
"lerna": "^3.20.2",
"lodash": "^4.17.21",
"openmrs": "next",
"prettier": "^2.2.1",
"pretty-quick": "^2.0.2",
Expand All @@ -67,8 +69,7 @@
"sass-loader": "^10.1.0",
"typescript": "^4.0.3",
"webpack": "^5.36.2",
"webpack-cli": "^4.7.0",
"d3-selection": "^3.0.0"
"webpack-cli": "^4.7.0"
},
"dependencies": {}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,61 @@ import React from 'react';
import FormView from './form-view.component';
import userEvent from '@testing-library/user-event';
import { screen, render } from '@testing-library/react';
import { getStartedVisit } from '@openmrs/esm-framework';
import { mockForms } from '../../../../__mocks__/forms.mock';
import { mockPatient } from '../../../../__mocks__/patient.mock';
import { mockCurrentVisit } from '../../../../__mocks__/visits.mock';
import { usePagination, useVisit } from '@openmrs/esm-framework';

const mockUseVisit = useVisit as jest.Mock;
const mockUsePagination = usePagination as jest.Mock;
const mockLaunchFormEntry = jest.fn();

window.CustomEvent = mockLaunchFormEntry;

jest.mock('lodash-es/debounce', () => jest.fn((fn) => fn));

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

describe('<FormViewComponent/>', () => {
beforeEach(() => {
getStartedVisit.next(mockCurrentVisit);
mockUseVisit.mockReturnValue({
currentVisit: mockCurrentVisit.visitData,
error: null,
});
mockUsePagination.mockReturnValue({
results: mockForms.slice(0, 3),
goTo: () => {},
currentPage: 1,
});
render(
<FormView
forms={mockForms}
patientUuid={mockPatient.id}
patient={mockPatient}
encounterUuid={'5859f098-45d6-4c4e-9447-53dd4032d7d7'}
pageUrl={'/seeAll'}
urlLabel=""
pageSize={5}
/>,
);
});

afterEach(() => {
mockUseVisit.mockReset();
mockUsePagination.mockReset();
});

it('should be able to search for a form', async () => {
expect(screen.getByText(/Biometrics/i)).toBeInTheDocument();
expect(screen.getByText(/Admission/i)).toBeInTheDocument();
expect(screen.getByText(/POC Vitals/i)).toBeInTheDocument();
const searchInput = screen.getByPlaceholderText(/Search for a form/);
userEvent.type(searchInput, 'POC');
expect(await screen.getByText(/1 match found/)).toBeInTheDocument();
userEvent.type(searchInput, 'I');
expect(await screen.findByText(/3 match found/)).toBeInTheDocument();
});

it('should display not found message when searched form is not found', () => {
Expand Down
Loading

0 comments on commit 1c26f83

Please sign in to comment.