Skip to content

Commit

Permalink
Refactored volunteer assignment logic and improved test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sidpg123 committed Nov 23, 2024
1 parent 8ed99ed commit 5be77e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
44 changes: 22 additions & 22 deletions cypress/e2e/patient_spec/PatientVolunteer.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@ describe("Assign a volunteer to a patient", () => {
beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
});

it("assigns a volunteer to a patient and checks the banner that shows the volunteer's name", () => {
cy.visit("/patients");

cy.visit("/patients").then(() => {
cy.log("Successfully navigated to patients page");
});
patientPage.visitPatient(patient);
patientConsultationPage.clickPatientDetails();
});

patientDetailsPage.clickAssignToAVounteer();

patientDetailsPage.selectAndAssignVolunteer(volunteerName);

patientDetailsPage.verifyVolunteerBannerIsUpdated(volunteerName);

patientDetailsPage.clickAssignToAVounteer();

patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName);

patientDetailsPage.verifyVolunteerBannerIsUpdated(anotherVolunteerName);

patientDetailsPage.clickAssignToAVounteer();

patientDetailsPage.unassignVolunteer();

patientDetailsPage.verifyBannerIsRemovedAfterUnassign();
describe("volunteer assignment workflow", () => {
it("should assign a new volunteer successfully", () => {
patientDetailsPage.clickAssignToVolunteer();
patientDetailsPage.selectAndAssignVolunteer(volunteerName);
patientDetailsPage.verifyVolunteerBannerIsUpdated(volunteerName);
});

it("should replace existing volunteer successfully", () => {
patientDetailsPage.clickAssignToVolunteer();
patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName);
patientDetailsPage.verifyVolunteerBannerIsUpdated(anotherVolunteerName);
});

it("should unassign volunteer successfully", () => {
patientDetailsPage.clickAssignToVolunteer();
patientDetailsPage.unassignAndPrepareForReassignment();
patientDetailsPage.verifyBannerIsRemovedAfterUnassign();
});
});
});
19 changes: 12 additions & 7 deletions cypress/pageobject/Patient/PatientDetails.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
export class PatientDetailsPage {
clickAssignToAVounteer() {
cy.get('button:contains("Assign to a volunteer")').click({ force: true });
clickAssignToVolunteer() {
cy.contains("button", "Assign to a volunteer")
.scrollIntoView()
.should("be.visible")
.should("be.enabled")
.click();
}

selectAndAssignVolunteer(volunteerName: string) {
cy.clickAndSelectOption("#assign_volunteer", volunteerName);
cy.clickSubmitButton("Assign");
cy.wait(2000);
cy.get("#assigned-volunteer", { timeout: 10000 })
.scrollIntoView()
.should("be.visible")
.should("contain.text", volunteerName);
}

verifyVolunteerBannerIsUpdated(volunteerName: string) {
Expand All @@ -15,11 +22,9 @@ export class PatientDetailsPage {
.should("contain.text", `Assigned Volunteer:${volunteerName}`);
}

unassignVolunteer() {
unassignAndPrepareForReassignment() {
cy.get("#clear-button").should("be.visible").find("svg").click();
// Close the dropdown
cy.get('button[id^="headlessui-combobox-button-"]').click(); // Click the dropdown close button

cy.get("#dropdown-toggle").click();
cy.clickSubmitButton("Assign");
}

Expand Down

0 comments on commit 5be77e1

Please sign in to comment.