-
Notifications
You must be signed in to change notification settings - Fork 532
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
Changes from 8 commits
c5c6b0b
48cb8d9
8ed99ed
5be77e1
9654198
e99203b
9cc5379
95d7dc6
c0cc83a
60e3890
3d30a92
0dbf1e2
045f375
b65f952
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
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", () => { | ||||||
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(() => { | ||||||
cy.log("Logging in as district admin"); | ||||||
loginPage.loginAsDistrictAdmin(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
cy.saveLocalStorage(); | ||||||
}); | ||||||
|
||||||
beforeEach(() => { | ||||||
cy.restoreLocalStorage(); | ||||||
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.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", () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Combine everything into one single test |
||||||
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(); | ||||||
}); | ||||||
}); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add test coverage for error states and edge cases While the happy path scenarios are well covered, consider adding tests for error states and edge cases. Add these test cases: 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 assignment cancellation", () => {
patientDetailsPage.clickAssignToVolunteer();
patientDetailsPage.cancelAssignment();
patientDetailsPage.verifyAssignmentModalClosed();
});
it("should prevent duplicate volunteer assignment", () => {
// Assuming the volunteer is already assigned
patientDetailsPage.clickAssignToVolunteer();
patientDetailsPage.selectAndAssignVolunteer(volunteerName);
cy.get('[data-testid="error-message"]')
.should('contain', 'Volunteer already assigned');
});
}); Also, verify the UI state between actions: it("should replace existing volunteer successfully", () => {
patientDetailsPage.clickAssignToVolunteer();
+ // Verify current volunteer is shown as selected
+ cy.get('[data-testid="current-volunteer"]')
+ .should('contain', volunteerName);
patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName);
+ // Verify loading state during assignment
+ cy.get('[data-testid="loading-indicator"]')
+ .should('exist')
+ .should('not.exist');
patientDetailsPage.verifyVolunteerBannerIsUpdated(anotherVolunteerName);
}); |
||||||
|
||||||
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"); | ||||||
}); | ||||||
}); | ||||||
}); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||
export class PatientDetailsPage { | ||||||
clickAssignToVolunteer() { | ||||||
cy.contains("button", "Assign to a Volunteer") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
use proper Id for the button There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check for cy.verifyAndClickElement() function after you give them the id |
||||||
.scrollIntoView() | ||||||
.should("be.visible") | ||||||
.should("be.enabled") | ||||||
.click(); | ||||||
} | ||||||
|
||||||
selectAndAssignVolunteer(volunteerName: string) { | ||||||
cy.clickAndSelectOption("#assign_volunteer", volunteerName); | ||||||
cy.clickSubmitButton("Assign"); | ||||||
cy.get("#assigned-volunteer", { timeout: 10000 }) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check for cy.verifyAndClickElement() function |
||||||
.scrollIntoView() | ||||||
.should("be.visible") | ||||||
.should("contain.text", volunteerName); | ||||||
} | ||||||
|
||||||
verifyVolunteerBannerIsUpdated(volunteerName: string) { | ||||||
cy.get("#assigned-volunteer").should( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
check the function cy.verifyContentPresence |
||||||
"contain.text", | ||||||
`Assigned Volunteer:${volunteerName}`, | ||||||
); | ||||||
} | ||||||
|
||||||
unassignAndPrepareForReassignment() { | ||||||
cy.get("#clear-button").should("be.visible").click(); | ||||||
cy.get("#dropdown-toggle").should("be.visible").click(); | ||||||
cy.clickSubmitButton("Assign"); | ||||||
} | ||||||
|
||||||
verifyBannerIsRemovedAfterUnassign() { | ||||||
cy.get("#assigned-volunteer", { timeout: 10000 }).should("not.exist"); | ||||||
} | ||||||
|
||||||
searchVolunteer(volunteerName: string) { | ||||||
cy.get("#assign_volunteer") | ||||||
.should("be.visible") | ||||||
.click() | ||||||
.type(volunteerName); | ||||||
|
||||||
cy.get("[data-testid='volunteer-search-results']", { | ||||||
timeout: 10000, | ||||||
}).should("be.visible"); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unwanted logging