From 9156578a23817e5ff0dbc643e278240e32cca54b Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 01:12:35 +0530 Subject: [PATCH 01/17] add visible check for command action --- cypress/support/commands.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index f5bbcf42290..7b98aacb7ff 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -180,6 +180,9 @@ Cypress.Commands.add( .click() .then(() => { cy.get("[role='option']").contains(reference).click(); + }) + .then(() => { + cy.get(element).should("contain", reference); }); }, ); From c9e6650bb0c800ce27899719e76c776369ec18b0 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 01:55:01 +0530 Subject: [PATCH 02/17] created new command function to verify all typed elemenents are present in the input field --- .../pageobject/Patient/PatientLogupdate.ts | 4 ++-- cypress/support/commands.ts | 20 ++++++++++++++++--- cypress/support/index.ts | 4 ++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index bbe7c157e15..a639867a201 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -55,11 +55,11 @@ class PatientLogupdate { } typeSystolic(systolic: string) { - cy.get("#systolic").click().type(systolic); + cy.typeAndVerifyValue("#systolic", systolic); } typeDiastolic(diastolic: string) { - cy.get("#diastolic").click().type(diastolic); + cy.typeAndVerifyValue("#diastolic", diastolic); } typePulse(pulse: string) { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 7b98aacb7ff..724da6fbbf4 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -133,12 +133,15 @@ Cypress.Commands.add("clickCancelButton", (buttonText = "Cancel") => { Cypress.Commands.add( "typeAndSelectOption", - (element: string, referance: string) => { + (element: string, reference: string) => { cy.get(element) .click() - .type(referance) + .type(reference) + .then(() => { + cy.get("[role='option']").contains(reference).click(); + }) .then(() => { - cy.get("[role='option']").contains(referance).click(); + cy.get(element).should("contain", reference); }); }, ); @@ -187,6 +190,17 @@ Cypress.Commands.add( }, ); +Cypress.Commands.add( + "typeAndVerifyValue", + (selector: string, value: string) => { + cy.get(selector) + .should("be.visible") + .click() + .type(value) + .should("have.value", value); + }, +); + Cypress.Commands.add("selectRadioOption", (name: string, value: string) => { cy.get(`input[type='radio'][name='${name}'][value=${value}]`).click(); }); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index fa01326698c..09c135e2639 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -39,6 +39,10 @@ declare global { element: string, reference: string, ): Chainable; + typeAndVerifyValue( + element: string, + reference: string, + ): Chainable; preventPrint(): Chainable; closeNotification(): Chainable; verifyContentPresence( From f11a0b901118ef960cb145dd239344ff91672ee8 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 02:55:11 +0530 Subject: [PATCH 03/17] revert unwanted change --- cypress/support/commands.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 724da6fbbf4..60eb12547bf 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -139,9 +139,6 @@ Cypress.Commands.add( .type(reference) .then(() => { cy.get("[role='option']").contains(reference).click(); - }) - .then(() => { - cy.get(element).should("contain", reference); }); }, ); From de59ef7b5b897d02b48abe9de3b2b4ba5d9bb3ca Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:08:58 +0530 Subject: [PATCH 04/17] added scrollintoview into the reusable component --- cypress/pageobject/Patient/PatientLogupdate.ts | 13 ++++++------- cypress/support/commands.ts | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index a639867a201..cec2520608a 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -36,8 +36,7 @@ class PatientLogupdate { } typePhysicalExamination(examination: string) { - cy.get("#physical_examination_info").click().type(examination); - cy.get("#physical_examination_info").should("contain", examination); + cy.typeAndVerifyValue("#physical_examination_info", examination); } typeOtherDetails(details: string) { @@ -63,19 +62,19 @@ class PatientLogupdate { } typePulse(pulse: string) { - cy.get("#pulse").click().type(pulse); + cy.typeAndVerifyValue("#pulse", pulse); } typeTemperature(temperature: string) { - cy.get("#temperature").click().type(temperature); + cy.typeAndVerifyValue("#temperature", temperature); } typeRespiratory(respiratory: string) { - cy.get("#resp").click().type(respiratory); + cy.typeAndVerifyValue("#resp", respiratory); } typeSpo2(spo: string) { - cy.get("#ventilator_spo2").click().type(spo); + cy.typeAndVerifyValue("#ventilator_spo2", spo); } selectRhythm(rhythm: string) { @@ -83,7 +82,7 @@ class PatientLogupdate { } typeRhythm(rhythm: string) { - cy.get("#rhythm_detail").click().type(rhythm); + cy.typeAndVerifyValue("#rhythm_detail", rhythm); } interceptDailyRounds() { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 60eb12547bf..ff7257fe6dd 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -191,6 +191,7 @@ Cypress.Commands.add( "typeAndVerifyValue", (selector: string, value: string) => { cy.get(selector) + .scrollIntoView() .should("be.visible") .click() .type(value) From 286d50da22c873a3b2e8533ea9192fff4e0cf195 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 03:49:11 +0530 Subject: [PATCH 05/17] fixed cypress failure in patient registration form --- .../patient_spec/PatientRegistration.cy.ts | 33 +++++------ .../pageobject/Patient/PatientConsultation.ts | 2 +- cypress/pageobject/Patient/PatientCreation.ts | 22 +------ cypress/pageobject/utils/constants.ts | 58 +++++++++++++++++++ cypress/support/commands.ts | 7 ++- cypress/support/index.ts | 1 + 6 files changed, 83 insertions(+), 40 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientRegistration.cy.ts b/cypress/e2e/patient_spec/PatientRegistration.cy.ts index 5601f994c53..2bf7bb03431 100644 --- a/cypress/e2e/patient_spec/PatientRegistration.cy.ts +++ b/cypress/e2e/patient_spec/PatientRegistration.cy.ts @@ -1,3 +1,5 @@ +import { PatientConsultationPage } from "pageobject/Patient/PatientConsultation"; + import LoginPage from "../../pageobject/Login/LoginPage"; import { PatientData, @@ -6,7 +8,11 @@ import { import PatientInsurance from "../../pageobject/Patient/PatientInsurance"; import PatientMedicalHistory from "../../pageobject/Patient/PatientMedicalHistory"; import PatientTransfer from "../../pageobject/Patient/PatientTransfer"; -import { generatePhoneNumber } from "../../pageobject/utils/constants"; +import { + generatePatientName, + generatePhoneNumber, + generateRandomAddress, +} from "../../pageobject/utils/constants"; const yearOfBirth = "2001"; @@ -35,18 +41,17 @@ describe("Patient Creation with consultation", () => { const patientTransfer = new PatientTransfer(); const patientInsurance = new PatientInsurance(); const patientMedicalHistory = new PatientMedicalHistory(); + const patientConsultationPage = new PatientConsultationPage(); const phone_number = generatePhoneNumber(); const age = calculateAge(); const patientFacility = "Dummy Facility 40"; const patientDateOfBirth = "01012001"; const patientMenstruationStartDate = getRelativeDateString(-10); const patientDateOfDelivery = getRelativeDateString(-20); - const patientOneName = "Great Napolean 14"; + const patientOneName = generatePatientName(); const patientOneGender = "Male"; const patientOneUpdatedGender = "Female"; - const patientOneAddress = `149/J, 3rd Block, - Aluva - Ernakulam, Kerala - 682001`; + const patientOneAddress = generateRandomAddress(true); const patientOnePincode = "682001"; const patientOneState = "Kerala"; const patientOneDistrict = "Ernakulam"; @@ -115,13 +120,11 @@ describe("Patient Creation with consultation", () => { it("Create a new patient with all field in registration form and no consultation", () => { patientPage.createPatientWithData(newPatientData); - // Verify the patient details patientPage.clickCancelButton(); - patientPage.savePatientUrl(); + // Verify the patient details patientPage.verifyPatientDashboardDetails( patientOneGender, age, - patientOneName, phone_number, phone_number, yearOfBirth, @@ -149,13 +152,12 @@ describe("Patient Creation with consultation", () => { patientPage.verifyPatientNameList(patientOneName); }); - it("Edit the patient details with no consultation and verify", () => { - patientPage.interceptFacilities(); - patientPage.visitUpdatePatientUrl(); - patientPage.verifyStatusCode(); - patientPage.patientformvisibility(); + it("Edit the patient details and verify its reflection", () => { + const patientName = "Dummy Patient Two"; + patientPage.visitPatient(patientName); + patientConsultationPage.clickPatientDetails(); + patientPage.clickPatientUpdateDetails(); // change the gender to female and input data to related changed field - cy.wait(3000); patientPage.selectPatientGender(patientOneUpdatedGender); patientPage.typePatientDateOfBirth(patientDateOfBirth); patientPage.clickPatientAntenatalStatusYes(); @@ -197,9 +199,6 @@ describe("Patient Creation with consultation", () => { ); patientPage.clickUpdatePatient(); patientPage.verifyPatientUpdated(); - patientPage.interceptGetPatient(); - patientPage.visitPatientUrl(); - patientPage.verifyGetPatientResponse(); // Verify Female Gender change reflection, No Medical History and Insurance Details patientPage.verifyPatientDashboardDetails( patientOneUpdatedGender, diff --git a/cypress/pageobject/Patient/PatientConsultation.ts b/cypress/pageobject/Patient/PatientConsultation.ts index 8ef4554277f..1306432bd03 100644 --- a/cypress/pageobject/Patient/PatientConsultation.ts +++ b/cypress/pageobject/Patient/PatientConsultation.ts @@ -65,7 +65,7 @@ export class PatientConsultationPage { } clickPatientDetails() { - cy.verifyAndClickElement("#consultationpage-header", "Patient Details"); + cy.verifyAndClickElement("#patient-details", "Patient Details"); } typePatientIllnessHistory(history: string) { diff --git a/cypress/pageobject/Patient/PatientCreation.ts b/cypress/pageobject/Patient/PatientCreation.ts index bdc65c7d431..fe810eb2136 100644 --- a/cypress/pageobject/Patient/PatientCreation.ts +++ b/cypress/pageobject/Patient/PatientCreation.ts @@ -3,7 +3,7 @@ import FacilityPage from "pageobject/Facility/FacilityCreation"; import PatientMedicalHistory from "./PatientMedicalHistory"; -let patient_url = ""; +const patient_url = ""; const facilityPage = new FacilityPage(); const patientMedicalHistory = new PatientMedicalHistory(); @@ -96,7 +96,7 @@ export class PatientPage { } typePatientAge(age: string) { - cy.clickAndSelectOption("#patientAge", "Age"); + cy.clickAndSelectOption("#patientAge", "Age", true); cy.clickSubmitButton("Confirm"); cy.get("#age").clear().type(age); } @@ -175,22 +175,6 @@ export class PatientPage { cy.url().should("include", "/patient"); } - savePatientUrl() { - cy.url().then((url) => { - patient_url = url; - }); - } - - visitPatientUrl() { - this.interceptGetPatient(); - cy.awaitUrl(patient_url); - this.verifyGetPatientResponse(); - } - - visitConsultationPage() { - cy.visit(patient_url + "/consultation"); - } - clickUpdatePatient() { cy.intercept("PUT", "**/api/v1/patient/**").as("updatePatient"); cy.get("button").get("[data-testid=submit-button]").click(); @@ -220,7 +204,6 @@ export class PatientPage { verifyPatientDashboardDetails( gender: string, age: number, - patientName: string, phoneNumber: string, emergencyPhoneNumber: string, yearOfBirth: string, @@ -237,7 +220,6 @@ export class PatientPage { .then(($dashboard) => { expect($dashboard).to.contain(gender); expect($dashboard).to.contain(age); - expect($dashboard).to.contain(patientName); expect($dashboard).to.contain(phoneNumber); expect($dashboard).to.contain(emergencyPhoneNumber); expect($dashboard).to.contain(yearOfBirth); diff --git a/cypress/pageobject/utils/constants.ts b/cypress/pageobject/utils/constants.ts index 90baf3b6d4b..a19fd94e4b5 100644 --- a/cypress/pageobject/utils/constants.ts +++ b/cypress/pageobject/utils/constants.ts @@ -114,9 +114,67 @@ function generateRandomAddress(multiline: boolean = false): string { return multiline ? addressParts.join("\n") : addressParts.join(", "); } +function generatePatientName(): string { + const firstNames = [ + "John", + "Jane", + "Michael", + "Sarah", + "David", + "Emma", + "James", + "Olivia", + "Robert", + "Sophia", + "William", + "Isabella", + "Benjamin", + "Mia", + "Daniel", + "Charlotte", + "Lucas", + "Amelia", + "Ethan", + "Harper", + ]; + + const lastNames = [ + "Smith", + "Johnson", + "Williams", + "Brown", + "Jones", + "Miller", + "Davis", + "Garcia", + "Rodriguez", + "Wilson", + "Martinez", + "Hernandez", + "Lopez", + "Gonzalez", + "Perez", + "Taylor", + "Anderson", + "Thomas", + "Jackson", + "White", + ]; + + // Randomly choose a first name and last name + const randomFirstName = + firstNames[Math.floor(Math.random() * firstNames.length)]; + const randomLastName = + lastNames[Math.floor(Math.random() * lastNames.length)]; + + // Return the full name + return `${randomFirstName} ${randomLastName}`; +} + export { generatePhoneNumber, generateEmergencyPhoneNumber, generateFacilityName, generateRandomAddress, + generatePatientName, }; diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index ff7257fe6dd..29d69e29e80 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -175,14 +175,17 @@ Cypress.Commands.add( Cypress.Commands.add( "clickAndSelectOption", - (element: string, reference: string) => { + (element: string, reference: string, skipVerification: boolean = false) => { cy.get(element) .click() .then(() => { cy.get("[role='option']").contains(reference).click(); }) .then(() => { - cy.get(element).should("contain", reference); + // Skip verification if skipVerification is true + if (!skipVerification) { + cy.get(element).should("contain", reference); + } }); }, ); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index 09c135e2639..1bdb7a8e42e 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -34,6 +34,7 @@ declare global { clickAndSelectOption( element: string, reference: string, + skipVerification?: boolean, ): Chainable; verifyAndClickElement( element: string, From 5d67e6c97a874b6fc3679a1ce82f378e96309dc3 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 04:01:33 +0530 Subject: [PATCH 06/17] removed unwanted check --- .../patient_spec/PatientRegistration.cy.ts | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientRegistration.cy.ts b/cypress/e2e/patient_spec/PatientRegistration.cy.ts index 2bf7bb03431..c02ba40f481 100644 --- a/cypress/e2e/patient_spec/PatientRegistration.cy.ts +++ b/cypress/e2e/patient_spec/PatientRegistration.cy.ts @@ -21,20 +21,6 @@ const calculateAge = () => { return currentYear - parseInt(yearOfBirth); }; -const getRelativeDateString = (deltaDays = 0) => { - const date = new Date(); - if (deltaDays) { - date.setDate(date.getDate() + deltaDays); - } - return date - .toLocaleDateString("en-IN", { - day: "2-digit", - month: "2-digit", - year: "numeric", - }) - .replace(/\//g, ""); -}; - describe("Patient Creation with consultation", () => { const loginPage = new LoginPage(); const patientPage = new PatientPage(); @@ -46,8 +32,6 @@ describe("Patient Creation with consultation", () => { const age = calculateAge(); const patientFacility = "Dummy Facility 40"; const patientDateOfBirth = "01012001"; - const patientMenstruationStartDate = getRelativeDateString(-10); - const patientDateOfDelivery = getRelativeDateString(-20); const patientOneName = generatePatientName(); const patientOneGender = "Male"; const patientOneUpdatedGender = "Female"; @@ -157,15 +141,10 @@ describe("Patient Creation with consultation", () => { patientPage.visitPatient(patientName); patientConsultationPage.clickPatientDetails(); patientPage.clickPatientUpdateDetails(); - // change the gender to female and input data to related changed field patientPage.selectPatientGender(patientOneUpdatedGender); patientPage.typePatientDateOfBirth(patientDateOfBirth); - patientPage.clickPatientAntenatalStatusYes(); - patientPage.typeLastMenstruationStartDate(patientMenstruationStartDate); - patientPage.clickPatientPostPartumStatusYes(); - patientPage.typeDateOfDelivery(patientDateOfDelivery); patientPage.selectPatientBloodGroup(patientOneUpdatedBloodGroup); - // Edit the patient consultation , select none medical history and multiple health ID + // select none medical history and add multiple health ID patientMedicalHistory.clickNoneMedicialHistory(); patientInsurance.clickAddInsruanceDetails(); patientInsurance.typePatientInsuranceDetail( From 16e983d3d5b25571b7215d28e57ad8f0a81b7f75 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 04:13:00 +0530 Subject: [PATCH 07/17] removed unwanted check of patient name --- cypress/e2e/patient_spec/PatientRegistration.cy.ts | 1 - cypress/pageobject/Patient/PatientCreation.ts | 5 ----- 2 files changed, 6 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientRegistration.cy.ts b/cypress/e2e/patient_spec/PatientRegistration.cy.ts index c02ba40f481..71426af8baf 100644 --- a/cypress/e2e/patient_spec/PatientRegistration.cy.ts +++ b/cypress/e2e/patient_spec/PatientRegistration.cy.ts @@ -182,7 +182,6 @@ describe("Patient Creation with consultation", () => { patientPage.verifyPatientDashboardDetails( patientOneUpdatedGender, age, - patientOneName, phone_number, phone_number, yearOfBirth, diff --git a/cypress/pageobject/Patient/PatientCreation.ts b/cypress/pageobject/Patient/PatientCreation.ts index fe810eb2136..a74e088eeb8 100644 --- a/cypress/pageobject/Patient/PatientCreation.ts +++ b/cypress/pageobject/Patient/PatientCreation.ts @@ -3,7 +3,6 @@ import FacilityPage from "pageobject/Facility/FacilityCreation"; import PatientMedicalHistory from "./PatientMedicalHistory"; -const patient_url = ""; const facilityPage = new FacilityPage(); const patientMedicalHistory = new PatientMedicalHistory(); @@ -258,10 +257,6 @@ export class PatientPage { }); } - visitUpdatePatientUrl() { - cy.visit(patient_url + "/update"); - } - clickPatientUpdateDetails() { cy.verifyAndClickElement("#update-patient-details", "Edit Profile"); } From df02b98f7e10e8c89a64b19f49c3415502313166 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 04:23:19 +0530 Subject: [PATCH 08/17] removed unwanted check of patient details in edit --- cypress/e2e/patient_spec/PatientRegistration.cy.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientRegistration.cy.ts b/cypress/e2e/patient_spec/PatientRegistration.cy.ts index 71426af8baf..a8b1e47bb4d 100644 --- a/cypress/e2e/patient_spec/PatientRegistration.cy.ts +++ b/cypress/e2e/patient_spec/PatientRegistration.cy.ts @@ -178,16 +178,6 @@ describe("Patient Creation with consultation", () => { ); patientPage.clickUpdatePatient(); patientPage.verifyPatientUpdated(); - // Verify Female Gender change reflection, No Medical History and Insurance Details - patientPage.verifyPatientDashboardDetails( - patientOneUpdatedGender, - age, - phone_number, - phone_number, - yearOfBirth, - patientOneUpdatedBloodGroup, - patientOccupation, - ); // Verify No medical history patientMedicalHistory.verifyNoSymptosPresent("Diabetes"); // verify insurance details and dedicatd page From 63afdfbe96ef937950a7755c843128e9652e473e Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 05:07:40 +0530 Subject: [PATCH 09/17] fixed flaky issue in log update --- .../e2e/patient_spec/PatientLogUpdate.cy.ts | 8 +- .../pageobject/Patient/PatientLogupdate.ts | 85 +++++++++++-------- cypress/support/commands.ts | 19 ++--- cypress/support/index.ts | 4 - 4 files changed, 59 insertions(+), 57 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index da46a6c093e..2e7ad8129ff 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -13,6 +13,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { const patientInvestigation = new PatientInvestigation(); const patientPrescription = new PatientPrescription(); const patientCategory = "Moderate"; + const patientModifiedCategory = "Critical"; const additionalSymptoms = "Fever"; const physicalExamination = "physical examination details"; const otherExamination = "Other"; @@ -150,6 +151,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { ]); // verify the edit functionality patientLogupdate.clickUpdateDetail(); + patientLogupdate.selectPatientCategory(patientModifiedCategory); patientLogupdate.typeSystolic(patientModifiedSystolic); patientLogupdate.typeDiastolic(patientModifiedDiastolic); cy.clickSubmitButton("Continue"); @@ -318,10 +320,8 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { patientRhythm, ]); patientLogupdate.clickUpdateDetail(); - patientLogupdate.clearIntoElementById("#systolic"); - patientLogupdate.typeSystolic(patientModifiedSystolic); - patientLogupdate.clearIntoElementById("#diastolic"); - patientLogupdate.typeDiastolic(patientModifiedDiastolic); + patientLogupdate.typeSystolic(patientModifiedSystolic, true); + patientLogupdate.typeDiastolic(patientModifiedDiastolic, true); cy.clickSubmitButton("Continue"); cy.verifyNotification("Brief Update updated successfully"); cy.contains("button", "Log Updates").click(); diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index cec2520608a..1bbeba1d0ae 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -35,12 +35,17 @@ class PatientLogupdate { cy.clickAndSelectOption("#patientCategory", category); } - typePhysicalExamination(examination: string) { - cy.typeAndVerifyValue("#physical_examination_info", examination); + typePhysicalExamination( + examination: string, + clearBeforeTyping: boolean = false, + ) { + cy.typeIntoField("#physical_examination_info", examination, { + clearBeforeTyping, + }); } - typeOtherDetails(details: string) { - cy.get("#other_details").click().type(details); + typeOtherDetails(details: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#other_details", details, { clearBeforeTyping }); } typeAndMultiSelectSymptoms(input: string, symptoms: string[]) { @@ -53,36 +58,36 @@ class PatientLogupdate { cy.get("#add-symptom").click(); } - typeSystolic(systolic: string) { - cy.typeAndVerifyValue("#systolic", systolic); + typeSystolic(systolic: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#systolic", systolic, { clearBeforeTyping }); } - typeDiastolic(diastolic: string) { - cy.typeAndVerifyValue("#diastolic", diastolic); + typeDiastolic(diastolic: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#diastolic", diastolic, { clearBeforeTyping }); } - typePulse(pulse: string) { - cy.typeAndVerifyValue("#pulse", pulse); + typePulse(pulse: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#pulse", pulse, { clearBeforeTyping }); } - typeTemperature(temperature: string) { - cy.typeAndVerifyValue("#temperature", temperature); + typeTemperature(temperature: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#temperature", temperature, { clearBeforeTyping }); } - typeRespiratory(respiratory: string) { - cy.typeAndVerifyValue("#resp", respiratory); + typeRespiratory(respiratory: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#resp", respiratory, { clearBeforeTyping }); } - typeSpo2(spo: string) { - cy.typeAndVerifyValue("#ventilator_spo2", spo); + typeSpo2(spo: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#ventilator_spo2", spo, { clearBeforeTyping }); } selectRhythm(rhythm: string) { cy.clickAndSelectOption("#rhythm", rhythm); } - typeRhythm(rhythm: string) { - cy.typeAndVerifyValue("#rhythm_detail", rhythm); + typeRhythm(rhythm: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#rhythm_detail", rhythm, { clearBeforeTyping }); } interceptDailyRounds() { @@ -127,10 +132,6 @@ class PatientLogupdate { this.verifyDailyRounds(); } - clearIntoElementById(elementId) { - cy.get(elementId).click().clear(); - } - clickVitals() { cy.get("#consultation_tab_nav").scrollIntoView(); cy.verifyAndClickElement("#consultation_tab_nav", "Vitals"); @@ -140,8 +141,8 @@ class PatientLogupdate { cy.get("#bilateral_air_entry-option-false").click(); } - typeEtco2(etco2: string) { - cy.get("#etco2-range-input").type(etco2); + typeEtco2(etco2: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#etco2-range-input", etco2, { clearBeforeTyping }); } selectOxygenSupport() { @@ -152,36 +153,48 @@ class PatientLogupdate { cy.get("#ventilator_oxygen_modality-option-NON_REBREATHING_MASK").click(); } - typeOxygenFlowRate(flowRate: string) { - cy.get("#oxygen_flow_rate-range-input").type(flowRate); + typeOxygenFlowRate(flowRate: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#oxygen_flow_rate-range-input", flowRate, { + clearBeforeTyping, + }); } - typeVentilatorSpo2(spo2: string) { - cy.get("#ventilator_spo2-range-input").type(spo2); + typeVentilatorSpo2(spo2: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#ventilator_spo2-range-input", spo2, { + clearBeforeTyping, + }); } selectCriticalCareSection(sectionName: string) { cy.contains("button", sectionName).click(); } - typeBloodSugar(bloodSugar: string) { - cy.get("#blood_sugar_level-range-input").type(bloodSugar); + typeBloodSugar(bloodSugar: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#blood_sugar_level-range-input", bloodSugar, { + clearBeforeTyping, + }); } - typeInsulinDosage(insulinDosage: string) { - cy.get("#insulin_intake_dose-range-input").type(insulinDosage); + typeInsulinDosage(insulinDosage: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#insulin_intake_dose-range-input", insulinDosage, { + clearBeforeTyping, + }); } clickGoBackConsultation() { cy.get("#back-to-consultation").click(); } - typeFluidBalance(fluid: string) { - cy.get("#dialysis_fluid_balance-range-input").type(fluid); + typeFluidBalance(fluid: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#dialysis_fluid_balance-range-input", fluid, { + clearBeforeTyping, + }); } - typeNetBalance(netBalance: string) { - cy.get("#dialysis_net_balance-range-input").type(netBalance); + typeNetBalance(netBalance: string, clearBeforeTyping: boolean = false) { + cy.typeIntoField("#dialysis_net_balance-range-input", netBalance, { + clearBeforeTyping, + }); } } export default PatientLogupdate; diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 29d69e29e80..c6a1e403e24 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -190,18 +190,6 @@ Cypress.Commands.add( }, ); -Cypress.Commands.add( - "typeAndVerifyValue", - (selector: string, value: string) => { - cy.get(selector) - .scrollIntoView() - .should("be.visible") - .click() - .type(value) - .should("have.value", value); - }, -); - Cypress.Commands.add("selectRadioOption", (name: string, value: string) => { cy.get(`input[type='radio'][name='${name}'][value=${value}]`).click(); }); @@ -274,6 +262,11 @@ Cypress.Commands.add( inputField.clear(); // Clear the input field } - inputField.click().type(value); // Click and type the new value + inputField + .scrollIntoView() + .should("be.visible") + .click() + .type(value) + .should("have.value", value); // Click and type the new value }, ); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index 1bdb7a8e42e..ecbbf32738c 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -40,10 +40,6 @@ declare global { element: string, reference: string, ): Chainable; - typeAndVerifyValue( - element: string, - reference: string, - ): Chainable; preventPrint(): Chainable; closeNotification(): Chainable; verifyContentPresence( From 712380ec8ae66689969fdcf218f4193a5f08a543 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 05:52:30 +0530 Subject: [PATCH 10/17] skipped phone number verification in facility form --- .../pageobject/Facility/FacilityCreation.ts | 5 ++++- cypress/support/commands.ts | 18 +++++++++--------- cypress/support/index.ts | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index 969023c6dc0..f03fa65ce8b 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -55,7 +55,10 @@ class FacilityPage { phoneNumber: string, clearBeforeTyping: boolean = false, ) { - cy.typeIntoField("#phone_number", phoneNumber, { clearBeforeTyping }); + cy.typeIntoField("#phone_number", phoneNumber, { + clearBeforeTyping, + skipVerification: true, + }); } clickSaveFacilityButton() { diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index c6a1e403e24..54bc3be2666 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -253,20 +253,20 @@ Cypress.Commands.add( ( selector: string, value: string, - options: { clearBeforeTyping?: boolean } = {}, + options: { clearBeforeTyping?: boolean; skipVerification?: boolean } = {}, ) => { - const { clearBeforeTyping = false } = options; + const { clearBeforeTyping = false, skipVerification = false } = options; const inputField = cy.get(selector); if (clearBeforeTyping) { - inputField.clear(); // Clear the input field + inputField.clear(); // Clear the input field if specified } - inputField - .scrollIntoView() - .should("be.visible") - .click() - .type(value) - .should("have.value", value); // Click and type the new value + inputField.scrollIntoView().should("be.visible").click().type(value); + + // Conditionally skip verification based on the skipVerification flag + if (!skipVerification) { + inputField.should("have.value", value); // Verify the value if skipVerification is false + } }, ); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index ecbbf32738c..59620bf8a6d 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -50,7 +50,7 @@ declare global { typeIntoField( selector: string, value: string, - options?: { clearBeforeTyping?: boolean }, + options?: { clearBeforeTyping?: boolean; skipVerification?: boolean }, ): Chainable; } } From e5ebb8ed2ab61b8d7a1a824dbf0c48f806287eb5 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 06:05:45 +0530 Subject: [PATCH 11/17] verify the round type text --- cypress/e2e/patient_spec/PatientLogUpdate.cy.ts | 2 ++ cypress/pageobject/Patient/PatientLogupdate.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index 2e7ad8129ff..c0d914eb665 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -151,6 +151,8 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { ]); // verify the edit functionality patientLogupdate.clickUpdateDetail(); + patientLogupdate.verifyRoundType("Progress Note"); + patientLogupdate.verifyPatientCategory(patientCategory); patientLogupdate.selectPatientCategory(patientModifiedCategory); patientLogupdate.typeSystolic(patientModifiedSystolic); patientLogupdate.typeDiastolic(patientModifiedDiastolic); diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index 1bbeba1d0ae..f4d2f558cce 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -20,6 +20,12 @@ class PatientLogupdate { cy.clickAndSelectOption("#rounds_type", roundType); } + verifyRoundType(roundType: string) { + cy.get("#rounds_type") + .should("be.visible") + .should("contain.text", roundType); + } + selectBed(bed: string) { cy.typeAndSelectOption("input[name='bed']", bed); cy.intercept("POST", "**/api/v1/consultationbed/").as( @@ -35,6 +41,12 @@ class PatientLogupdate { cy.clickAndSelectOption("#patientCategory", category); } + verifyPatientCategory(category: string) { + cy.get("#patientCategory") + .should("be.visible") + .should("contain.text", category); + } + typePhysicalExamination( examination: string, clearBeforeTyping: boolean = false, From ee24ae4563c5456adfa1c53974246781728ac1bd Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 06:13:42 +0530 Subject: [PATCH 12/17] handle flaky test in log update form --- cypress/e2e/patient_spec/PatientLogUpdate.cy.ts | 1 + cypress/pageobject/utils/advanceFilterHelpers.ts | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index c0d914eb665..ccfcaf42397 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -286,6 +286,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { cy.verifyNotification("Consultation updated successfully"); cy.closeNotification(); patientLogupdate.clickLogupdate(); + patientLogupdate.verifyRoundType("Brief Update"); patientLogupdate.typePhysicalExamination(physicalExamination); patientLogupdate.typeOtherDetails(otherExamination); patientLogupdate.selectSymptomsDate("01012024"); diff --git a/cypress/pageobject/utils/advanceFilterHelpers.ts b/cypress/pageobject/utils/advanceFilterHelpers.ts index 613f4af2f23..14e3ab41bda 100644 --- a/cypress/pageobject/utils/advanceFilterHelpers.ts +++ b/cypress/pageobject/utils/advanceFilterHelpers.ts @@ -4,22 +4,22 @@ export const advanceFilters = { }, selectState(state: string) { - cy.wait(200); + cy.wait(1000); cy.clickAndSelectOption("#state", state); }, selectDistrict(district: string) { - cy.wait(200); + cy.wait(1000); cy.clickAndSelectOption("#district", district); }, selectLocalBody(localBody: string) { - cy.wait(200); + cy.wait(1000); cy.clickAndSelectOption("#local_body", localBody); }, selectWard(ward: string) { - cy.wait(200); + cy.wait(1000); cy.clickAndSelectOption("#ward", ward); }, From ece805d126517b2485b4731911945bccabed7758 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 06:34:52 +0530 Subject: [PATCH 13/17] skip verification hcx --- cypress/pageobject/Hcx/HcxClaims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/pageobject/Hcx/HcxClaims.ts b/cypress/pageobject/Hcx/HcxClaims.ts index b93862e6d13..883303d1af6 100644 --- a/cypress/pageobject/Hcx/HcxClaims.ts +++ b/cypress/pageobject/Hcx/HcxClaims.ts @@ -3,7 +3,7 @@ export class HcxClaims { cy.get("#select-insurance-policy", { timeout: 10000 }) .should("be.visible") .and("not.be.disabled"); - cy.clickAndSelectOption("#select-insurance-policy", policy); + cy.clickAndSelectOption("#select-insurance-policy", policy, true); } verifyPolicyEligibility() { From 0149ad493541cd25fe7496895ff07eca32f06931 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 06:54:40 +0530 Subject: [PATCH 14/17] fixed flaky test with timeout --- cypress/e2e/patient_spec/PatientLogUpdate.cy.ts | 7 ++++--- cypress/pageobject/Patient/PatientLogupdate.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index ccfcaf42397..c2ed8c3adc4 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -151,8 +151,8 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { ]); // verify the edit functionality patientLogupdate.clickUpdateDetail(); - patientLogupdate.verifyRoundType("Progress Note"); patientLogupdate.verifyPatientCategory(patientCategory); + patientLogupdate.verifyRoundType("Progress Note"); patientLogupdate.selectPatientCategory(patientModifiedCategory); patientLogupdate.typeSystolic(patientModifiedSystolic); patientLogupdate.typeDiastolic(patientModifiedDiastolic); @@ -286,12 +286,13 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { cy.verifyNotification("Consultation updated successfully"); cy.closeNotification(); patientLogupdate.clickLogupdate(); - patientLogupdate.verifyRoundType("Brief Update"); + patientLogupdate.verifyRoundType("Brief Update"); // Verify the default round type + patientLogupdate.selectRoundType("Brief Update"); + patientLogupdate.selectPatientCategory(patientCategory); patientLogupdate.typePhysicalExamination(physicalExamination); patientLogupdate.typeOtherDetails(otherExamination); patientLogupdate.selectSymptomsDate("01012024"); patientLogupdate.typeAndMultiSelectSymptoms("fe", ["Fever"]); - patientLogupdate.selectPatientCategory(patientCategory); patientLogupdate.typeSystolic(patientSystolic); patientLogupdate.typeDiastolic(patientDiastolic); patientLogupdate.typePulse(patientPulse); diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index f4d2f558cce..bcaf6695d96 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -21,7 +21,7 @@ class PatientLogupdate { } verifyRoundType(roundType: string) { - cy.get("#rounds_type") + cy.get("#rounds_type", { timeout: 10000 }) .should("be.visible") .should("contain.text", roundType); } @@ -42,7 +42,7 @@ class PatientLogupdate { } verifyPatientCategory(category: string) { - cy.get("#patientCategory") + cy.get("#patientCategory", { timeout: 10000 }) .should("be.visible") .should("contain.text", category); } From e1d5631e018c61ec473a1048b50eb2acd7806a76 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 07:06:58 +0530 Subject: [PATCH 15/17] updated the util folder to support more secure random generation --- cypress/pageobject/utils/constants.ts | 61 +++++++++++++++++++-------- 1 file changed, 43 insertions(+), 18 deletions(-) diff --git a/cypress/pageobject/utils/constants.ts b/cypress/pageobject/utils/constants.ts index a19fd94e4b5..5e8ea39167c 100644 --- a/cypress/pageobject/utils/constants.ts +++ b/cypress/pageobject/utils/constants.ts @@ -31,9 +31,10 @@ function generateFacilityName(): string { "Ernakulam", ]; const identifiers = [ - () => Math.floor(Math.random() * 100), // Numeric IDs - () => `Zone-${Math.floor(Math.random() * 10)}`, // Zone IDs - () => `Block-${String.fromCharCode(65 + Math.floor(Math.random() * 26))}`, // Alphabetic Blocks + () => window.crypto.getRandomValues(new Uint32Array(1))[0] % 100, // Numeric IDs + () => `Zone-${window.crypto.getRandomValues(new Uint32Array(1))[0] % 10}`, // Zone IDs + () => + `Block-${String.fromCharCode(65 + (window.crypto.getRandomValues(new Uint32Array(1))[0] % 26))}`, // Alphabetic Blocks ]; const suffixes = [ "Meta", @@ -46,12 +47,22 @@ function generateFacilityName(): string { "Hospital", ]; - const randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)]; + const randomPrefix = + prefixes[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % prefixes.length + ]; const randomLocation = - locations[Math.floor(Math.random() * locations.length)]; + locations[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % locations.length + ]; const randomIdentifier = - identifiers[Math.floor(Math.random() * identifiers.length)](); - const randomSuffix = suffixes[Math.floor(Math.random() * suffixes.length)]; + identifiers[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % identifiers.length + ](); + const randomSuffix = + suffixes[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % suffixes.length + ]; // Randomize the format of the name const formats = [ @@ -60,7 +71,9 @@ function generateFacilityName(): string { `${randomPrefix} ${randomLocation} ${randomSuffix}`, ]; - return formats[Math.floor(Math.random() * formats.length)]; + return formats[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % formats.length + ]; } function generateRandomAddress(multiline: boolean = false): string { @@ -89,15 +102,26 @@ function generateRandomAddress(multiline: boolean = false): string { ]; const districts = ["Kochi", "Ernakulam"]; const states = ["Kerala"]; - const pincode = Math.floor(682000 + Math.random() * 1000).toString(); // Generate random pincodes in the 682XXX range. + const pincode = + 682000 + (window.crypto.getRandomValues(new Uint32Array(1))[0] % 1000); // Generate random pincodes in the 682XXX range. const randomLocality = - localities[Math.floor(Math.random() * localities.length)]; + localities[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % localities.length + ]; const randomNeighborhood = - neighborhoods[Math.floor(Math.random() * neighborhoods.length)]; + neighborhoods[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % + neighborhoods.length + ]; const randomDistrict = - districts[Math.floor(Math.random() * districts.length)]; - const randomState = states[Math.floor(Math.random() * states.length)]; + districts[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % districts.length + ]; + const randomState = + states[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % states.length + ]; // Create address components const addressParts = [ @@ -109,8 +133,6 @@ function generateRandomAddress(multiline: boolean = false): string { ]; // Return address as single line or multiline - // If 'multiline' is false, return address as a single line - // If 'multiline' is true, return address with each component on a new line return multiline ? addressParts.join("\n") : addressParts.join(", "); } @@ -161,11 +183,14 @@ function generatePatientName(): string { "White", ]; - // Randomly choose a first name and last name const randomFirstName = - firstNames[Math.floor(Math.random() * firstNames.length)]; + firstNames[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % firstNames.length + ]; const randomLastName = - lastNames[Math.floor(Math.random() * lastNames.length)]; + lastNames[ + window.crypto.getRandomValues(new Uint32Array(1))[0] % lastNames.length + ]; // Return the full name return `${randomFirstName} ${randomLastName}`; From ed2bcc024c37c3e8f7d64e9a354336a872637c39 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 07:13:21 +0530 Subject: [PATCH 16/17] handle the issue raised by codeQL --- cypress/pageobject/utils/constants.ts | 89 +++++++++------------------ 1 file changed, 30 insertions(+), 59 deletions(-) diff --git a/cypress/pageobject/utils/constants.ts b/cypress/pageobject/utils/constants.ts index 5e8ea39167c..e14e3720231 100644 --- a/cypress/pageobject/utils/constants.ts +++ b/cypress/pageobject/utils/constants.ts @@ -1,7 +1,17 @@ -function generatePhoneNumber(): string { +function unbiasedRandom(max: number): number { const array = new Uint32Array(1); - window.crypto.getRandomValues(array); - const randomNum = (array[0] % 900000000) + 100000000; + let randomValue; + + do { + window.crypto.getRandomValues(array); + randomValue = array[0]; + } while (randomValue > Math.floor(0xffffffff / max) * max); + + return randomValue % max; +} + +function generatePhoneNumber(): string { + const randomNum = unbiasedRandom(900000000) + 100000000; // Ensure 9-digit range return "9" + randomNum.toString(); } @@ -31,10 +41,9 @@ function generateFacilityName(): string { "Ernakulam", ]; const identifiers = [ - () => window.crypto.getRandomValues(new Uint32Array(1))[0] % 100, // Numeric IDs - () => `Zone-${window.crypto.getRandomValues(new Uint32Array(1))[0] % 10}`, // Zone IDs - () => - `Block-${String.fromCharCode(65 + (window.crypto.getRandomValues(new Uint32Array(1))[0] % 26))}`, // Alphabetic Blocks + () => unbiasedRandom(100), // Numeric IDs + () => `Zone-${unbiasedRandom(10)}`, // Zone IDs + () => `Block-${String.fromCharCode(65 + unbiasedRandom(26))}`, // Alphabetic Blocks ]; const suffixes = [ "Meta", @@ -47,33 +56,18 @@ function generateFacilityName(): string { "Hospital", ]; - const randomPrefix = - prefixes[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % prefixes.length - ]; - const randomLocation = - locations[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % locations.length - ]; - const randomIdentifier = - identifiers[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % identifiers.length - ](); - const randomSuffix = - suffixes[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % suffixes.length - ]; - - // Randomize the format of the name + const randomPrefix = prefixes[unbiasedRandom(prefixes.length)]; + const randomLocation = locations[unbiasedRandom(locations.length)]; + const randomIdentifier = identifiers[unbiasedRandom(identifiers.length)](); + const randomSuffix = suffixes[unbiasedRandom(suffixes.length)]; + const formats = [ `${randomPrefix} ${randomLocation}-${randomIdentifier} ${randomSuffix}`, `${randomLocation} ${randomPrefix} ${randomSuffix}`, `${randomPrefix} ${randomLocation} ${randomSuffix}`, ]; - return formats[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % formats.length - ]; + return formats[unbiasedRandom(formats.length)]; } function generateRandomAddress(multiline: boolean = false): string { @@ -102,28 +96,14 @@ function generateRandomAddress(multiline: boolean = false): string { ]; const districts = ["Kochi", "Ernakulam"]; const states = ["Kerala"]; - const pincode = - 682000 + (window.crypto.getRandomValues(new Uint32Array(1))[0] % 1000); // Generate random pincodes in the 682XXX range. + const pincode = (682000 + unbiasedRandom(1000)).toString(); - const randomLocality = - localities[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % localities.length - ]; + const randomLocality = localities[unbiasedRandom(localities.length)]; const randomNeighborhood = - neighborhoods[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % - neighborhoods.length - ]; - const randomDistrict = - districts[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % districts.length - ]; - const randomState = - states[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % states.length - ]; - - // Create address components + neighborhoods[unbiasedRandom(neighborhoods.length)]; + const randomDistrict = districts[unbiasedRandom(districts.length)]; + const randomState = states[unbiasedRandom(states.length)]; + const addressParts = [ randomNeighborhood, randomLocality, @@ -132,7 +112,6 @@ function generateRandomAddress(multiline: boolean = false): string { `Pincode: ${pincode}`, ]; - // Return address as single line or multiline return multiline ? addressParts.join("\n") : addressParts.join(", "); } @@ -159,7 +138,6 @@ function generatePatientName(): string { "Ethan", "Harper", ]; - const lastNames = [ "Smith", "Johnson", @@ -183,16 +161,9 @@ function generatePatientName(): string { "White", ]; - const randomFirstName = - firstNames[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % firstNames.length - ]; - const randomLastName = - lastNames[ - window.crypto.getRandomValues(new Uint32Array(1))[0] % lastNames.length - ]; + const randomFirstName = firstNames[unbiasedRandom(firstNames.length)]; + const randomLastName = lastNames[unbiasedRandom(lastNames.length)]; - // Return the full name return `${randomFirstName} ${randomLastName}`; } From 8be3a3ccc69c0c36c9da7cb8f3386c86d23edb48 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Thu, 19 Dec 2024 07:20:29 +0530 Subject: [PATCH 17/17] verify data in log update form before interacting with the form --- cypress/e2e/patient_spec/PatientLogUpdate.cy.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index c2ed8c3adc4..963f62a76e0 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -253,8 +253,9 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { patientPage.interceptGetPatient(); patientLogupdate.clickLogupdate(); patientPage.verifyGetPatientResponse(); - patientLogupdate.typePhysicalExamination(physicalExamination); + patientLogupdate.verifyRoundType("Brief Update"); patientLogupdate.selectPatientCategory(patientCategory); + patientLogupdate.typePhysicalExamination(physicalExamination); patientLogupdate.typeOtherDetails(otherExamination); patientLogupdate.selectSymptomsDate("01012024"); patientLogupdate.typeAndMultiSelectSymptoms("fe", ["Fever"]); @@ -324,6 +325,8 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { patientRhythm, ]); patientLogupdate.clickUpdateDetail(); + patientLogupdate.verifyPatientCategory(patientCategory); + patientLogupdate.verifyRoundType("Brief Update"); patientLogupdate.typeSystolic(patientModifiedSystolic, true); patientLogupdate.typeDiastolic(patientModifiedDiastolic, true); cy.clickSubmitButton("Continue");