-
Notifications
You must be signed in to change notification settings - Fork 430
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
Add Cypress Test Suite for Facility Notice Board Functionality Verification #9045
base: develop
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
@@ -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]); | ||
}); | ||
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 Consider adding negative test cases and cleanup. The test covers the happy path well but could be enhanced with:
Would you like me to provide example code for these scenarios? |
||
|
||
afterEach(() => { | ||
cy.saveLocalStorage(); | ||
}); | ||
|
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(); | ||
} | ||
Comment on lines
+10
to
+12
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 timeout and error handling for link interaction. The notice board link interaction could be more robust with proper timeout and error handling. - cy.get("a[href='/notice_board']").should("be.visible").click();
+ cy.get('[data-testid="notice-board-link"]', { timeout: 10000 })
+ .should("be.visible")
+ .should("not.be.disabled")
+ .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); | ||
} | ||
Comment on lines
+18
to
+23
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 interception configuration and type safety. The facility search API interception could be more specific and type-safe. + private readonly API_PATHS = {
+ FACILITY_SEARCH: '**/api/v1/facility',
+ NOTIFICATION: '**/api/v1/notification'
+ } as const;
+
+ interface FacilitySearchResponse {
+ // Add expected response type definition
+ data: Array<{ id: string; name: string }>;
+ }
+
interceptFacilitySearchReq(): void {
- cy.intercept("GET", "**/api/v1/facility/**").as("searchFacility");
+ cy.intercept("GET", this.API_PATHS.FACILITY_SEARCH + '/**').as("searchFacility");
}
verifyFacilitySearchReq(): void {
- cy.wait("@searchFacility").its("response.statusCode").should("eq", 200);
+ cy.wait("@searchFacility").then((interception) => {
+ expect(interception.response?.statusCode).to.equal(200);
+ expect(interception.response?.body).to.have.property('data');
+ });
}
|
||
|
||
interceptPostNotificationReq(): void { | ||
cy.intercept("POST", "**/api/v1/notification/notify").as("notifyFacility"); | ||
} | ||
|
||
verifyPostNotificationReq(): void { | ||
cy.wait("@notifyFacility").its("response.statusCode").should("eq", 204); | ||
} | ||
Comment on lines
+25
to
+31
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 error handling for notification POST requests. The notification POST verification should handle error cases and validate request payload. interceptPostNotificationReq(): void {
- cy.intercept("POST", "**/api/v1/notification/notify").as("notifyFacility");
+ cy.intercept("POST", this.API_PATHS.NOTIFICATION + '/notify').as("notifyFacility");
}
verifyPostNotificationReq(): void {
- cy.wait("@notifyFacility").its("response.statusCode").should("eq", 204);
+ cy.wait("@notifyFacility").then((interception) => {
+ // Verify request payload
+ expect(interception.request.body).to.have.property('message');
+ // Verify response
+ expect(interception.response?.statusCode).to.equal(204);
+ // Handle potential error responses
+ if (interception.response?.statusCode !== 204) {
+ throw new Error(`Notification failed: ${interception.response?.body}`);
+ }
+ });
}
|
||
|
||
interceptGetNotificationReq(): void { | ||
cy.intercept("GET", "**/api/v1/notification/**").as("getNotifications"); | ||
} | ||
|
||
verifyGetNotificationReq(): void { | ||
cy.wait("@getNotifications").its("response.statusCode").should("eq", 200); | ||
} | ||
} |
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
Move notification messages to i18n configuration.
As per PR objectives, UI text should support internationalization. Consider moving these message constants to the i18n configuration:
notificationErrorMsg
noitificationMessage
Example structure: