Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #915 from Ferlab-Ste-Justine/Test/Ajout_modificati…
Browse files Browse the repository at this point in the history
…on_tests_integration

Ajout/modification tests intégration de création de patient/prescription
  • Loading branch information
kstonge authored Apr 1, 2022
2 parents 675ad0b + 20fa03e commit fbce549
Show file tree
Hide file tree
Showing 14 changed files with 577 additions and 429 deletions.
153 changes: 153 additions & 0 deletions client/src/__tests__/PrescriptionCreation/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import {
queryByTestId,
render, screen, waitFor,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { rest } from 'msw';
import { setupServer } from 'msw/node';

import AppTest from '../../AppTest';
import PatientSubmission from '../../components/screens/PatientSubmission';
import { mockRptToken } from '../mocks';
import * as mock from '../mocks/mockData'

const buildHPORequest = () => rest.get(
'https://hpo.qa.cqgc.hsj.rtss.qc.ca/hpo/descendants',
(req, res, ctx) => res(ctx.status(200), ctx.json(mock.HPORequest)),
);

const buildServiceRequestCodeRequest = () => rest.get(
'https://fhir.qa.cqgc.hsj.rtss.qc.ca/fhir/CodeSystem/service-request-code',
(req, res, ctx) => res(ctx.status(200), ctx.json(mock.ServiceRequestCodeRequest)),
);
describe('PrescriptionCreation', () => {
const server = setupServer();

beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' });
});

beforeEach(() => {
server.resetHandlers();
console.error = jest.fn();
console.warn = jest.fn();
console.log = jest.fn();
});

afterAll(() => {
server.close();
});

describe('Should not be able to create a prescription', () => {
test('without MRN', async () => {
mockRptToken();

server.use(buildHPORequest());
server.use(buildServiceRequestCodeRequest());
render(
<AppTest>
<PatientSubmission />
</AppTest>,
);

await waitFor(() => screen.getByTestId('MMG'));
const prescriptionTestLabel = screen.getByTestId('MMG');
act(() => userEvent.click(prescriptionTestLabel, {}));

act(() => userEvent.click(screen.getByTestId('SubmitButton'), {}));

await waitFor(() => screen.getByTestId('alert'));
expect(alert).toBeDefined();
});

test('without Analyse', async () => {
mockRptToken();

server.use(buildHPORequest());
server.use(buildServiceRequestCodeRequest());
render(
<AppTest>
<PatientSubmission />
</AppTest>,
);

const mrnOptions = screen.getByTestId('mrn-organization-submission');
act(() => userEvent.selectOptions(mrnOptions, 'MRN1 | CHUSJ'));

act(() => userEvent.click(screen.getByTestId('SubmitButton'), {}));

await waitFor(() => screen.getByTestId('alert'));
expect(alert).toBeDefined();
});

describe('Should be able to create a prescription', () => {
test('with required field only', async () => {
mockRptToken();

server.use(buildHPORequest());
server.use(buildServiceRequestCodeRequest());
render(
<AppTest>
<PatientSubmission />
</AppTest>,
);

const mrnOptions = screen.getByTestId('mrn-organization-submission');
act(() => userEvent.selectOptions(mrnOptions, 'MRN1 | CHUSJ'));

await waitFor(() => screen.getByTestId('MMG'));
const prescriptionTestLabel = screen.getByTestId('MMG');
act(() => userEvent.click(prescriptionTestLabel, {}));

act(() => userEvent.click(screen.getByTestId('SubmitButton'), {}));

await waitFor(() => screen.getByTestId('submissionModal'));

await waitFor(() => expect(queryByTestId(screen.getByTestId('submissionModal'), 'prescribingDoctor-placeholder')).toBeNull());
});
});

test('with all fields', async () => {
mockRptToken();

server.use(buildHPORequest());
server.use(buildServiceRequestCodeRequest());
render(
<AppTest>
<PatientSubmission />
</AppTest>,
);

const mrnOptions = screen.getByTestId('mrn-organization-submission');
act(() => userEvent.selectOptions(mrnOptions, 'MRN1 | CHUSJ'));

await waitFor(() => screen.getByTestId('MMG'));
const prescriptionTestLabel = screen.getByTestId('MMG');
act(() => userEvent.click(prescriptionTestLabel, {}));

const cgh = screen.getByTestId('cgh');
act(() => userEvent.click(cgh, {}));
await waitFor(() => screen);

const familyHealth = screen.getByTestId('familyHealth');
act(() => userEvent.click(familyHealth, {}));

const clinicalSignRoot = screen.getByText('Abnormal eye physiology (HP:0012373)').parentElement?.previousSibling as Element;
act(() => userEvent.click(clinicalSignRoot, {}));

const clincalInterpretation = screen.getByTestId('InterpretationDropdown');
act(() => userEvent.selectOptions(clincalInterpretation, ['POS']));

const hypothesisTextArea = screen.getByTestId('hypothesis-placeholder');
act(() => userEvent.type(hypothesisTextArea, 'Hypothèse de la prescription.'));

act(() => userEvent.click(screen.getByTestId('SubmitButton'), {}));

await waitFor(() => screen.getByTestId('submissionModal'));

await waitFor(() => expect(queryByTestId(screen.getByTestId('submissionModal'), 'prescribingDoctor-placeholder')).toBeNull());
});
});
});
117 changes: 117 additions & 0 deletions client/src/__tests__/mocks/mockData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
export const HPORequest = {
data: {
hits: [
{
_id: '-ID',
_index: 'hpo',
_score: 9.455486,
_source: {
compact_ancestors: [
{ hpo_id: 'HP:0000478', name: 'Abnormality of the eye' },
{ hpo_id: 'HP:0000118', name: 'Phenotypic abnormality' },
{ hpo_id: 'HP:0000001', name: 'All' },
],
hpo_id: 'HP:0012373',
is_leaf: false,
name: 'Abnormal eye physiology',
parents: ['Abnormality of the eye (HP:0000478)'],
},
_type: '_doc',
},
],
total: 1,
},
message: 'Ok',
timestamp: 1623252338496,
}
export const ServiceRequestCodeRequest = {
"caseSensitive": true,
"concept": [
{
"code": "MMG",
"designation": [
{
"language": "fr",
"value": "Maladies musculaires (Panel global)"
}
],
"display": "Maladies musculaires (Panel global)"
},
{
"code": "DYSTM",
"designation": [
{
"language": "fr",
"value": "Dystrophies Musculaires"
}
],
"display": "Dystrophies Musculaires"
},
{
"code": "RHAB",
"designation": [
{
"language": "fr",
"value": "Rhabdomyolyse"
}
],
"display": "Rhabdomyolyse"
},
{
"code": "MYOPC",
"designation": [
{
"language": "fr",
"value": "Myopathies congénitales"
}
],
"display": "Myopathies congénitales"
},
{
"code": "MYASC",
"designation": [
{
"language": "fr",
"value": "Myasthenias congénitales"
}
],
"display": "Myasthenias congénitales"
},
{
"code": "HYPM",
"designation": [
{
"language": "fr",
"value": "Hyperthermie maligne"
}
],
"display": "Hyperthermie maligne"
},
{
"code": "DI",
"designation": [
{
"language": "fr",
"value": "Déficience intellectuelle (Trio)"
}
],
"display": "Déficience intellectuelle (Trio)"
}
],
"content": "complete",
"description": "Codes of service request in our system",
"experimental": false,
"id": "service-request-code",
"meta": {
"lastUpdated": "2021-12-02T01:52:59.610+00:00",
"source": "#cf312fb7fcc5e903",
"versionId": "1"
},
"name": "service-request-code",
"publisher": "Ferlab.bio",
"resourceType": "CodeSystem",
"status": "draft",
"title": "service request code",
"url": "http://fhir.cqgc.ferlab.bio/CodeSystem/service-request-code",
"version": "0.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { patientNotProbandSubState, patientProbandSubState } from './mockData';
describe('Family', () => {

beforeEach(() => {
console.error = jest.fn(); //Pour masquer les "console.error"
console.error = jest.fn();
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ describe('PatientFiles', () => {

beforeEach(() => {
(useFilesData as jest.Mock).mockReset();
console.error = jest.fn(); //Pour masquer les "console.error"
console.error = jest.fn();
});

afterEach(() => {
jest.clearAllMocks(); //Pour masquer les "console.error"
jest.clearAllMocks();
});

test('shoud show empty page when no file', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const ExistingModal: React.FC<Props> = ({ open, onClose, onNavigateToPatientCard
<Button
type="primary"
onClick={() => onNavigateToPatientCard(patient.id)}
data-testid="ResultModalExistingPatient"
>
{ intl.get(`${I18N_PREFIX}patientCard`) }
<ArrowRightOutlined />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const FormModal = ({

return (
<>
<Modal closable={false} footer={null} title={null} visible={open && isCreating}>
<Modal closable={false} footer={null} title={null} visible={open && isCreating} data-testid="ModalCreating">
<Row gutter={8}>
<Col>
<LoadingOutlined size={16} spin />
Expand Down Expand Up @@ -382,6 +382,7 @@ const FormModal = ({
}}
placeholder="ROYL 1234 4567"
suffix={isFetchingPatientInfoByRamq && <LoadingOutlined spin />}
data-testid="InputRAMQ"
/>
</Form.Item>
</fieldset>
Expand All @@ -408,6 +409,7 @@ const FormModal = ({
<Input
disabled={isFetusWithParent}
placeholder={intl.get(`${I18N_PREFIX}lastname`)}
data-testid="InputLastName"
/>
</Form.Item>
<Form.Item
Expand All @@ -431,6 +433,7 @@ const FormModal = ({
<Input
disabled={isFetusWithParent}
placeholder={intl.get(`${I18N_PREFIX}firstname`)}
data-testid="InputFirstName"
/>
</Form.Item>
<Form.Item
Expand Down Expand Up @@ -469,6 +472,7 @@ const FormModal = ({
disabled={isFetusWithParent}
disabledDate={(current: any) => current && current > moment().startOf('day')}
placeholder={intl.get(`${I18N_PREFIX}birthday.placeholder`)}
data-testid="DatePickerBirthday"
/>
</Form.Item>
<Form.Item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ResultModal: React.FC<Props> = ({
{ actions }
</div>
<span>
<Button type="link" onClick={() => onClose()} className="patient-creation__modal__content__close-button">
<Button type="link" onClick={() => onClose()} className="patient-creation__modal__content__close-button" data-testid="CloseButton">
{ intl.get(`${I18N_PREFIX}close`) }
</Button>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const SuccessModal: React.FC<Props> = ({
return (
<ResultModal
icon={<CheckCircleFilled style={{ color: '#52C41A', fontSize: 63 }} />}
data-testid="ResultModalCreation"
actions={(
<>
<Button onClick={onNewPatient}>
Expand All @@ -49,6 +50,7 @@ const SuccessModal: React.FC<Props> = ({
type="link"
className="link--underline"
onClick={() => onNavigateToPatient(patient.id!)}
data-testid="ResultModalCreation"
>
{ intl.get(`${I18N_PREFIX}patientCard`) }
</Button>
Expand Down
1 change: 1 addition & 0 deletions client/src/components/screens/PatientCreation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const PatientCreation: React.FC = () => {
className="patient-creation__button"
onClick={() => setOpenModal(SCREENS.FORM)}
type="primary"
data-testid="PatientCreationButton"
>
<PlusOutlined />
{intl.get(`${I18N_PREFIX}createPrescription`)}
Expand Down
Loading

0 comments on commit fbce549

Please sign in to comment.