diff --git a/cypress/e2e/patient_spec/PatientVolunteer.cy.ts b/cypress/e2e/patient_spec/PatientVolunteer.cy.ts new file mode 100644 index 00000000000..87a406bc251 --- /dev/null +++ b/cypress/e2e/patient_spec/PatientVolunteer.cy.ts @@ -0,0 +1,57 @@ +import LoginPage from "../../pageobject/Login/LoginPage"; +import { PatientConsultationPage } from "../../pageobject/Patient/PatientConsultation"; +import { PatientPage } from "../../pageobject/Patient/PatientCreation"; +import { PatientDetailsPage } from "../../pageobject/Patient/PatientDetails"; + +describe("Assign a volunteer to a patient - Multiple Tests", () => { + const loginPage = new LoginPage(); + const patientPage = new PatientPage(); + const patientConsultationPage = new PatientConsultationPage(); + const patientDetailsPage = new PatientDetailsPage(); + const patient = "Dummy Patient 16"; + const volunteerName = "dummy volunteer"; + const anotherVolunteerName = "Abhi Patil"; + + before(() => { + loginPage.loginByRole("districtAdmin"); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); + cy.request("/patients").its("status").should("eq", 200); + + cy.visit("/patients"); + cy.wrap(null, { timeout: 10000 }).then(() => { + patientPage.visitPatient(patient); + }); + + cy.get("#patient-details").should("exist"); + patientConsultationPage.clickPatientDetails(); + }); + + it("should assign a new volunteer successfully", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.selectAndAssignVolunteer(volunteerName); + }); + + it("should replace existing volunteer successfully", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName); + }); + + it("should unassign volunteer successfully", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.unassignVolunteer(); + patientDetailsPage.verifyBannerIsRemovedAfterUnassign(); + }); + + it("should handle volunteer not found in dropdown", () => { + patientDetailsPage.clickAssignOrReassignVolunteer(); + patientDetailsPage.searchNonExistingVolunteer( + "Non-existent Volunteer", + false, + ); + }); +}); diff --git a/cypress/pageobject/Patient/PatientDetails.ts b/cypress/pageobject/Patient/PatientDetails.ts new file mode 100644 index 00000000000..9514870fbf8 --- /dev/null +++ b/cypress/pageobject/Patient/PatientDetails.ts @@ -0,0 +1,56 @@ +export class PatientDetailsPage { + clickAssignToVolunteer() { + cy.verifyAndClickElement("#assign-volunteer", "Assign to a Volunteer"); + } + + clickReassignToVolunteer() { + cy.verifyAndClickElement("#assign-volunteer", "Reassign Volunteer"); + } + + clickAssignOrReassignVolunteer() { + cy.get("#assign-volunteer") + .scrollIntoView() + .should("be.visible") + .invoke("text") + .then((text) => { + if (text.includes("Assign to a Volunteer")) { + this.clickAssignToVolunteer(); + } else if (text.includes("Reassign Volunteer")) { + this.clickReassignToVolunteer(); + } else { + throw new Error( + `Button text must be either "Assign to a Volunteer" or "Reassign Volunteer", but found: "${text}"`, + ); + } + }); + } + + selectAndAssignVolunteer(volunteerName: string) { + cy.clickAndSelectOption("#assign_volunteer", volunteerName); + cy.clickSubmitButton("Assign"); + cy.wait(1000); + cy.verifyContentPresence("#assigned-volunteer", [volunteerName]); + } + + unassignVolunteer() { + cy.get("#clear-button").should("be.visible").click(); + cy.get("#dropdown-toggle").should("be.visible").click(); + cy.clickSubmitButton("Unassign"); + } + + verifyBannerIsRemovedAfterUnassign() { + cy.get("#assigned-volunteer", { timeout: 10000 }).should("not.exist"); + } + + searchVolunteer(volunteerName: string) { + cy.typeAndSelectOption("#assign_volunteer", volunteerName); + } + + searchNonExistingVolunteer( + volunteerName: string, + clearBeforeTyping: boolean = false, + ) { + cy.typeIntoField("#assign_volunteer", volunteerName, { clearBeforeTyping }); + cy.verifyContentPresence('[data-testid="no-results"]', []); + } +} diff --git a/src/components/Form/FormFields/Autocomplete.tsx b/src/components/Form/FormFields/Autocomplete.tsx index df552883152..cf7e4837327 100644 --- a/src/components/Form/FormFields/Autocomplete.tsx +++ b/src/components/Form/FormFields/Autocomplete.tsx @@ -240,6 +240,7 @@ export const Autocomplete = (props: AutocompleteProps) => { (props: AutocompleteProps) => { {`Please enter at least ${props.minQueryLength} characters to search`} ) : filteredOptions.length === 0 ? ( -
+
No options found
) : ( diff --git a/src/components/Patient/PatientHome.tsx b/src/components/Patient/PatientHome.tsx index 1c992445706..71829841c21 100644 --- a/src/components/Patient/PatientHome.tsx +++ b/src/components/Patient/PatientHome.tsx @@ -405,7 +405,7 @@ export const PatientHome = (props: { )} {patientData.assigned_to_object && ( -
+

{t("assigned_volunteer")}: