Skip to content

Commit

Permalink
updated tests according to changes in frontend & used existing comman…
Browse files Browse the repository at this point in the history
…ds from command.ts
  • Loading branch information
sidpg123 committed Dec 17, 2024
1 parent 3d30a92 commit 0dbf1e2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
50 changes: 19 additions & 31 deletions cypress/e2e/patient_spec/PatientVolunteer.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
});

Expand All @@ -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");
});
});
39 changes: 25 additions & 14 deletions cypress/pageobject/Patient/PatientDetails.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit 0dbf1e2

Please sign in to comment.