Skip to content

Commit

Permalink
New Cypress Test | Facility Location and Bed Management | Facility Mo…
Browse files Browse the repository at this point in the history
…dule (#6907)

* add-location-conversion

* bed-test

* single bed addition and updation

* final multiple bed

* final test change

* revert vite
  • Loading branch information
nihal467 authored Dec 25, 2023
1 parent 97ca611 commit c74c2f3
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 29 deletions.
147 changes: 125 additions & 22 deletions cypress/e2e/facility_spec/locations.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
import { afterEach, before, beforeEach, cy, describe, it } from "local-cypress";
import { AssetPage } from "../../pageobject/Asset/AssetCreation";
import { UserCreationPage } from "../../pageobject/Users/UserCreation";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityLocation from "../../pageobject/Facility/FacilityLocation";
// import { AssetPagination } from "../../pageobject/Asset/AssetPagination";

describe("Location Management Section", () => {
const assetPage = new AssetPage();
const userCreationPage = new UserCreationPage();
const facilityPage = new FacilityPage();
const facilityLocation = new FacilityLocation();
// const assetPagination = new AssetPagination();
const EXPECTED_LOCATION_ERROR_MESSAGES = [
"Name is required",
"Location Type is required",
];
const EXPECTED_BED_ERROR_MESSAGES = [
"Please enter a name",
"Please select a bed type",
];
const locationName = "Test-location";
const locationDescription = "Test Description";
const locationType = "WARD";
const locationMiddleware = "dev_middleware.coronasafe.live";
const locationModifiedName = "Test Modified location";
const locationModifiedDescription = "Test Modified Description";
const locationModifiedType = "ICU";
const locationModifiedMiddleware = "dev-middleware.coronasafe.live";
const bedName = "Test Bed";
const bedDescrption = "test description";
const bedType = "ICU";
const bedStatus = "Vacant";
const bedModifiedName = "test modified bed";
const bedModifiedDescrption = "test modified description";
const bedModifiedType = "Isolation";
const numberOfBeds = 10;
// const numberOfModifiedBeds = 25;

before(() => {
cy.loginByApi("devdistrictadmin", "Coronasafe@123");
cy.saveLocalStorage();
Expand All @@ -20,28 +56,95 @@ describe("Location Management Section", () => {
cy.get("[id=location-management]").click();
});

it("Adds Location", () => {
cy.contains("Add New Location").click();
cy.get("[name='name']").type("Test Location");
cy.get("textarea[name='description']").type("Test Description");
cy.get("#location-type").click();
cy.get("#location-type-option-ICU").click();
cy.intercept(/\/api\/v1\/facility\/[\w-]+\/asset_location\//).as(
"addLocation"
);
cy.get("button").contains("Add Location").click();
cy.wait("@addLocation").then((interception) => {
switch (interception?.response?.statusCode) {
case 201:
cy.verifyNotification("Location created successfully");
return;
case 400:
cy.verifyNotification(
"Name - Asset location with this name and facility already exists."
);
return;
}
});
it("Adds Location to a facility and modify it", () => {
// add a new location form mandatory error
facilityLocation.clickAddNewLocationButton();
assetPage.clickassetupdatebutton();
userCreationPage.verifyErrorMessages(EXPECTED_LOCATION_ERROR_MESSAGES);
// create a new location
facilityPage.fillFacilityName(locationName);
facilityLocation.fillDescription(locationDescription);
facilityLocation.selectLocationType(locationType);
facilityLocation.fillMiddlewareAddress(locationMiddleware);
assetPage.clickassetupdatebutton();
// verify the reflection
facilityLocation.verifyLocationName(locationName);
facilityLocation.verifyLocationType(locationType);
facilityLocation.verifyLocationDescription(locationDescription);
facilityLocation.verifyLocationMiddleware(locationMiddleware);
// modify the existing data
facilityLocation.clickEditLocationButton();
facilityPage.fillFacilityName(locationModifiedName);
facilityLocation.fillDescription(locationModifiedDescription);
facilityLocation.selectLocationType(locationModifiedType);
facilityLocation.fillMiddlewareAddress(locationModifiedMiddleware);
assetPage.clickassetupdatebutton();
// verify the reflection
facilityLocation.verifyLocationName(locationModifiedName);
facilityLocation.verifyLocationType(locationModifiedType);
facilityLocation.verifyLocationDescription(locationModifiedDescription);
facilityLocation.verifyLocationMiddleware(locationModifiedMiddleware);
});

it("Add Multiple Bed to a facility location and delete a bed", () => {
// create multiple bed and verify
facilityLocation.clickManageBedButton();
facilityLocation.clickAddBedButton();
facilityLocation.enterBedName(bedName);
facilityLocation.enterBedDescription(bedDescrption);
facilityLocation.selectBedType(bedType);
facilityLocation.setMultipleBeds(numberOfBeds);
assetPage.clickassetupdatebutton();
// verify the bed creation
facilityLocation.verifyBedBadge(bedType);
facilityLocation.verifyBedBadge(bedStatus);
facilityLocation.verifyIndividualBedName(bedName, numberOfBeds);
// delete a bed and verify it
facilityLocation.deleteFirstBed();
facilityLocation.deleteBedRequest();
assetPage.clickassetupdatebutton();
facilityLocation.deleteBedRequest();
});

// it("Add Multiple Bed to a facility location and verify pagination", () => {
// // bed creation
// facilityLocation.clickManageBedButton();
// facilityLocation.clickAddBedButton();
// facilityLocation.enterBedName(bedModifiedName);
// facilityLocation.enterBedDescription(bedModifiedDescrption);
// facilityLocation.selectBedType(bedModifiedType);
// facilityLocation.setMultipleBeds(numberOfModifiedBeds);
// assetPage.clickassetupdatebutton();
// // pagination
// assetPagination.navigateToNextPage();
// assetPagination.navigateToPreviousPage();
// }); need to be unblocked upon issue #6906 is solved

it("Add Single Bed to a facility location and modify it", () => {
// mandatory field verification in bed creation
facilityLocation.clickManageBedButton();
facilityLocation.clickAddBedButton();
assetPage.clickassetupdatebutton();
userCreationPage.verifyErrorMessages(EXPECTED_BED_ERROR_MESSAGES);
// create a new single bed and verify
facilityLocation.enterBedName(bedName);
facilityLocation.enterBedDescription(bedDescrption);
facilityLocation.selectBedType(bedType);
assetPage.clickassetupdatebutton();
// Verify the bed creation
facilityLocation.verifyBedNameBadge(bedName);
facilityLocation.verifyBedBadge(bedType);
facilityLocation.verifyBedBadge(bedStatus);
// edit the created bed
facilityLocation.clickEditBedButton();
facilityLocation.enterBedName(bedModifiedName);
facilityLocation.enterBedDescription(bedModifiedDescrption);
facilityLocation.selectBedType(bedModifiedType);
assetPage.clickassetupdatebutton();
// verify the modification
facilityLocation.verifyBedNameBadge(bedModifiedName);
facilityLocation.verifyBedBadge(bedModifiedType);
facilityLocation.verifyBedBadge(bedStatus);
});

afterEach(() => {
Expand Down
105 changes: 105 additions & 0 deletions cypress/pageobject/Facility/FacilityLocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
class FacilityLocation {
clickAddNewLocationButton() {
cy.get("#add-new-location").click();
}

clickEditLocationButton() {
cy.get("#edit-location-button").click();
}

clickEditBedButton() {
cy.get("#edit-bed-button").click();
}

fillDescription(description: string) {
cy.get("#description").clear().click().type(description);
}

selectLocationType(type: string) {
cy.get("#location-type").click();
cy.get("li[role=option]").contains(type).click();
}

fillMiddlewareAddress(address: string) {
cy.get("#location-middleware-address").clear().click().type(address);
}

verifyLocationName(name: string) {
cy.get("#view-location-name").contains(name);
}

verifyLocationType(type: string) {
cy.get("#location-type").contains(type);
}

verifyLocationDescription(description: string) {
cy.get("#view-location-description").contains(description);
}

verifyLocationMiddleware(middleware: string) {
cy.get("#view-location-middleware").contains(middleware);
}

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

clickAddBedButton() {
cy.get("#add-new-bed").click();
}

enterBedName(name: string) {
cy.get("#bed-name").clear().click().type(name);
}

enterBedDescription(description: string) {
cy.get("#bed-description").clear().click().type(description);
}

selectBedType(type: string) {
cy.get("#bed-type").click();
cy.get("li[role=option]").contains(type).click();
}

setMultipleBeds(numberOfBeds: number) {
if (numberOfBeds > 1) {
cy.get("#multiplebed-checkbox").click();
cy.get("#numberofbed")
.click()
.clear()
.click()
.type(numberOfBeds.toString());
}
}

verifyBedBadge(badge: string) {
cy.get("#view-bedbadges").contains(badge);
}

verifyBedNameBadge(name: string) {
cy.get("#view-bed-name").contains(name);
}

verifyIndividualBedName(baseName: string, totalBeds: number) {
for (let i = 1; i <= totalBeds; i++) {
const expectedName = `${baseName} ${i}`;
cy.get("p#view-bed-name.inline.break-words.text-xl.capitalize")
.should("be.visible")
.contains(expectedName);
}
}

deleteFirstBed() {
cy.get("#delete-bed-button").first().click();
}

deleteBedRequest() {
cy.intercept("DELETE", "**/api/v1/bed/**").as("deleteRequest");
}

deleteBedResponse() {
cy.wait("@deleteRequest").its("response.statusCode").should("eq", 204);
}
}

export default FacilityLocation;
5 changes: 4 additions & 1 deletion src/Components/Facility/AddBedForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,14 @@ export const AddBedForm = (props: BedFormProps) => {
name="name"
type="text"
label="Name"
id="name"
id="bed-name"
required
value={name}
onChange={(e) => setName(e.value)}
error={errors.name}
/>
<TextAreaFormField
id="bed-description"
rows={5}
label="Description"
name="description"
Expand All @@ -215,6 +216,7 @@ export const AddBedForm = (props: BedFormProps) => {
{!bedId && (
<>
<CheckBoxFormField
id="multiplebed-checkbox"
label="Do you want to make multiple beds?"
onChange={() => {
if (multipleBeds) setNumberOfBeds(1);
Expand All @@ -223,6 +225,7 @@ export const AddBedForm = (props: BedFormProps) => {
name={"multipleBeds"}
/>
<TextFormField
id="numberofbed"
name="number_of_beds"
disabled={!multipleBeds}
label="Number of beds"
Expand Down
1 change: 1 addition & 0 deletions src/Components/Facility/AddLocationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const AddLocationForm = (props: LocationFormProps) => {
</div>
<div>
<TextFormField
id="location-middleware-address"
name="Location Middleware Address"
type="text"
label="Location Middleware Address"
Expand Down
12 changes: 10 additions & 2 deletions src/Components/Facility/BedManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ const BedRow = (props: BedRowProps) => {
>
<div className="mt-2 space-y-2 px-4 lg:w-3/4">
<div className="flex flex-col sm:flex-row">
<p className="inline break-words text-xl capitalize">{name}</p>{" "}
<p
className="inline break-words text-xl capitalize"
id="view-bed-name"
>
{name}
</p>{" "}
&nbsp;
<div>
<div id="view-bedbadges">
{LOCATION_BED_TYPES.find((item) => item.id === bedType) && (
<p className="mb-1 inline-flex w-fit items-center rounded-md bg-blue-100 px-2.5 py-0.5 text-sm font-medium capitalize leading-5 text-blue-800">
{LOCATION_BED_TYPES.find(
Expand All @@ -119,6 +124,7 @@ const BedRow = (props: BedRowProps) => {
</div>
<div className="mt-4 flex flex-col gap-2 lg:mt-0 lg:flex-row">
<ButtonV2
id="edit-bed-button"
href={`/facility/${facilityId}/location/${locationId}/beds/${id}/update`}
authorizeFor={NonReadOnlyUsers}
className="w-full lg:w-auto"
Expand All @@ -130,6 +136,7 @@ const BedRow = (props: BedRowProps) => {
Edit
</ButtonV2>
<ButtonV2
id="delete-bed-button"
onClick={() => handleDelete(name, id)}
authorizeFor={NonReadOnlyUsers}
variant="danger"
Expand Down Expand Up @@ -272,6 +279,7 @@ export const BedManagement = (props: BedManagementProps) => {
<div className="container mx-auto px-4 py-2 sm:px-8">
<div className="flex justify-end">
<ButtonV2
id="add-new-bed"
href={`/facility/${facilityId}/location/${locationId}/beds/add`}
authorizeFor={NonReadOnlyUsers}
>
Expand Down
Loading

0 comments on commit c74c2f3

Please sign in to comment.