-
Notifications
You must be signed in to change notification settings - Fork 522
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 2 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,50 @@ | ||||||
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--.+/); | ||||||
}); | ||||||
|
||||||
it("assigns a volunteer to a patient and checks the banner that shows the volunteer's name", () => { | ||||||
cy.visit("/patients"); | ||||||
|
||||||
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(); | ||||||
}); | ||||||
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 Enhance test organization and assertions While the test covers all required scenarios, consider these improvements:
describe("Assign a volunteer to a patient", () => {
// ... existing setup ...
describe("volunteer assignment workflow", () => {
beforeEach(() => {
cy.visit("/patients").then(() => {
cy.log("Successfully navigated to patients page");
});
patientPage.visitPatient(patient);
patientConsultationPage.clickPatientDetails();
});
it("should assign a new volunteer successfully", () => {
patientDetailsPage.clickAssignToAVounteer();
patientDetailsPage.selectAndAssignVolunteer(volunteerName);
patientDetailsPage.verifyVolunteerBannerIsUpdated(volunteerName);
});
it("should replace existing volunteer successfully", () => {
patientDetailsPage.clickAssignToAVounteer();
patientDetailsPage.selectAndAssignVolunteer(anotherVolunteerName);
patientDetailsPage.verifyVolunteerBannerIsUpdated(anotherVolunteerName);
});
it("should unassign volunteer successfully", () => {
patientDetailsPage.clickAssignToAVounteer();
patientDetailsPage.unassignVolunteer();
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. Some of the suggestions are worth doing, like this one (break it up into smaller tests). Go ahead and make the changes accordingly @sidpg123 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.
|
||||||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,29 @@ | ||||||||||||||||||||||||||||
export class PatientDetailsPage { | ||||||||||||||||||||||||||||
clickAssignToAVounteer() { | ||||||||||||||||||||||||||||
cy.get('button:contains("Assign to a volunteer")').click({ force: true }); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
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. Fix typo and avoid force clicks
Here's the suggested fix: - clickAssignToAVounteer() {
- cy.get('button:contains("Assign to a volunteer")').click({ force: true });
+ clickAssignToVolunteer() {
+ cy.contains('button', 'Assign to a volunteer')
+ .should('be.visible')
+ .should('be.enabled')
+ .click(); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
selectAndAssignVolunteer(volunteerName: string) { | ||||||||||||||||||||||||||||
cy.clickAndSelectOption("#assign_volunteer", volunteerName); | ||||||||||||||||||||||||||||
cy.clickSubmitButton("Assign"); | ||||||||||||||||||||||||||||
cy.wait(2000); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
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 Replace hardcoded wait with explicit conditions The hardcoded selectAndAssignVolunteer(volunteerName: string) {
cy.clickAndSelectOption("#assign_volunteer", volunteerName);
cy.clickSubmitButton("Assign");
- cy.wait(2000);
+ // Wait for the assignment to complete
+ cy.get('#assigned-volunteer', { timeout: 10000 })
+ .should('be.visible')
+ .should('contain.text', volunteerName);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
verifyVolunteerBannerIsUpdated(volunteerName: string) { | ||||||||||||||||||||||||||||
cy.get("#assigned-volunteer") | ||||||||||||||||||||||||||||
.scrollIntoView() | ||||||||||||||||||||||||||||
.should("contain.text", `Assigned Volunteer:${volunteerName}`); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
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 Fix banner text verification and remove redundant scroll The banner text verification has formatting issues and unnecessary scrolling. verifyVolunteerBannerIsUpdated(volunteerName: string) {
cy.get("#assigned-volunteer")
- .scrollIntoView()
.should("contain.text",
- `Assigned Volunteer:${volunteerName}`
+ `Assigned Volunteer: ${volunteerName}`
);
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
unassignVolunteer() { | ||||||||||||||||||||||||||||
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.clickSubmitButton("Assign"); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
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 Improve method clarity and selector robustness
- unassignVolunteer() {
+ unassignAndPrepareForReassignment() {
cy.get("#clear-button")
.should("be.visible")
.find("svg")
.click();
- // Close the dropdown
- cy.get('button[id^="headlessui-combobox-button-"]').click();
+ // Use a more reliable selector for the dropdown
+ cy.get('[data-testid="volunteer-dropdown"]').click();
cy.clickSubmitButton("Assign");
}
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
verifyBannerIsRemovedAfterUnassign() { | ||||||||||||||||||||||||||||
cy.get("#assigned-volunteer").should("not.exist"); // Ensure the banner does not exist | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
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 timeout for banner removal verification The verification should account for potential delays in DOM updates. verifyBannerIsRemovedAfterUnassign() {
- cy.get("#assigned-volunteer").should("not.exist"); // Ensure the banner does not exist
+ cy.get("#assigned-volunteer", { timeout: 10000 }).should("not.exist");
} 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
} |
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