-
Notifications
You must be signed in to change notification settings - Fork 429
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
Add Cypress Test Suite for Sample Test Request Workflow #8977
base: develop
Are you sure you want to change the base?
Changes from 13 commits
1511f69
8f5448d
36b1ceb
66bfe4a
c37f252
3b731aa
b9edb9b
a03ce0d
c6e12eb
e1ffd14
e89ec71
a882727
988fbb1
f7e9ef3
7f8a699
641137a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,83 @@ | ||||||||||||
import { SampleTestPage } from "pageobject/Sample/SampleTestCreate"; | ||||||||||||
import { PatientPage } from "pageobject/Patient/PatientCreation"; | ||||||||||||
import LoginPage from "pageobject/Login/LoginPage"; | ||||||||||||
|
||||||||||||
describe("Sample Test", () => { | ||||||||||||
const sampleTestPage = new SampleTestPage(); | ||||||||||||
const patientPage = new PatientPage(); | ||||||||||||
const loginPage = new LoginPage(); | ||||||||||||
|
||||||||||||
const patientName = "Dummy Patient 11"; | ||||||||||||
const sampleTestType = "BA/ETA"; | ||||||||||||
const icmrCategory = "Cat 0"; | ||||||||||||
const icmrLabel = "Test Icmr Label"; | ||||||||||||
const doctorName = "Dr. John Doe"; | ||||||||||||
const atypicalDetails = "Patient showing unusual symptoms"; | ||||||||||||
const diagnosis = "Suspected respiratory infection"; | ||||||||||||
const etiologyIdentified = "Bacterial infection suspected"; | ||||||||||||
const differentialDiagnosis = "Possibly a viral infection"; | ||||||||||||
const fastTrackReason = | ||||||||||||
"The patient has a high risk of complications and requires immediate testing."; | ||||||||||||
|
||||||||||||
before(() => { | ||||||||||||
loginPage.loginAsDisctrictAdmin(); | ||||||||||||
cy.saveLocalStorage(); | ||||||||||||
}); | ||||||||||||
|
||||||||||||
beforeEach(() => { | ||||||||||||
cy.restoreLocalStorage(); | ||||||||||||
cy.clearLocalStorage(/filters--.+/); | ||||||||||||
}); | ||||||||||||
|
||||||||||||
it("should request a new sample test", () => { | ||||||||||||
// Ensure patient list API is loaded before proceeding | ||||||||||||
cy.awaitUrl("/patients"); | ||||||||||||
patientPage.visitPatient(patientName); | ||||||||||||
cy.verifyAndClickElement("#patient-details", "Patient Details"); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
sampleTestPage.interceptPatientDetailsAPI(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
sampleTestPage.verifyPatientDetailsResponse(); | ||||||||||||
|
||||||||||||
// Ensure sample request API is loaded | ||||||||||||
sampleTestPage.visitSampleRequestPage(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add API intercept to ensure the sample request page has fully loaded. To ensure that the sample request page is fully loaded before interacting with it, consider adding a Apply this diff to implement the intercept: // Ensure sample request API is loaded
+ sampleTestPage.interceptSampleRequestAPI();
sampleTestPage.visitSampleRequestPage();
+ sampleTestPage.waitForSampleRequestResponse(); If these methods are not available, you can use: // Ensure sample request API is loaded
+ cy.intercept('GET', '/api/v1/sample/*').as('getSampleRequest');
sampleTestPage.visitSampleRequestPage();
+ cy.wait('@getSampleRequest');
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like the ai review suggested, there is API verification is missing |
||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||
// Fill form fields using helper functions | ||||||||||||
sampleTestPage.selectSampleType(sampleTestType); | ||||||||||||
sampleTestPage.selectIcmrCategory(icmrCategory); | ||||||||||||
sampleTestPage.fillIcmrLabel(icmrLabel); | ||||||||||||
sampleTestPage.fillFastTrackReason(fastTrackReason); | ||||||||||||
sampleTestPage.fillDoctorName(doctorName); | ||||||||||||
sampleTestPage.fillAtypicalPresentation(atypicalDetails); | ||||||||||||
sampleTestPage.fillDiagnosis(diagnosis); | ||||||||||||
sampleTestPage.fillEtiology(etiologyIdentified); | ||||||||||||
sampleTestPage.fillDiffDiagnosis(differentialDiagnosis); | ||||||||||||
sampleTestPage.checkHasSari(); | ||||||||||||
sampleTestPage.checkHasAri(); | ||||||||||||
sampleTestPage.checkIsUnusualCourse(); | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
// Submit the form and verify notification | ||||||||||||
cy.submitButton("Confirm your request to send sample for testing"); | ||||||||||||
cy.verifyNotification("Sample test created successfully"); | ||||||||||||
|
||||||||||||
// Check the updated request history | ||||||||||||
sampleTestPage.interceptSampleTestReq(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
sampleTestPage.verifySampleTestReq(); | ||||||||||||
sampleTestPage.checkRequestHistory(fastTrackReason); | ||||||||||||
|
||||||||||||
// Ensure sample page API is loaded before proceeding | ||||||||||||
cy.awaitUrl("/sample"); | ||||||||||||
|
||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add API intercept to ensure the sample page data is loaded before proceeding. To make sure that the sample page data is fully loaded before performing actions like searching, add a Apply this diff to include the intercept: // Ensure sample page API is loaded before proceeding
+ cy.intercept('GET', '/api/v1/sample/*').as('getSamples');
cy.awaitUrl("/sample");
+ cy.wait('@getSamples'); 📝 Committable suggestion
Suggested change
|
||||||||||||
sampleTestPage.searchPatientSample(patientName); | ||||||||||||
sampleTestPage.interceptGetSampleTestReq(); | ||||||||||||
sampleTestPage.verifyGetSampleTestReq(); | ||||||||||||
sampleTestPage.verifyPatientName(patientName); | ||||||||||||
sampleTestPage.clickOnSampleDetailsBtn(); | ||||||||||||
sampleTestPage.verifyGetSampleTestReq(); | ||||||||||||
sampleTestPage.verifyPatientTestDetails( | ||||||||||||
patientName, | ||||||||||||
fastTrackReason, | ||||||||||||
diagnosis, | ||||||||||||
differentialDiagnosis, | ||||||||||||
etiologyIdentified, | ||||||||||||
); | ||||||||||||
}); | ||||||||||||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,115 @@ | ||||||||||||||||||||||||
export class SampleTestPage { | ||||||||||||||||||||||||
visitSampleRequestPage() { | ||||||||||||||||||||||||
cy.verifyAndClickElement("#sample-request-btn", "Request Sample Test"); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
selectSampleType(option: string) { | ||||||||||||||||||||||||
cy.clickAndSelectOption("#sample-type", option); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation for parameters in interaction methods To enhance robustness, consider adding input validation to ensure that the Apply this diff to add input validation: selectSampleType(option: string) {
+ if (!option) {
+ throw new Error('Option is required for selectSampleType');
+ }
cy.clickAndSelectOption("#sample-type", option);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
selectIcmrCategory(option: string) { | ||||||||||||||||||||||||
cy.clickAndSelectOption("#icmr-category", option); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation for parameters in interaction methods Similarly, validate the Apply this diff: selectIcmrCategory(option: string) {
+ if (!option) {
+ throw new Error('Option is required for selectIcmrCategory');
+ }
cy.clickAndSelectOption("#icmr-category", option);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillIcmrLabel(label: string) { | ||||||||||||||||||||||||
cy.get("#icmr-label").should("be.visible").type(label); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate input parameter before using in Ensure the Apply this diff: fillIcmrLabel(label: string) {
+ if (!label) {
+ throw new Error('Label is required for fillIcmrLabel');
+ }
cy.get("#icmr-label").should("be.visible").type(label);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillFastTrackReason(value: string) { | ||||||||||||||||||||||||
cy.get("#is_fast_track").should("be.visible").check(); | ||||||||||||||||||||||||
cy.get("#fast_track").should("be.visible").type(value); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation to Validate the Apply this diff: fillFastTrackReason(value: string) {
+ if (!value) {
+ throw new Error('Value is required for fillFastTrackReason');
+ }
cy.get("#is_fast_track").should("be.visible").check();
cy.get("#fast_track").should("be.visible").type(value);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillDoctorName(value: string) { | ||||||||||||||||||||||||
cy.get("#doctor_name").should("be.visible").type(value); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate input in To prevent errors, check that Apply this diff: fillDoctorName(value: string) {
+ if (!value) {
+ throw new Error('Doctor name is required for fillDoctorName');
+ }
cy.get("#doctor_name").should("be.visible").type(value);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillAtypicalPresentation(value: string) { | ||||||||||||||||||||||||
cy.get("#is_atypical_presentation").should("be.visible").check(); | ||||||||||||||||||||||||
cy.get("#atypical_presentation").should("be.visible").type(value); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add parameter validation in Ensure Apply this diff: fillAtypicalPresentation(value: string) {
+ if (!value) {
+ throw new Error('Value is required for fillAtypicalPresentation');
+ }
cy.get("#is_atypical_presentation").should("be.visible").check();
cy.get("#atypical_presentation").should("be.visible").type(value);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillDiagnosis(value: string) { | ||||||||||||||||||||||||
cy.get("#diagnosis").should("be.visible").type(value); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate Add a check to ensure Apply this diff: fillDiagnosis(value: string) {
+ if (!value) {
+ throw new Error('Diagnosis value is required for fillDiagnosis');
+ }
cy.get("#diagnosis").should("be.visible").type(value);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillEtiology(value: string) { | ||||||||||||||||||||||||
cy.get("#etiology_identified").should("be.visible").type(value); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add input validation to Check that Apply this diff: fillEtiology(value: string) {
+ if (!value) {
+ throw new Error('Etiology value is required for fillEtiology');
+ }
cy.get("#etiology_identified").should("be.visible").type(value);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
fillDiffDiagnosis(value: string) { | ||||||||||||||||||||||||
cy.get("#diff_diagnosis").should("be.visible").type(value); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Validate Ensure Apply this diff: fillDiffDiagnosis(value: string) {
+ if (!value) {
+ throw new Error('Differential diagnosis value is required for fillDiffDiagnosis');
+ }
cy.get("#diff_diagnosis").should("be.visible").type(value);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
checkHasSari() { | ||||||||||||||||||||||||
cy.get("#has_sari").should("be.visible").check(); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
checkHasAri() { | ||||||||||||||||||||||||
cy.get("#has_ari").should("be.visible").check(); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
checkIsUnusualCourse() { | ||||||||||||||||||||||||
cy.get("#is_unusual_course").should("be.visible").check(); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
checkRequestHistory(fastTrack: string) { | ||||||||||||||||||||||||
cy.verifyContentPresence("#sample-test-status", ["Request Submitted"]); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
cy.verifyContentPresence("#sample-test-type", ["ba/eta"]); | ||||||||||||||||||||||||
cy.verifyContentPresence("#sample-test-fast-track", [fastTrack]); | ||||||||||||||||||||||||
cy.verifyContentPresence("#sample-test-result", ["Awaiting"]); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
searchPatientSample(patientName: string) { | ||||||||||||||||||||||||
cy.get("#search_patient_name").should("be.visible").type(patientName); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
verifyPatientName(patientName: string) { | ||||||||||||||||||||||||
cy.verifyContentPresence("#sample-test-patient-name", [patientName]); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
clickOnSampleDetailsBtn() { | ||||||||||||||||||||||||
cy.get("#sample-details-btn").should("be.visible").first().click(); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
verifyPatientTestDetails( | ||||||||||||||||||||||||
patientName: string, | ||||||||||||||||||||||||
fastTrackReason: string, | ||||||||||||||||||||||||
diagnosis: string, | ||||||||||||||||||||||||
differentialDiagnosis: string, | ||||||||||||||||||||||||
etiologyIdentified: string, | ||||||||||||||||||||||||
) { | ||||||||||||||||||||||||
cy.verifyContentPresence("#patient_name", [patientName]); | ||||||||||||||||||||||||
cy.verifyContentPresence("#fast_track_reason", [fastTrackReason]); | ||||||||||||||||||||||||
cy.verifyContentPresence("#doctor_name", ["Dr John Doe"]); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
cy.verifyContentPresence("#diagnosis", [diagnosis]); | ||||||||||||||||||||||||
cy.verifyContentPresence("#diff_diagnosis", [differentialDiagnosis]); | ||||||||||||||||||||||||
cy.verifyContentPresence("#etiology_identified", [etiologyIdentified]); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
interceptPatientDetailsAPI() { | ||||||||||||||||||||||||
cy.intercept("GET", "**/api/v1/patient/**").as("patientDetails"); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
verifyPatientDetailsResponse() { | ||||||||||||||||||||||||
cy.wait("@patientDetails").its("response.statusCode").should("eq", 200); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
interceptSampleTestReq() { | ||||||||||||||||||||||||
cy.intercept("GET", "**/api/v1/patient/*/test_sample/**").as( | ||||||||||||||||||||||||
"sampleDetails", | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
verifySampleTestReq() { | ||||||||||||||||||||||||
cy.wait("@sampleDetails").its("response.statusCode").should("eq", 200); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
interceptGetSampleTestReq() { | ||||||||||||||||||||||||
cy.intercept("GET", "**/api/v1/test_sample/**").as("getSampleTestReq"); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
verifyGetSampleTestReq() { | ||||||||||||||||||||||||
cy.wait("@getSampleTestReq").its("response.statusCode").should("eq", 200); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1370,6 +1370,7 @@ export const PatientHome = (props: any) => { | |
) | ||
} | ||
authorizeFor={NonReadOnlyUsers} | ||
id="sample-request-btn" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Both instances of "Request Sample Test" should have test identifiers for consistency The codebase has two instances of "Request Sample Test":
For consistent test automation, consider adding a test identifier to the 🔗 Analysis chainLGTM! Test identifier added for Cypress automation. The addition of the Let's verify if similar buttons in the desktop view also need test identifiers: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for other sample test related buttons in the file
rg --type tsx "Request Sample Test" -B 2 -A 2
Length of output: 75 Script: #!/bin/bash
# Search for other sample test related buttons in the file, using ripgrep without file type filter
rg "Request Sample Test" -B 2 -A 2
Length of output: 856 Script: #!/bin/bash
# Let's check if these other instances have test identifiers
rg -B 5 -A 5 "Request Sample Test" src/components/Patient/PatientHome.tsx
Length of output: 909 |
||
> | ||
<span className="flex w-full items-center justify-start gap-2"> | ||
<CareIcon icon="l-medkit" className="text-xl" /> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the typo in method name
loginAsDisctrictAdmin
.The method name
loginAsDisctrictAdmin
contains a typo. It should beloginAsDistrictAdmin
.Apply this diff to correct the typo:
📝 Committable suggestion