Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a cypress test to assign a volunteer to a patient #9167

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions cypress/e2e/patient_spec/PatientVolunteer.cy.ts
Original file line number Diff line number Diff line change
@@ -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,
);
});
});
56 changes: 56 additions & 0 deletions cypress/pageobject/Patient/PatientDetails.ts
Original file line number Diff line number Diff line change
@@ -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"]', []);
}
}
6 changes: 5 additions & 1 deletion src/components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {

<DropdownTransition>
<ComboboxOptions
data-testid="volunteer-search-results"
modal={false}
as="ul"
className="cui-dropdown-base absolute z-10 mt-0.5 origin-top-right"
Expand All @@ -249,7 +250,10 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
{`Please enter at least ${props.minQueryLength} characters to search`}
</div>
) : filteredOptions.length === 0 ? (
<div className="p-2 text-sm text-secondary-500">
<div
data-testid="no-results"
className="p-2 text-sm text-secondary-500"
>
No options found
</div>
) : (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Patient/PatientHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const PatientHome = (props: {
)}

{patientData.assigned_to_object && (
<div>
<div id="assigned-volunteer">
<p className="text-xs font-normal leading-tight text-gray-600">
{t("assigned_volunteer")}:
</p>
Expand Down
Loading