This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #915 from Ferlab-Ste-Justine/Test/Ajout_modificati…
…on_tests_integration Ajout/modification tests intégration de création de patient/prescription
- Loading branch information
Showing
14 changed files
with
577 additions
and
429 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
client/src/__tests__/PrescriptionCreation/index.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.