diff --git a/cypress/e2e/patient_spec/PatientVolunteer.cy.ts b/cypress/e2e/patient_spec/PatientVolunteer.cy.ts index 322e35685b6..168cc0838a2 100644 --- a/cypress/e2e/patient_spec/PatientVolunteer.cy.ts +++ b/cypress/e2e/patient_spec/PatientVolunteer.cy.ts @@ -3,7 +3,7 @@ import { PatientConsultationPage } from "../../pageobject/Patient/PatientConsult import { PatientPage } from "../../pageobject/Patient/PatientCreation"; import { PatientDetailsPage } from "../../pageobject/Patient/PatientDetails"; -describe("Assign a volunteer to a patient", () => { +describe("Assign a volunteer to a patient - Multiple Tests", () => { const loginPage = new LoginPage(); const patientPage = new PatientPage(); const patientConsultationPage = new PatientConsultationPage(); @@ -13,8 +13,7 @@ describe("Assign a volunteer to a patient", () => { const anotherVolunteerName = "Abhi Patil"; before(() => { - cy.log("Logging in as district admin"); - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -23,45 +22,34 @@ describe("Assign a volunteer to a patient", () => { cy.clearLocalStorage(/filters--.+/); cy.request("/patients").its("status").should("eq", 200); - cy.visit("/patients").then(() => { - cy.log("Successfully navigated to patients page"); - }); - - // Add timeout and retry strategy for patient search + cy.visit("/patients"); cy.wrap(null, { timeout: 10000 }).then(() => { patientPage.visitPatient(patient); }); - // Verify patient details page is accessible cy.get("#patient-details").should("exist"); patientConsultationPage.clickPatientDetails(); }); - describe("volunteer assignment workflow", () => { - it("should assign a new volunteer successfully", () => { - patientDetailsPage.clickAssignToVolunteer(); - patientDetailsPage.selectAndAssignVolunteer(volunteerName); - patientDetailsPage.verifyVolunteerBannerIsUpdated(volunteerName); - }); + it("should assign a new volunteer successfully", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.selectAndAssignVolunteer(volunteerName); + }); - it("should replace existing volunteer successfully", () => { - patientDetailsPage.clickAssignToVolunteer(); - patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName); - patientDetailsPage.verifyVolunteerBannerIsUpdated(anotherVolunteerName); - }); + it("should replace existing volunteer successfully", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName); + }); - it("should unassign volunteer successfully", () => { - patientDetailsPage.clickAssignToVolunteer(); - patientDetailsPage.unassignAndPrepareForReassignment(); - patientDetailsPage.verifyBannerIsRemovedAfterUnassign(); - }); + it("should unassign volunteer successfully", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.unassignAndPrepareForReassignment(); + patientDetailsPage.verifyBannerIsRemovedAfterUnassign(); }); - describe("error states and edge cases", () => { - it("should handle volunteer not found in dropdown", () => { - patientDetailsPage.clickAssignToVolunteer(); - patientDetailsPage.searchVolunteer("Non-existent Volunteer"); - cy.get('[data-testid="no-results"]').should("be.visible"); - }); + it("should handle volunteer not found in dropdown", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.searchVolunteer("Non-existent Volunteer"); + cy.get('[data-testid="no-results"]').should("be.visible"); }); }); diff --git a/cypress/pageobject/Patient/PatientDetails.ts b/cypress/pageobject/Patient/PatientDetails.ts index 8b032ca9bf7..b17eb86de43 100644 --- a/cypress/pageobject/Patient/PatientDetails.ts +++ b/cypress/pageobject/Patient/PatientDetails.ts @@ -1,32 +1,43 @@ export class PatientDetailsPage { clickAssignToVolunteer() { - cy.contains("button", "Assign to a Volunteer") + cy.verifyAndClickElement("#assign-volunteer", "Assign to a Volunteer"); + } + + clickReassignToVolunteer() { + cy.verifyAndClickElement("#assign-volunteer", "Reassign Volunteer"); + } + + clickAssignOrReassignVolunteer() { + cy.get("#assign-volunteer") .scrollIntoView() .should("be.visible") .should("be.enabled") - .click(); + .invoke("text") + .then((text) => { + if (text.includes("Assign to a Volunteer")) { + cy.verifyAndClickElement( + "#assign-volunteer", + "Assign to a Volunteer", + ); + } else if (text.includes("Reassign Volunteer")) { + cy.verifyAndClickElement("#assign-volunteer", "Reassign Volunteer"); + } else { + throw new Error("Expected button text not found."); + } + }); } selectAndAssignVolunteer(volunteerName: string) { cy.clickAndSelectOption("#assign_volunteer", volunteerName); cy.clickSubmitButton("Assign"); - cy.get("#assigned-volunteer", { timeout: 10000 }) - .scrollIntoView() - .should("be.visible") - .should("contain.text", volunteerName); - } - - verifyVolunteerBannerIsUpdated(volunteerName: string) { - cy.get("#assigned-volunteer").should( - "contain.text", - `Assigned Volunteer:${volunteerName}`, - ); + cy.wait(1000); + cy.verifyContentPresence("#assigned-volunteer", [volunteerName]); } unassignAndPrepareForReassignment() { cy.get("#clear-button").should("be.visible").click(); cy.get("#dropdown-toggle").should("be.visible").click(); - cy.clickSubmitButton("Assign"); + cy.clickSubmitButton("Unassign"); } verifyBannerIsRemovedAfterUnassign() {