Skip to content

Commit

Permalink
Refactored Location Management Test
Browse files Browse the repository at this point in the history
  • Loading branch information
nihal467 committed Dec 4, 2024
1 parent a57480c commit 57f4c43
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 189 deletions.
10 changes: 4 additions & 6 deletions cypress/e2e/facility_spec/FacilityCreation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityHome from "../../pageobject/Facility/FacilityHome";
import LoginPage from "../../pageobject/Login/LoginPage";
import ManageUserPage from "../../pageobject/Users/ManageUserPage";
import { UserCreationPage } from "../../pageobject/Users/UserCreation";
import { nonAdminRoles } from "../../pageobject/utils/userConfig";

describe("Facility Creation", () => {
Expand All @@ -13,7 +12,6 @@ describe("Facility Creation", () => {
const loginPage = new LoginPage();
const facilityHome = new FacilityHome();
const manageUserPage = new ManageUserPage();
const userCreationPage = new UserCreationPage();
const facilityFeature = [
"CT Scan",
"X-Ray",
Expand Down Expand Up @@ -87,7 +85,7 @@ describe("Facility Creation", () => {
facilityPage.scrollToFacilityTriage();
facilityPage.clickAddFacilityTriage();
manageUserPage.clickSubmit();
userCreationPage.verifyErrorMessages(triageErrorMessage);
cy.verifyErrorMessages(triageErrorMessage);
// create a entry and verify reflection
facilityPage.fillEntryDate(triageDate);
facilityPage.fillTriageEntryFields(
Expand Down Expand Up @@ -123,7 +121,7 @@ describe("Facility Creation", () => {
// create facility with multiple capacity and verify form error message for facility form
facilityPage.visitCreateFacilityPage();
facilityPage.submitForm();
userCreationPage.verifyErrorMessages(facilityErrorMessage);
cy.verifyErrorMessages(facilityErrorMessage);
facilityPage.fillFacilityName(facilityName);
facilityPage.selectFacilityType(facilityType);
facilityPage.clickfacilityfeatureoption();
Expand Down Expand Up @@ -270,12 +268,12 @@ describe("Facility Creation", () => {
// add no bed capacity and verify form error message
facilityPage.isVisibleselectBedType();
facilityPage.saveAndExitBedCapacityForm();
userCreationPage.verifyErrorMessages(bedErrorMessage);
cy.verifyErrorMessages(bedErrorMessage);
facilityPage.clickcancelbutton();
// add no doctor capacity and verify form error message
facilityPage.isVisibleAreaOfSpecialization();
facilityPage.clickdoctorcapacityaddmore();
userCreationPage.verifyErrorMessages(doctorErrorMessage);
cy.verifyErrorMessages(doctorErrorMessage);
facilityPage.clickcancelbutton();
cy.url().then((newUrl) => {
facilityUrl1 = newUrl;
Expand Down
280 changes: 138 additions & 142 deletions cypress/e2e/facility_spec/FacilityLocation.cy.ts

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions cypress/pageobject/Facility/FacilityHome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ class FacilityHome {
cy.get('[data-test-id="occupancy-badge"]').should("be.visible");
}

verifyAndCloseNotifyModal() {
cy.get("#cancel").should("be.visible");
cy.get("#cancel").click();
}

navigateBack() {
cy.go(-1);
}
Expand Down
71 changes: 46 additions & 25 deletions cypress/pageobject/Facility/FacilityLocation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
class FacilityLocation {
loadLocationManagementPage(name: string) {
cy.awaitUrl("/");
cy.intercept("GET", "**/api/v1/facility/**").as("getFacilities");
cy.get("[id='facility-name-card']").contains(name).click();
cy.wait("@getFacilities").its("response.statusCode").should("eq", 200);
cy.get("h1.text-3xl.font-bold", { timeout: 10000 }).should("be.visible");
cy.get("#manage-facility-dropdown button").should("be.visible");
cy.get("[id='manage-facility-dropdown']").scrollIntoView().click();
cy.get("[id=location-management]").click();
}

closeNotification() {
cy.get(".pnotify")
.should("exist")
Expand All @@ -22,10 +11,18 @@ class FacilityLocation {
cy.get("#add-new-location").click();
}

typeLocationName(locationName: string) {
cy.get("#location-name").type(locationName);
}

clickFacilityLocationManagement() {
cy.get("[id=location-management]").click();
}

clickAddLocationButton() {
cy.clickSubmitButton("Add Location");
}

clickEditLocationButton() {
cy.get("#edit-location-button").click();
}
Expand Down Expand Up @@ -63,10 +60,6 @@ class FacilityLocation {
cy.get("#location-type").contains(type);
}

verifyNotification(message: string) {
cy.get(".pnotify-container").should("contain", message).and("be.visible");
}

verifyLocationDescription(description: string) {
cy.get("#view-location-description").contains(description);
}
Expand All @@ -76,15 +69,39 @@ class FacilityLocation {
}

clickManageBedButton() {
cy.get("#manage-bed-button").first().click();
cy.verifyAndClickElement("#manage-bed-button", "Manage Beds");
}

clickAddBedButton() {
cy.get("#add-new-bed").click();
cy.verifyAndClickElement("#add-new-bed", "Add New Bed(s)");
}

clickSubmitBedsButton() {
cy.clickSubmitButton("Add Bed(s)");
}

closeAddLocationForm() {
cy.clickCancelButton("Cancel");
}

clickNotification() {
cy.get(".pnotify-container").click();
verifyAddLocationSuccessfulMesssage() {
cy.verifyNotification("Location created successfully");
cy.closeNotification();
}

verifyEditBedSuccessfulMessage() {
cy.verifyNotification("Bed updated successfully");
cy.closeNotification();
}

verifyEditLocationSuccessfulMessage() {
cy.verifyNotification("Location updated successfully");
cy.closeNotification();
}

verifyAddSingleBedSuccessfulMesssage() {
cy.verifyNotification("1 Bed created successfully");
cy.closeNotification();
}

enterBedName(name: string) {
Expand All @@ -95,6 +112,14 @@ class FacilityLocation {
cy.get("#bed-description").clear().click().type(description);
}

clickUpdateBedButton() {
cy.clickSubmitButton("Update Bed");
}

clickUpdateLocationButton() {
cy.clickSubmitButton("Update Location");
}

selectBedType(type: string) {
cy.get("#bed-type").click();
cy.get("li[role=option]").contains(type).click();
Expand Down Expand Up @@ -136,12 +161,8 @@ class FacilityLocation {
cy.get("#manage-assets").click();
}

deleteLocation(name: string) {
cy.contains("div", name)
.should("exist")
.then(($div) => {
$div.parents("div").eq(2).find("button#delete-location-button").click();
});
clickDeleteLocation() {
cy.verifyAndClickElement("#delete-location-button", "Delete");
}

deleteFirstBed() {
Expand Down
11 changes: 0 additions & 11 deletions cypress/pageobject/Users/UserCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,4 @@ export class UserCreationPage {
clickSaveUserButton() {
cy.clickSubmitButton("Save User");
}

verifyErrorMessages(errorMessages: string[]) {
cy.get(".error-text").then(($errors) => {
const displayedErrorMessages = $errors
.map((_, el) => Cypress.$(el).text())
.get();
errorMessages.forEach((errorMessage) => {
expect(displayedErrorMessages).to.include(errorMessage);
});
});
}
}
12 changes: 12 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,15 @@ Cypress.Commands.add("verifyContentPresence", (selector, texts) => {
});
});
});

Cypress.Commands.add("verifyErrorMessages", (errorMessages: string[]) => {
const selector = ".error-text"; // Static selector
cy.get(selector).then(($errors) => {
const displayedErrorMessages = $errors
.map((_, el) => Cypress.$(el).text())
.get();
errorMessages.forEach((errorMessage) => {
expect(displayedErrorMessages).to.include(errorMessage);
});
});
});
1 change: 1 addition & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare global {
selector: string,
texts: string[],
): Chainable<Element>;
verifyErrorMessages(errorMessages: string[]): Chainable<Subject>;
}
}
}
1 change: 1 addition & 0 deletions src/components/Facility/AddLocationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const AddLocationForm = ({ facilityId, locationId }: Props) => {
<div className="mt-2 grid grid-cols-1 gap-4">
<div>
<TextFormField
id="location-name"
name="name"
type="text"
label="Name"
Expand Down

0 comments on commit 57f4c43

Please sign in to comment.