From 66d6ef405c82f2fd8548739e685b3ce8cc313cb1 Mon Sep 17 00:00:00 2001 From: JavidSumra Date: Thu, 7 Nov 2024 18:09:09 +0530 Subject: [PATCH 1/3] Add Cypress Test Suit to Verify Notify Facility --- .../e2e/facility_spec/FacilityHomepage.cy.ts | 52 ++++++++++++++++--- cypress/pageobject/Facility/FacilityNotify.ts | 36 +++++++++++++ cypress/pageobject/Login/LoginPage.ts | 4 ++ src/components/Common/Sidebar/SidebarItem.tsx | 2 + src/components/Facility/FacilityCard.tsx | 5 +- src/components/Notifications/NoticeBoard.tsx | 4 +- .../Notifications/NotificationsList.tsx | 5 +- 7 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 cypress/pageobject/Facility/FacilityNotify.ts diff --git a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts index e6caf645f7a..f6e0c1759ef 100644 --- a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts +++ b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts @@ -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(); @@ -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(); @@ -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"); @@ -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(); }); diff --git a/cypress/pageobject/Facility/FacilityNotify.ts b/cypress/pageobject/Facility/FacilityNotify.ts new file mode 100644 index 00000000000..c0f7d54f4f3 --- /dev/null +++ b/cypress/pageobject/Facility/FacilityNotify.ts @@ -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); + } +} diff --git a/cypress/pageobject/Login/LoginPage.ts b/cypress/pageobject/Login/LoginPage.ts index cd5230a7772..38b8aeee2af 100644 --- a/cypress/pageobject/Login/LoginPage.ts +++ b/cypress/pageobject/Login/LoginPage.ts @@ -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; diff --git a/src/components/Common/Sidebar/SidebarItem.tsx b/src/components/Common/Sidebar/SidebarItem.tsx index 31f64754ffd..7d91e56dd76 100644 --- a/src/components/Common/Sidebar/SidebarItem.tsx +++ b/src/components/Common/Sidebar/SidebarItem.tsx @@ -21,6 +21,7 @@ type SidebarItemProps = { type SidebarItemBaseProps = SidebarItemProps & { shrinked?: boolean; + id?: string; }; const SidebarItemBase = forwardRef( @@ -31,6 +32,7 @@ const SidebarItemBase = forwardRef( return ( + Notify: {facility.name} } diff --git a/src/components/Notifications/NoticeBoard.tsx b/src/components/Notifications/NoticeBoard.tsx index e4472107c8f..e1f00075000 100644 --- a/src/components/Notifications/NoticeBoard.tsx +++ b/src/components/Notifications/NoticeBoard.tsx @@ -26,7 +26,9 @@ export const NoticeBoard = () => { className="overflow-hidden rounded shadow-md" >
-
{item.message}
+
+ {item.message} +
{formatName(item.caused_by)} -{" "} diff --git a/src/components/Notifications/NotificationsList.tsx b/src/components/Notifications/NotificationsList.tsx index 5d88cc8d603..0808877a444 100644 --- a/src/components/Notifications/NotificationsList.tsx +++ b/src/components/Notifications/NotificationsList.tsx @@ -115,7 +115,9 @@ const NotificationTile = ({ />
-
{result.message}
+
+ {result.message} +
{formatDateTime(result.created_date)} @@ -474,6 +476,7 @@ export default function NotificationsList({ <> setOpen(!open)} icon={} badgeCount={unreadCount} From 15669108f39f316a859fc3a786925da5f9f6045a Mon Sep 17 00:00:00 2001 From: JavidSumra Date: Thu, 7 Nov 2024 18:24:00 +0530 Subject: [PATCH 2/3] fix addded id in SidebarItemProps type --- src/components/Common/Sidebar/SidebarItem.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Common/Sidebar/SidebarItem.tsx b/src/components/Common/Sidebar/SidebarItem.tsx index 7d91e56dd76..7262c6a103b 100644 --- a/src/components/Common/Sidebar/SidebarItem.tsx +++ b/src/components/Common/Sidebar/SidebarItem.tsx @@ -9,6 +9,7 @@ import useAppHistory from "@/hooks/useAppHistory"; export type SidebarIcon = React.ReactNode; type SidebarItemProps = { + id?: string; ref?: React.Ref; text: string; icon: SidebarIcon; @@ -21,7 +22,6 @@ type SidebarItemProps = { type SidebarItemBaseProps = SidebarItemProps & { shrinked?: boolean; - id?: string; }; const SidebarItemBase = forwardRef( From dd38cefa05b475ba7a973215f5814e0d6e184709 Mon Sep 17 00:00:00 2001 From: JavidSumra Date: Thu, 7 Nov 2024 18:56:27 +0530 Subject: [PATCH 3/3] fix failing test case --- cypress/e2e/facility_spec/FacilityHomepage.cy.ts | 2 +- cypress/pageobject/Facility/FacilityNotify.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts index f6e0c1759ef..05a1d4ccdfb 100644 --- a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts +++ b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts @@ -166,7 +166,7 @@ describe("Facility Homepage Function", () => { facilityNotify.verifyGetNotificationReq(); cy.verifyContentPresence("#notification-message", [noitificationMessage]); facilityNotify.interceptGetNotificationReq(); - cy.verifyAndClickElement("#notification-slide-btn", "Notifications"); + facilityNotify.openNotificationSlide(); facilityNotify.verifyGetNotificationReq(); cy.verifyContentPresence("#notification-slide-msg", [noitificationMessage]); }); diff --git a/cypress/pageobject/Facility/FacilityNotify.ts b/cypress/pageobject/Facility/FacilityNotify.ts index c0f7d54f4f3..590ce2d4259 100644 --- a/cypress/pageobject/Facility/FacilityNotify.ts +++ b/cypress/pageobject/Facility/FacilityNotify.ts @@ -3,6 +3,10 @@ export class FacilityNotify { cy.get("#NotifyModalMessageInput").should("be.visible").type(message); } + openNotificationSlide(): void { + cy.get("#notification-slide-btn").should("be.visible").click(); + } + visitNoticeBoard(): void { cy.get("a[href='/notice_board']").should("be.visible").click(); }