-
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 cypress tests for Facility cover image button functionality #9134
Changes from all commits
5ae7257
8e76e29
ae6c1ba
f910767
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,56 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
import FacilityPage from "../../pageobject/Facility/FacilityCreation"; | ||||||||||||||||||||||||||||||||||||||||||||||
import FacilityManage from "../../pageobject/Facility/FacilityManage"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
const roleUserFacilities = [ | ||||||||||||||||||||||||||||||||||||||||||||||
{ username: "devdistrictadmin", facilityName: "Dummy Facility 40" }, | ||||||||||||||||||||||||||||||||||||||||||||||
{ username: "devdoctor", facilityName: "Dummy Facility 4" }, | ||||||||||||||||||||||||||||||||||||||||||||||
]; | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
roleUserFacilities.forEach(({ username, facilityName }) => { | ||||||||||||||||||||||||||||||||||||||||||||||
describe("Facility Cover Image Functionality", () => { | ||||||||||||||||||||||||||||||||||||||||||||||
const facilityManage = new FacilityManage(); | ||||||||||||||||||||||||||||||||||||||||||||||
const facilityPage = new FacilityPage(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
before(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
cy.loginByApi(username, "Coronasafe@123"); | ||||||||||||||||||||||||||||||||||||||||||||||
cy.saveLocalStorage(); | ||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
beforeEach(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
cy.viewport(1280, 720); | ||||||||||||||||||||||||||||||||||||||||||||||
cy.restoreLocalStorage(); | ||||||||||||||||||||||||||||||||||||||||||||||
cy.clearLocalStorage(/filters--.+/); | ||||||||||||||||||||||||||||||||||||||||||||||
cy.awaitUrl("/"); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityPage.typeFacilitySearch(facilityName); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityPage.verifyFacilityBadgeContent(facilityName); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityPage.visitAlreadyCreatedFacility(); | ||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+19
to
+27
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. Implement API intercepts as specified in PR objectives The PR objectives mention using Add API intercepts before navigation: beforeEach(() => {
cy.viewport(1280, 720);
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
+ cy.intercept('GET', '/api/v1/facility/*').as('getFacility');
+ cy.intercept('POST', '/api/v1/facility/*/cover_image').as('uploadCoverImage');
+ cy.intercept('DELETE', '/api/v1/facility/*/cover_image').as('deleteCoverImage');
cy.awaitUrl("/");
facilityPage.typeFacilitySearch(facilityName);
facilityPage.verifyFacilityBadgeContent(facilityName);
facilityPage.visitAlreadyCreatedFacility();
+ cy.wait('@getFacility');
}); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
it("Facility Cover Image button functionality", () => { | ||||||||||||||||||||||||||||||||||||||||||||||
// It's only button functionality because we can't access S3 bucket in local | ||||||||||||||||||||||||||||||||||||||||||||||
// Check: Cancel button functionality | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickCancelButton(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.verifyCoverImageModalClosed(); | ||||||||||||||||||||||||||||||||||||||||||||||
// Check: upload an image, verifying the API response. | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.verifyUploadButtonVisible(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.uploadCoverImage("facility-cover-image.jpg"); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickSaveCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.verifyCoverImageModalClosed(); | ||||||||||||||||||||||||||||||||||||||||||||||
// //Check: Edit the current cover image by uploading a new one, and verify the API response. | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.verifyUploadButtonVisible(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.uploadCoverImage("new-facility-cover-image.jpg"); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickSaveCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.verifyCoverImageModalClosed(); | ||||||||||||||||||||||||||||||||||||||||||||||
//Check: Delete the existing cover image, confirming the API response. | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
facilityManage.clickDeleteCoverImage(); | ||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+29
to
+50
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. Enhance test assertions and API verifications The test case lacks proper assertions after API calls and UI state verifications. Add assertions and API verifications: it("Facility Cover Image button functionality", () => {
- // It's only button functionality because we can't access S3 bucket in local
+ // Note: This test verifies UI interactions and API calls without actual S3 bucket operations
+ // as S3 access is not available in local development environment
// Check: Cancel button functionality
facilityManage.clickCoverImage();
facilityManage.clickCancelButton();
facilityManage.verifyCoverImageModalClosed();
// Check: upload an image, verifying the API response.
facilityManage.clickCoverImage();
facilityManage.verifyUploadButtonVisible();
facilityManage.uploadCoverImage("facility-cover-image.jpg");
facilityManage.clickSaveCoverImage();
+ cy.wait('@uploadCoverImage').its('response.statusCode').should('eq', 200);
facilityManage.verifyCoverImageModalClosed();
+ facilityManage.verifyCoverImageVisible();
// Check: Edit the current cover image
facilityManage.clickCoverImage();
facilityManage.verifyUploadButtonVisible();
facilityManage.uploadCoverImage("new-facility-cover-image.jpg");
facilityManage.clickSaveCoverImage();
+ cy.wait('@uploadCoverImage').its('response.statusCode').should('eq', 200);
facilityManage.verifyCoverImageModalClosed();
+ facilityManage.verifyCoverImageVisible();
// Check: Delete the existing cover image
facilityManage.clickCoverImage();
facilityManage.clickDeleteCoverImage();
+ cy.wait('@deleteCoverImage').its('response.statusCode').should('eq', 200);
+ facilityManage.verifyCoverImageNotVisible();
});
|
||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||
afterEach(() => { | ||||||||||||||||||||||||||||||||||||||||||||||
cy.saveLocalStorage(); | ||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+52
to
+54
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 proper test cleanup The test should clean up any resources it creates to maintain test isolation. afterEach(() => {
cy.saveLocalStorage();
+ // Clean up any uploaded images to maintain test isolation
+ cy.get('@deleteCoverImage').then((interception) => {
+ if (interception) {
+ facilityManage.clickCoverImage();
+ facilityManage.clickDeleteCoverImage();
+ cy.wait('@deleteCoverImage');
+ }
+ });
});
|
||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||
}); |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,10 +1,20 @@ | ||||||||||||||||||||||||||||
/// <reference types="cypress" /> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
class FacilityManage { | ||||||||||||||||||||||||||||
clickCoverImage() { | ||||||||||||||||||||||||||||
cy.get("#facility-coverimage").click(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
clickCancelButton() { | ||||||||||||||||||||||||||||
cy.get("#cancel").scrollIntoView().should("be.visible").click(); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+8
to
+10
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 Use a more specific selector for the cancel button The current selector '#cancel' is too generic and could match unintended elements on the page. Consider using a more specific selector that includes the context of the cover image modal. - cy.get("#cancel").scrollIntoView().should("be.visible").click();
+ cy.get("[data-testid='cover-image-modal-cancel']").scrollIntoView().should("be.visible").click(); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
verifyCoverImageModalClosed() { | ||||||||||||||||||||||||||||
cy.get("#upload-cover-image").should("not.exist"); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+12
to
+14
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 Verify modal closure using the modal container The current implementation checks for the upload button's non-existence, which might not accurately represent whether the modal is closed. Consider checking the modal container element instead. - cy.get("#upload-cover-image").should("not.exist");
+ cy.get("[data-testid='cover-image-modal']").should("not.exist");
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
verifyUploadButtonVisible() { | ||||||||||||||||||||||||||||
cy.get("#upload-cover-image").should("be.visible"); | ||||||||||||||||||||||||||||
cy.get("#upload-cover-image").scrollIntoView().should("be.visible"); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
uploadCoverImage(fileName: string) { | ||||||||||||||||||||||||||||
|
@@ -14,8 +24,16 @@ class FacilityManage { | |||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
clickSaveCoverImage() { | ||||||||||||||||||||||||||||
cy.get("#save-cover-image").scrollIntoView(); | ||||||||||||||||||||||||||||
cy.get("#save-cover-image").click(); | ||||||||||||||||||||||||||||
cy.intercept("POST", "**/api/v1/facility/**").as("uploadCoverImage"); | ||||||||||||||||||||||||||||
cy.get("#save-cover-image").scrollIntoView().click(); | ||||||||||||||||||||||||||||
cy.wait("@uploadCoverImage").its("response.statusCode").should("eq", 200); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+27
to
+30
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 API intercept and error handling The current implementation has several areas for improvement:
- cy.intercept("POST", "**/api/v1/facility/**").as("uploadCoverImage");
- cy.get("#save-cover-image").scrollIntoView().click();
- cy.wait("@uploadCoverImage").its("response.statusCode").should("eq", 200);
+ cy.intercept("POST", "**/api/v1/facility/*/cover_image").as("uploadCoverImage");
+ cy.get("#save-cover-image").scrollIntoView().should("be.visible").click();
+ cy.wait("@uploadCoverImage").then((interception) => {
+ if (interception.response?.statusCode !== 200) {
+ throw new Error(`Failed to upload cover image: ${interception.response?.statusCode}`);
+ }
+ }); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
clickDeleteCoverImage() { | ||||||||||||||||||||||||||||
cy.intercept("DELETE", "**/api/v1/facility/**").as("deleteCoverImage"); | ||||||||||||||||||||||||||||
cy.get("#delete-cover-image").scrollIntoView(); | ||||||||||||||||||||||||||||
cy.get("#delete-cover-image").click(); | ||||||||||||||||||||||||||||
cy.wait("@deleteCoverImage").its("response.statusCode").should("eq", 204); | ||||||||||||||||||||||||||||
Comment on lines
+32
to
+36
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 duplicate scrollIntoView and improve error handling The current implementation has several issues:
- cy.intercept("DELETE", "**/api/v1/facility/**").as("deleteCoverImage");
- cy.get("#delete-cover-image").scrollIntoView();
- cy.get("#delete-cover-image").click();
- cy.wait("@deleteCoverImage").its("response.statusCode").should("eq", 204);
+ cy.intercept("DELETE", "**/api/v1/facility/*/cover_image").as("deleteCoverImage");
+ cy.get("#delete-cover-image").scrollIntoView().should("be.visible").click();
+ cy.wait("@deleteCoverImage").then((interception) => {
+ if (interception.response?.statusCode !== 204) {
+ throw new Error(`Failed to delete cover image: ${interception.response?.statusCode}`);
+ }
+ }); 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
verifyTotalDoctorCapacity(expectedCapacity: string) { | ||||||||||||||||||||||||||||
|
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.
🛠️ Refactor suggestion
Add error handling for login failures
The login step should handle potential failures gracefully.
📝 Committable suggestion