Skip to content

Commit

Permalink
Add Cypress Test Suit to Verify Notify Facility
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidSumra committed Nov 7, 2024
1 parent c27f595 commit 66d6ef4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 11 deletions.
52 changes: 44 additions & 8 deletions cypress/e2e/facility_spec/FacilityHomepage.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// FacilityCreation

import LoginPage from "../../pageobject/Login/LoginPage";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import FacilityHome from "../../pageobject/Facility/FacilityHome";
import { FacilityNotify } from "../../pageobject/Facility/FacilityNotify";
import LoginPage from "../../pageobject/Login/LoginPage";
import ManageUserPage from "../../pageobject/Users/ManageUserPage";
import FacilityPage from "../../pageobject/Facility/FacilityCreation";
import { UserPage } from "../../pageobject/Users/UserSearch";
import { AssetPagination } from "../../pageobject/Asset/AssetPagination";

describe("Facility Homepage Function", () => {
const loginPage = new LoginPage();
const facilityHome = new FacilityHome();
const facilityNotify = new FacilityNotify();
const facilityPage = new FacilityPage();
const manageUserPage = new ManageUserPage();
const userPage = new UserPage();
Expand All @@ -23,7 +24,9 @@ describe("Facility Homepage Function", () => {
const district = "Ernakulam";
const localBody = "Aikaranad";
const facilityType = "Private Hospital";

const notificationErrorMsg = "Message cannot be empty";
const noitificationMessage =
"Reminder: The monthly report submission deadline is on 15th Nov. Ensure all entries are updated.";
before(() => {
loginPage.loginAsDistrictAdmin();
cy.saveLocalStorage();
Expand All @@ -42,9 +45,6 @@ describe("Facility Homepage Function", () => {
facilityHome.clickViewCnsButton();
facilityHome.verifyCnsUrl();
facilityHome.navigateBack();
// view notify button
facilityHome.clickFacilityNotifyButton();
facilityHome.verifyAndCloseNotifyModal();
// view facility button
facilityHome.clickViewFacilityDetails();
facilityPage.getFacilityName().should("be.visible");
Expand Down Expand Up @@ -135,6 +135,42 @@ describe("Facility Homepage Function", () => {
facilityHome.verifyLiveMonitorUrl();
});

it("Verify Notice Board Functionality", () => {
// search facility and verify it's loaded or not
facilityNotify.interceptFacilitySearchReq();
manageUserPage.typeFacilitySearch(facilityName);
facilityNotify.verifyFacilitySearchReq();
// verify facility name and notify button and click it
manageUserPage.assertFacilityInCard(facilityName);
facilityHome.clickFacilityNotifyButton();
// check visiblity of pop-up and frontend error on empty message
cy.verifyContentPresence("#notify-facility-name", [facilityName]);
cy.submitButton("Notify");
cy.verifyContentPresence(".error-text", [notificationErrorMsg]);
// close pop-up and verify
facilityHome.verifyAndCloseNotifyModal();
// send notification
facilityHome.clickFacilityNotifyButton();
facilityNotify.fillNotifyText(noitificationMessage);
facilityNotify.interceptPostNotificationReq();
cy.submitButton("Notify");
cy.verifyNotification("Facility Notified");
facilityNotify.verifyPostNotificationReq();
// signout as district admin and login as a Nurse
loginPage.ensureLoggedIn();
loginPage.clickSignOutBtn();
loginPage.loginManuallyAsNurse();
// Visit Notification Sidebar
facilityNotify.interceptGetNotificationReq();
facilityNotify.visitNoticeBoard();
facilityNotify.verifyGetNotificationReq();
cy.verifyContentPresence("#notification-message", [noitificationMessage]);
facilityNotify.interceptGetNotificationReq();
cy.verifyAndClickElement("#notification-slide-btn", "Notifications");
facilityNotify.verifyGetNotificationReq();
cy.verifyContentPresence("#notification-slide-msg", [noitificationMessage]);
});

afterEach(() => {
cy.saveLocalStorage();
});
Expand Down
36 changes: 36 additions & 0 deletions cypress/pageobject/Facility/FacilityNotify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export class FacilityNotify {
fillNotifyText(message: string): void {
cy.get("#NotifyModalMessageInput").should("be.visible").type(message);
}

visitNoticeBoard(): void {
cy.get("a[href='/notice_board']").should("be.visible").click();
}

visitNotificationSideBar(): void {
cy.get("#notification-slide-btn").should("be.visible").click();
}

interceptFacilitySearchReq(): void {
cy.intercept("GET", "**/api/v1/facility/**").as("searchFacility");
}
verifyFacilitySearchReq(): void {
cy.wait("@searchFacility").its("response.statusCode").should("eq", 200);
}

interceptPostNotificationReq(): void {
cy.intercept("POST", "**/api/v1/notification/notify").as("notifyFacility");
}

verifyPostNotificationReq(): void {
cy.wait("@notifyFacility").its("response.statusCode").should("eq", 204);
}

interceptGetNotificationReq(): void {
cy.intercept("GET", "**/api/v1/notification/**").as("getNotifications");
}

verifyGetNotificationReq(): void {
cy.wait("@getNotifications").its("response.statusCode").should("eq", 200);
}
}
4 changes: 4 additions & 0 deletions cypress/pageobject/Login/LoginPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class LoginPage {
cy.get("#sign-out-button").scrollIntoView();
cy.get("#sign-out-button").contains("Sign Out").should("exist");
}

clickSignOutBtn(): void {
cy.verifyAndClickElement("#sign-out-button", "Sign Out");
}
}

export default LoginPage;
2 changes: 2 additions & 0 deletions src/components/Common/Sidebar/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type SidebarItemProps = {

type SidebarItemBaseProps = SidebarItemProps & {
shrinked?: boolean;
id?: string;
};

const SidebarItemBase = forwardRef<HTMLAnchorElement, SidebarItemBaseProps>(
Expand All @@ -31,6 +32,7 @@ const SidebarItemBase = forwardRef<HTMLAnchorElement, SidebarItemBaseProps>(
return (
<Link
ref={ref}
id={props?.id}
className={`tooltip relative ml-1 mr-2 h-12 flex-1 cursor-pointer rounded-md py-1 font-medium text-gray-600 transition md:flex-none ${
props.selected
? "bg-white text-green-800 shadow"
Expand Down
5 changes: 4 additions & 1 deletion src/components/Facility/FacilityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ export const FacilityCard = (props: {
<DialogModal
show={notifyModalFor === facility.id}
title={
<span className="flex justify-center text-2xl">
<span
className="flex justify-center text-2xl"
id="notify-facility-name"
>
Notify: {facility.name}
</span>
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Notifications/NoticeBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export const NoticeBoard = () => {
className="overflow-hidden rounded shadow-md"
>
<div className="px-6 py-4">
<div className="text-justify text-lg">{item.message}</div>
<div className="text-justify text-lg" id="notification-message">
{item.message}
</div>
<div className="text-md my-2 text-secondary-700">
{formatName(item.caused_by)} -{" "}
<span className="font-bold text-primary-700">
Expand Down
5 changes: 4 additions & 1 deletion src/components/Notifications/NotificationsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ const NotificationTile = ({
/>
</div>
</div>
<div className="py-1 text-sm">{result.message}</div>
<div className="py-1 text-sm" id="notification-slide-msg">
{result.message}
</div>
<div className="flex flex-col justify-end gap-2">
<div className="py-1 text-right text-xs text-secondary-700">
{formatDateTime(result.created_date)}
Expand Down Expand Up @@ -474,6 +476,7 @@ export default function NotificationsList({
<>
<Item
text={t("Notifications")}
id="notification-slide-btn"
do={() => setOpen(!open)}
icon={<CareIcon icon="l-bell" className="h-5" />}
badgeCount={unreadCount}
Expand Down

0 comments on commit 66d6ef4

Please sign in to comment.