From 6c4f151829919817cd92ceccb483ad957bbebfa0 Mon Sep 17 00:00:00 2001 From: Mohammed Nihal <57055998+nihal467@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:01:45 +0530 Subject: [PATCH 1/5] New Cypress Test | Functionality test of Linking and Unlinking Facility | User Tab (#6564) * add test to link and unlink a facility and verify its reflection * added a little bit comment * fixed the changes requested --- cypress/e2e/users_spec/user_creation.cy.ts | 12 --- cypress/e2e/users_spec/user_manage.cy.ts | 83 ++++++++++++++++++ cypress/pageobject/Users/ManageUserPage.ts | 85 +++++++++++++++++++ .../Facility/DoctorVideoSlideover.tsx | 8 +- src/Components/Facility/FacilityCard.tsx | 5 +- src/Components/Facility/FacilityHome.tsx | 1 + src/Components/Patient/ManagePatients.tsx | 1 + src/Components/Users/ManageUsers.tsx | 6 +- 8 files changed, 185 insertions(+), 16 deletions(-) create mode 100644 cypress/e2e/users_spec/user_manage.cy.ts create mode 100644 cypress/pageobject/Users/ManageUserPage.ts diff --git a/cypress/e2e/users_spec/user_creation.cy.ts b/cypress/e2e/users_spec/user_creation.cy.ts index bd5002d386f..9090f72505a 100644 --- a/cypress/e2e/users_spec/user_creation.cy.ts +++ b/cypress/e2e/users_spec/user_creation.cy.ts @@ -193,18 +193,6 @@ describe("User Creation", () => { userPage.verifyMultipleBadgesWithSameId(alreadylinkedusersviews); }); - // the below commented out codes, will be used in the upcoming refactoring of this module, since it is a inter-dependent of partially converted code, currently taking it down - - // it("link facility for user", () => { - // cy.contains("Linked Facilities").click(); - // cy.intercept(/\/api\/v1\/facility/).as("getFacilities"); - // cy.get("[name='facility']") - // .click() - // .type("Dummy Facility 1") - // .wait("@getFacilities"); - // cy.get("li[role='option']").should("not.exist"); - // }); - afterEach(() => { cy.saveLocalStorage(); }); diff --git a/cypress/e2e/users_spec/user_manage.cy.ts b/cypress/e2e/users_spec/user_manage.cy.ts new file mode 100644 index 00000000000..384a88ceab3 --- /dev/null +++ b/cypress/e2e/users_spec/user_manage.cy.ts @@ -0,0 +1,83 @@ +import { cy, describe, before, beforeEach, it, afterEach } from "local-cypress"; +import LoginPage from "../../pageobject/Login/LoginPage"; +import { UserPage } from "../../pageobject/Users/UserSearch"; +import ManageUserPage from "../../pageobject/Users/ManageUserPage"; + +describe("Manage User", () => { + const loginPage = new LoginPage(); + const userPage = new UserPage(); + const manageUserPage = new ManageUserPage(); + const usernametolinkfacilitydoc1 = "dummydoctor4"; + const usernametolinkfacilitydoc2 = "dummydoctor5"; + const usernametolinkfacilitydoc3 = "dummydoctor6"; + const usernamerealname = "Dummy Doctor"; + const facilitytolinkusername = "Dummy Shifting Center"; + + before(() => { + loginPage.loginAsDisctrictAdmin(); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.awaitUrl("/users"); + }); + + it("linking and unlinking facility for multiple users, and confirm reflection in user cards and doctor connect", () => { + // verify the user doesn't have any home facility + userPage.typeInSearchInput(usernametolinkfacilitydoc1); + userPage.checkUsernameText(usernametolinkfacilitydoc1); + manageUserPage.assertHomeFacility("No Home Facility"); + // Link a new facility and ensure it is under linked facility - doctor username (1) + manageUserPage.clickFacilitiesTab(); + manageUserPage.typeFacilityName(facilitytolinkusername); + manageUserPage.selectFacilityFromDropdown(facilitytolinkusername); + manageUserPage.clickLinkFacility(); + manageUserPage.assertLinkedFacility(facilitytolinkusername); + // Verify in the already linked facility are not present in droplist + manageUserPage.assertFacilityNotInDropdown(facilitytolinkusername); + manageUserPage.clickCloseSlideOver(); + // Link a new facility and ensure it is under home facility - doctor username (2) + userPage.clearSearchInput(); + userPage.typeInSearchInput(usernametolinkfacilitydoc2); + userPage.checkUsernameText(usernametolinkfacilitydoc2); + manageUserPage.clickFacilitiesTab(); + manageUserPage.typeFacilityName(facilitytolinkusername); + manageUserPage.selectFacilityFromDropdown(facilitytolinkusername); + manageUserPage.clickLinkFacility(); + manageUserPage.clickHomeFacilityIcon(); + manageUserPage.assertnotLinkedFacility(facilitytolinkusername); + manageUserPage.assertHomeFacilitylink(facilitytolinkusername); + manageUserPage.clickCloseSlideOver(); + // verify the home facility doctor id have reflection in user card + userPage.clearSearchInput(); + userPage.typeInSearchInput(usernametolinkfacilitydoc2); + userPage.checkUsernameText(usernametolinkfacilitydoc2); + manageUserPage.assertHomeFacility(facilitytolinkusername); + // Link a new facility and unlink the facility from the doctor username (3) + userPage.clearSearchInput(); + userPage.typeInSearchInput(usernametolinkfacilitydoc3); + userPage.checkUsernameText(usernametolinkfacilitydoc3); + manageUserPage.clickFacilitiesTab(); + manageUserPage.typeFacilityName(facilitytolinkusername); + manageUserPage.selectFacilityFromDropdown(facilitytolinkusername); + manageUserPage.clickLinkFacility(); + manageUserPage.clickUnlinkFacilityButton(); + manageUserPage.clickSubmit(); + manageUserPage.assertnotLinkedFacility; + manageUserPage.linkedfacilitylistnotvisible(); + manageUserPage.clickCloseSlideOver(); + // Go to particular facility doctor connect and all user-id are reflected based on there access + // Path will be facility page to patient page then doctor connect button + manageUserPage.navigateToFacility(); + manageUserPage.typeFacilitySearch(facilitytolinkusername); + manageUserPage.assertFacilityInCard(facilitytolinkusername); + manageUserPage.clickFacilityPatients(); + manageUserPage.clickDoctorConnectButton(); + manageUserPage.assertDoctorConnectVisibility(usernamerealname); + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); +}); diff --git a/cypress/pageobject/Users/ManageUserPage.ts b/cypress/pageobject/Users/ManageUserPage.ts new file mode 100644 index 00000000000..0775408abb4 --- /dev/null +++ b/cypress/pageobject/Users/ManageUserPage.ts @@ -0,0 +1,85 @@ +export class ManageUserPage { + assertHomeFacility(expectedText) { + cy.get("#home_facility").should("contain.text", expectedText); + } + + clickFacilitiesTab() { + cy.get("#facilities").click(); + } + + typeFacilityName(facilityName) { + cy.get("input[name='facility']").click().type(facilityName); + } + + selectFacilityFromDropdown(facilityName) { + cy.get("[role='option']").contains(facilityName).click(); + } + + clickLinkFacility() { + cy.get("#link-facility").click(); + } + + assertLinkedFacility(facilityName) { + cy.get("#linked-facility-list").should("contain.text", facilityName); + } + + assertnotLinkedFacility(facilityName) { + cy.get("#linked-facility-list").should("not.contain", facilityName); + } + + linkedfacilitylistnotvisible() { + cy.get("#linked-facility-list").should("not.exist"); + } + + assertHomeFacilitylink(facilityName) { + cy.get("#home-facility").should("contain.text", facilityName); + } + + assertFacilityNotInDropdown(facilityName) { + this.typeFacilityName(facilityName); + cy.get("[role='option']").should("not.exist"); + } + + clickCloseSlideOver() { + cy.get("#close-slide-over").click(); + } + + clickHomeFacilityIcon() { + cy.get("#home-facility-icon").click(); + } + + clickUnlinkFacilityButton() { + cy.get("#unlink-facility-button").click(); + } + + clickSubmit() { + cy.get("#submit").click(); + } + + navigateToFacility() { + cy.visit("/facility"); + } + + typeFacilitySearch(facilityName) { + cy.get("#search").click().type(facilityName); + } + + assertFacilityInCard(facilityName) { + cy.get("#facility-name-card").should("contain", facilityName); + } + + clickFacilityPatients() { + cy.get("#facility-patients").click(); + } + + clickDoctorConnectButton() { + cy.get("#doctor-connect-patient-button").click(); + } + + assertDoctorConnectVisibility(realName) { + cy.get("#doctor-connect-home-doctor").should("contain.text", realName); + cy.get("#doctor-connect-remote-doctor").should("contain.text", realName); + } +} + +export default ManageUserPage; diff --git a/src/Components/Facility/DoctorVideoSlideover.tsx b/src/Components/Facility/DoctorVideoSlideover.tsx index 59c443cb64e..5302f7f9d53 100644 --- a/src/Components/Facility/DoctorVideoSlideover.tsx +++ b/src/Components/Facility/DoctorVideoSlideover.tsx @@ -68,7 +68,13 @@ export default function DoctorVideoSlideover(props: { home: false, }, ].map((type, i) => ( -