diff --git a/.github/workflows/cypress.yaml b/.github/workflows/cypress.yaml index 506c2e56f66..3abf95cd4b0 100644 --- a/.github/workflows/cypress.yaml +++ b/.github/workflows/cypress.yaml @@ -18,8 +18,9 @@ jobs: containers: [1, 2, 3, 4] env: REACT_CARE_API_URL: http://localhost:9000 - REACT_ENABLED_APPS: "ohcnetwork/care_hcx_fe@main" + REACT_ENABLED_APPS: "ohcnetwork/care_hcx_fe@main,ohcnetwork/care_abdm_fe@main" REACT_ENABLE_HCX: true + REACT_ENABLE_ABDM: true steps: - name: Checkout 📥 uses: actions/checkout@v3 @@ -135,4 +136,4 @@ jobs: if: ${{ failure() && steps.pr_origin.outputs.is_forked == 'true' }} with: name: cypress-videos - path: cypress/videos \ No newline at end of file + path: cypress/videos diff --git a/.github/workflows/notify-non-core-qn.yml b/.github/workflows/notify-non-core-qn.yml index 7aa59e6e868..07533c320c5 100644 --- a/.github/workflows/notify-non-core-qn.yml +++ b/.github/workflows/notify-non-core-qn.yml @@ -1,37 +1,39 @@ name: Notify Core Team on Non-Core Questions + on: issue_comment: types: [created] + permissions: issues: write pull-requests: write + jobs: notify_core_team: runs-on: ubuntu-latest env: - ALLOWED_USERNAMES: ${{ vars.ALLOWED_USERNAMES }} - QUESTION_KEYWORDS: ${{ vars.QUESTION_KEYWORDS }} - QUESTION_LABELS: ${{ vars.QUESTION_LABELS }} - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + ALLOWED_USERNAMES: ${{ vars.ALLOWED_USERNAMES || '' }} + QUESTION_KEYWORDS: ${{ vars.QUESTION_KEYWORDS || '' }} + QUESTION_LABELS: ${{ vars.QUESTION_LABELS || '' }} + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK || '' }} + steps: - name: Check and Notify - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | - console.log('Script started'); - const isOrgMember = (commenter, allowedUsers) => { - return allowedUsers.split(',').map(u => u.trim()).includes(commenter); - }; - const containsQuestionKeywords = (text, keywords) => { - return keywords.split(',').map(k => k.trim()).some(keyword => + const isOrgMember = (commenter, allowedUsers) => + allowedUsers.split(',').map(u => u.trim()).includes(commenter); + + const containsQuestionKeywords = (text, keywords) => + keywords.split(',').map(k => k.trim()).some(keyword => text.toLowerCase().includes(keyword.toLowerCase()) ); - }; + const addLabelsToIssue = async (github, context, labelsString) => { - const labels = labelsString.split(',').map(label => label.trim()).filter(label => label); + const labels = labelsString.split(',').map(label => label.trim()).filter(Boolean); if (labels.length > 0) { - console.log('Adding labels:', labels); await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, @@ -40,48 +42,47 @@ jobs: }); } }; - const sendSlackNotification = async (webhook, payload) => { + + const sendSlackNotification = async (webhook, commentUrl) => { + const payload = { commentUrl }; const response = await fetch(webhook, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) { - throw new Error(`HTTP error! status: ${response.status}`); + throw new Error(`Slack notification failed with status: ${response.status}`); } }; + + const isBot = async (github, commenter) => { + try { + const { data: user } = await github.rest.users.getByUsername({ username: commenter }); + return user.type === 'Bot'; + } catch { + return false; + } + }; + const commenter = context.payload.comment.user.login; - console.log('Commenter:', commenter); - if (!isOrgMember(commenter, process.env.ALLOWED_USERNAMES)) { - const commentBody = context.payload.comment.body; - const sanitizedComment = commentBody - ?.replace(/[^\w\s?]/gi, '') - .toLowerCase(); - console.log('Comment body:', sanitizedComment); - if (containsQuestionKeywords(sanitizedComment, process.env.QUESTION_KEYWORDS)) { - try { - console.log('Adding labels to the issue'); - await addLabelsToIssue(github, context, process.env.QUESTION_LABELS); - console.log('Labels added successfully'); - const issueUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/issues/${context.payload.issue.number}`; - const issueTitle = context.payload.issue.title; - const issueNumber = context.payload.issue.number; - console.log('Issue URL:', issueUrl); - console.log('Issue Title:', issueTitle); - console.log('Issue Number:', issueNumber); - const payload = { - link: issueUrl, - Question: commentBody, - "issue-number": issueNumber, - title: issueTitle, - user: commenter - }; - await sendSlackNotification(process.env.SLACK_WEBHOOK, payload); - console.log('Slack notification sent successfully'); - } catch (error) { - console.error('Workflow failed:', error.message); - core.setFailed(`Workflow failed: ${error.message}`); + const allowedUsers = process.env.ALLOWED_USERNAMES; + const keywords = process.env.QUESTION_KEYWORDS; + const labels = process.env.QUESTION_LABELS; + const webhook = process.env.SLACK_WEBHOOK; + + if (await isBot(github, commenter)) return; + + if (allowedUsers && !isOrgMember(commenter, allowedUsers)) { + const commentBody = context.payload.comment.body.trim(); + const filteredCommentBody = commentBody.split('\n').filter(line => !line.startsWith('>')).join('\n'); + + if (keywords && containsQuestionKeywords(filteredCommentBody, keywords)) { + if (labels) { + await addLabelsToIssue(github, context, labels); + } + if (webhook) { + const commentUrl = context.payload.comment.html_url; + await sendSlackNotification(webhook, commentUrl); } } } - console.log('Script ended'); diff --git a/cypress/e2e/assets_spec/AssetHomepage.cy.ts b/cypress/e2e/assets_spec/AssetHomepage.cy.ts index dfb3249c243..e19f885db72 100644 --- a/cypress/e2e/assets_spec/AssetHomepage.cy.ts +++ b/cypress/e2e/assets_spec/AssetHomepage.cy.ts @@ -2,112 +2,128 @@ import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; import { pageNavigation } from "pageobject/utils/paginationHelpers"; import { v4 as uuidv4 } from "uuid"; -import { AssetPage } from "../../pageobject/Asset/AssetCreation"; import { AssetFilters } from "../../pageobject/Asset/AssetFilters"; -import { AssetQRScanPage } from "../../pageobject/Asset/AssetQRScan"; -import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch"; +import { AssetHome } from "../../pageobject/Asset/AssetHome"; import LoginPage from "../../pageobject/Login/LoginPage"; - -describe("Asset Tab", () => { - const assetSearchPage = new AssetSearchPage(); - const assetQRScanPage = new AssetQRScanPage(); - const assetFilters = new AssetFilters(); - const assetPage = new AssetPage(); - const loginPage = new LoginPage(); - const assetName = "Dummy Camera 10"; - const qrCode = uuidv4(); - const serialNumber = Math.floor(Math.random() * 10 ** 10).toString(); - - before(() => { - loginPage.loginAsDistrictAdmin(); - cy.saveLocalStorage(); - }); - - beforeEach(() => { - cy.restoreLocalStorage(); - cy.clearLocalStorage(/filters--.+/); - cy.awaitUrl("/assets"); - }); - - // search for a element - - it("Search Asset Name/QR_ID/Serial_number", () => { - assetSearchPage.typeSearchKeyword(assetName); - assetSearchPage.pressEnter(); - assetSearchPage.verifyBadgeContent(assetName); - assetSearchPage.clickAssetByName(assetName); - assetSearchPage.clickUpdateButton(); - assetSearchPage.clearAndTypeQRCode(qrCode); - assetSearchPage.clearAndTypeSerialNumber(serialNumber); - assetSearchPage.clickAssetSubmitButton(); - assetSearchPage.visitAssetsPage(); - assetSearchPage.typeSearchKeyword(qrCode); - assetSearchPage.pressEnter(); - assetSearchPage.verifyAssetListContains(assetName); - assetSearchPage.verifyBadgeContent(qrCode); - assetSearchPage.typeSearchKeyword(serialNumber); - assetSearchPage.verifyAssetListContains(assetName); - assetSearchPage.verifyBadgeContent(serialNumber); - }); - - // scan a asset qr code - - it("Scan Asset QR", () => { - assetQRScanPage.scanAssetQR(); - }); - - // filter the asset and verify the badges are there - - it("Filter Asset", () => { - assetFilters.filterAssets( - "Dummy Facility 40", - "ACTIVE", - "ONVIF Camera", - "Camera Loc", - ); - advanceFilters.clickAdvancedFiltersButton(); - assetFilters.clickslideoverbackbutton(); // to verify the back button doesn't clear applied filters - assetFilters.assertFacilityText("Dummy Facility 40"); - assetFilters.assertAssetClassText("ONVIF"); - assetFilters.assertStatusText("ACTIVE"); - assetFilters.assertLocationText("Camera Loc"); - advanceFilters.clickAdvancedFiltersButton(); - assetFilters.clearFilters(); - }); - - // Verify the pagination in the page - - it("Next/Previous Page", () => { - pageNavigation.navigateToNextPage(); - pageNavigation.verifyCurrentPageNumber(2); - pageNavigation.navigateToPreviousPage(); - pageNavigation.verifyCurrentPageNumber(1); - }); - - it("Import new asset", () => { - assetPage.selectassetimportbutton(); - assetPage.selectImportOption(); - assetPage.selectImportFacility("Dummy Facility 40"); - assetPage.importAssetFile(); - assetPage.selectImportLocation("Camera Loc"); - assetPage.clickImportAsset(); - }); - - it("verify imported asset", () => { - assetSearchPage.typeSearchKeyword("New Test Asset"); - assetSearchPage.pressEnter(); - assetSearchPage.verifyAssetIsPresent("New Test Asset"); - }); - - it("Export asset", () => { - assetPage.selectassetimportbutton(); - cy.wait(2000); - assetPage.selectJsonExportButton(); - assetPage.selectassetimportbutton(); - assetPage.selectCsvExportButton(); - }); - - afterEach(() => { - cy.saveLocalStorage(); +import { nonAdminRoles } from "../../pageobject/utils/userConfig"; + +const rolesToTest: Array<"districtAdmin" | (typeof nonAdminRoles)[number]> = [ + "districtAdmin", + ...nonAdminRoles, +]; + +rolesToTest.forEach((role) => { + describe(`Asset Tab Tests for Role: ${role}`, () => { + const assetHome = new AssetHome(); + const assetFilters = new AssetFilters(); + const loginPage = new LoginPage(); + const assetName = "Dummy Camera 10"; + const assetStatus = "ACTIVE"; + const assetClass = "ONVIF"; + const assetLocation = "Camera Loc"; + const facilityName = "Dummy Facility 40"; + const newImportAssetName = "New Test Asset"; + const qrCode = uuidv4(); + const serialNumber = Math.floor(Math.random() * 10 ** 10).toString(); + + before(() => { + loginPage.loginByRole(role); + cy.saveLocalStorage(); + }); + + beforeEach(() => { + cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); + cy.awaitUrl("/assets"); + }); + + it("Search Asset Name/QR_ID/Serial_number", () => { + assetHome.typeAssetSearch(assetName); + advanceFilters.verifyFilterBadgePresence( + "Name/Serial No./QR ID", + assetName, + true, + ); + assetHome.clickAssetByName(assetName); + assetHome.clickAssetDetailsUpdateButton(); + assetHome.clearAndTypeQRCode(qrCode); + assetHome.clearAndTypeSerialNumber(serialNumber); + assetHome.clickAssetUpdateSubmitButton(); + assetHome.navigateToAssetsPage(); + assetHome.typeAssetSearch(qrCode); + assetHome.verifyAssetListContains(assetName); + advanceFilters.verifyFilterBadgePresence( + "Name/Serial No./QR ID", + qrCode, + true, + ); + assetHome.typeAssetSearch(serialNumber); + assetHome.verifyAssetListContains(assetName); + advanceFilters.verifyFilterBadgePresence( + "Name/Serial No./QR ID", + serialNumber, + true, + ); + }); + + it("Scan Asset QR", () => { + assetHome.scanAssetQR(); + }); + + it("Advance Filter Asset", () => { + advanceFilters.clickAdvancedFiltersButton(); + advanceFilters.typeFacilityName(facilityName); + assetFilters.filterAssets(assetStatus, assetClass, assetLocation); + advanceFilters.applySelectedFilter(); + advanceFilters.clickAdvancedFiltersButton(); + advanceFilters.clickslideoverbackbutton(); // to verify the back button doesn't clear applied filters + advanceFilters.verifyFilterBadgePresence("Facility", facilityName, true); + advanceFilters.verifyFilterBadgePresence("Asset Class", assetClass, true); + advanceFilters.verifyFilterBadgePresence("Status", assetStatus, true); + advanceFilters.verifyFilterBadgePresence("Location", assetLocation, true); + advanceFilters.clickAdvancedFiltersButton(); + advanceFilters.clickClearAdvanceFilters(); + }); + + it("Next/Previous Page", () => { + pageNavigation.navigateToNextPage(); + pageNavigation.verifyCurrentPageNumber(2); + pageNavigation.navigateToPreviousPage(); + pageNavigation.verifyCurrentPageNumber(1); + }); + + it("Import new asset and verify its presence", () => { + if (role === "districtAdmin") { + assetHome.selectAssetImportButton("click"); + assetHome.selectImportOption(); + assetHome.selectImportFacility(facilityName); + assetHome.importAssetFile(); + assetHome.selectImportLocation(assetLocation); + assetHome.clickImportAsset(); + cy.verifyNotification("Assets imported successfully"); + cy.closeNotification(); + assetHome.navigateToAssetsPage(); + assetHome.typeAssetSearch(newImportAssetName); + assetHome.verifyAssetIsPresent(newImportAssetName); + } else { + assetHome.selectAssetImportButton("verifyNotExist"); + } + }); + + it("Export the list of assets in CSV & Json", () => { + if (role === "districtAdmin") { + assetHome.selectAssetImportButton("click"); + cy.wait(2000); + assetHome.selectJsonExportButton(); + assetHome.selectAssetImportButton("click"); + assetHome.selectCsvExportButton(); + } else { + assetHome.selectAssetImportButton("verifyNotExist"); + } + }); + + afterEach(() => { + cy.saveLocalStorage(); + }); }); }); diff --git a/cypress/e2e/assets_spec/AssetsCreation.cy.ts b/cypress/e2e/assets_spec/AssetsCreation.cy.ts index 61c6fe9b517..76f225b03d7 100644 --- a/cypress/e2e/assets_spec/AssetsCreation.cy.ts +++ b/cypress/e2e/assets_spec/AssetsCreation.cy.ts @@ -1,18 +1,18 @@ import { v4 as uuidv4 } from "uuid"; import { AssetPage } from "../../pageobject/Asset/AssetCreation"; -import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch"; +import { AssetHome } from "../../pageobject/Asset/AssetHome"; import LoginPage from "../../pageobject/Login/LoginPage"; describe("Asset", () => { const assetPage = new AssetPage(); - const assetSearchPage = new AssetSearchPage(); + const assetHome = new AssetHome(); const loginPage = new LoginPage(); const phone_number = "9999999999"; const serialNumber = Math.floor(Math.random() * 10 ** 10).toString(); before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -87,9 +87,8 @@ describe("Asset", () => { assetPage.verifyAssetCreation(); assetPage.verifySuccessNotification("Asset created successfully"); - assetSearchPage.typeSearchKeyword("New Test Asset 2"); - assetSearchPage.pressEnter(); - assetSearchPage.verifyAssetIsPresent("New Test Asset 2"); + assetHome.typeAssetSearch("New Test Asset 2"); + assetHome.verifyAssetIsPresent("New Test Asset 2"); }); it("Edit an Asset", () => { @@ -114,9 +113,8 @@ describe("Asset", () => { }); it("Verify Editted Asset", () => { - assetSearchPage.typeSearchKeyword("New Test Asset Edited"); - assetSearchPage.pressEnter(); - assetSearchPage.verifyAssetIsPresent("New Test Asset Edited"); + assetHome.typeAssetSearch("New Test Asset Edited"); + assetHome.verifyAssetIsPresent("New Test Asset Edited"); }); it("Configure an asset", () => { @@ -159,8 +157,7 @@ describe("Asset", () => { assetPage.interceptAssetCreation(); assetPage.clickCreateAsset(); assetPage.verifyAssetCreation(); - assetSearchPage.typeSearchKeyword("New Test Asset Vital"); - assetSearchPage.pressEnter(); + assetHome.typeAssetSearch("New Test Asset Vital"); assetPage.openCreatedAsset(); assetPage.configureVitalAsset("Host name", "192.168.1.20"); assetPage.clickConfigureVital(); diff --git a/cypress/e2e/assets_spec/AssetsManage.cy.ts b/cypress/e2e/assets_spec/AssetsManage.cy.ts index 9645cd22c30..32dc5791bd3 100644 --- a/cypress/e2e/assets_spec/AssetsManage.cy.ts +++ b/cypress/e2e/assets_spec/AssetsManage.cy.ts @@ -1,6 +1,8 @@ +import FacilityHome from "pageobject/Facility/FacilityHome"; +import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; + import { AssetPage } from "../../pageobject/Asset/AssetCreation"; -import { AssetFilters } from "../../pageobject/Asset/AssetFilters"; -import { AssetSearchPage } from "../../pageobject/Asset/AssetSearch"; +import { AssetHome } from "../../pageobject/Asset/AssetHome"; import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import LoginPage from "../../pageobject/Login/LoginPage"; @@ -14,15 +16,15 @@ describe("Asset", () => { const assetPage = new AssetPage(); const loginPage = new LoginPage(); const facilityPage = new FacilityPage(); - const assetSearchPage = new AssetSearchPage(); - const assetFilters = new AssetFilters(); + const assetHome = new AssetHome(); + const facilityHome = new FacilityHome(); const fillFacilityName = "Dummy Facility 40"; const assetname = "Dummy Camera"; const locationName = "Dummy Location 1"; const initiallocationName = "Camera Location"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -33,10 +35,13 @@ describe("Asset", () => { }); it("Verify Asset Warranty Expiry Label", () => { - assetSearchPage.typeSearchKeyword(assetname); - assetSearchPage.pressEnter(); - assetSearchPage.verifyBadgeContent(assetname); - assetSearchPage.clickAssetByName(assetname); + assetHome.typeAssetSearch(assetname); + advanceFilters.verifyFilterBadgePresence( + "Name/Serial No./QR ID", + assetname, + true, + ); + assetHome.clickAssetByName(assetname); assetPage.clickupdatedetailbutton(); assetPage.scrollintoWarrantyDetails(); assetPage.enterWarrantyExpiryDate(addDaysToDate(100)); // greater than 3 months @@ -60,10 +65,13 @@ describe("Asset", () => { }); it("Create & Edit a service history and verify reflection", () => { - assetSearchPage.typeSearchKeyword(assetname); - assetSearchPage.pressEnter(); - assetSearchPage.verifyBadgeContent(assetname); - assetSearchPage.clickAssetByName(assetname); + assetHome.typeAssetSearch(assetname); + advanceFilters.verifyFilterBadgePresence( + "Name/Serial No./QR ID", + assetname, + true, + ); + assetHome.clickAssetByName(assetname); assetPage.clickupdatedetailbutton(); assetPage.scrollintonotes(); assetPage.enterAssetNotes("Dummy Notes"); @@ -82,10 +90,13 @@ describe("Asset", () => { }); it("Create a asset transaction and verify history", () => { - assetSearchPage.typeSearchKeyword(assetname); - assetSearchPage.pressEnter(); - assetSearchPage.verifyBadgeContent(assetname); - assetSearchPage.clickAssetByName(assetname); + assetHome.typeAssetSearch(assetname); + advanceFilters.verifyFilterBadgePresence( + "Name/Serial No./QR ID", + assetname, + true, + ); + assetHome.clickAssetByName(assetname); assetPage.clickupdatedetailbutton(); assetPage.clickassetlocation(locationName); assetPage.clickUpdateAsset(); @@ -94,9 +105,13 @@ describe("Asset", () => { }); it("Verify Facility Asset Page Redirection", () => { - cy.visit("/facility"); - cy.get("#facility-search").click().clear().type(fillFacilityName); - facilityPage.verifyFacilityBadgeContent(fillFacilityName); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch(fillFacilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + fillFacilityName, + true, + ); facilityPage.visitAlreadyCreatedFacility(); facilityPage.clickManageFacilityDropdown(); facilityPage.clickCreateAssetFacilityOption(); @@ -105,7 +120,11 @@ describe("Asset", () => { facilityPage.clickManageFacilityDropdown(); facilityPage.clickviewAssetFacilityOption(); facilityPage.verifyfacilityviewassetredirection(); - assetFilters.assertFacilityText(fillFacilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility", + fillFacilityName, + true, + ); facilityPage.verifyassetfacilitybackredirection(); }); diff --git a/cypress/e2e/facility_spec/FacilityCreation.cy.ts b/cypress/e2e/facility_spec/FacilityCreation.cy.ts index 5fd988480fc..d8d73417e7e 100644 --- a/cypress/e2e/facility_spec/FacilityCreation.cy.ts +++ b/cypress/e2e/facility_spec/FacilityCreation.cy.ts @@ -1,8 +1,11 @@ +import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; + import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import FacilityHome from "../../pageobject/Facility/FacilityHome"; import LoginPage from "../../pageobject/Login/LoginPage"; import ManageUserPage from "../../pageobject/Users/ManageUserPage"; import { UserCreationPage } from "../../pageobject/Users/UserCreation"; +import { nonAdminRoles } from "../../pageobject/utils/userConfig"; describe("Facility Creation", () => { let facilityUrl1: string; @@ -60,7 +63,7 @@ describe("Facility Creation", () => { const facilityType = "Primary Health Centres"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -72,9 +75,13 @@ describe("Facility Creation", () => { it("Verify Facility Triage Function", () => { // mandatory field error throw - manageUserPage.typeFacilitySearch(facilityName2); - facilityPage.verifyFacilityBadgeContent(facilityName2); - manageUserPage.assertFacilityInCard(facilityName2); + facilityHome.typeFacilitySearch(facilityName2); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName2, + true, + ); + facilityHome.assertFacilityInCard(facilityName2); facilityHome.verifyURLContains(facilityName2); facilityPage.visitAlreadyCreatedFacility(); facilityPage.scrollToFacilityTriage(); @@ -237,10 +244,14 @@ describe("Facility Creation", () => { .contains(facilityNumber) .should("be.visible"); // verify the facility homepage - cy.visit("/facility"); - manageUserPage.typeFacilitySearch(facilityName); - facilityPage.verifyFacilityBadgeContent(facilityName); - manageUserPage.assertFacilityInCard(facilityName); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch(facilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName, + true, + ); + facilityHome.assertFacilityInCard(facilityName); facilityHome.verifyURLContains(facilityName); }); @@ -335,13 +346,8 @@ describe("Facility Creation", () => { }); it("Access Restriction for Non-Admin Users to facility creation page", () => { - const nonAdminLoginMethods = [ - loginPage.loginAsDevDoctor.bind(loginPage), - loginPage.loginAsStaff.bind(loginPage), - ]; - - nonAdminLoginMethods.forEach((loginMethod) => { - loginMethod(); + nonAdminRoles.forEach((role) => { + loginPage.loginByRole(role); cy.visit("/facility/create"); facilityPage.verifyErrorNotification( "You don't have permission to perform this action. Contact the admin", diff --git a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts index f4c7aaa90a0..7d03f7a16f0 100644 --- a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts +++ b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts @@ -6,7 +6,6 @@ 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 { UserPage } from "../../pageobject/Users/UserSearch"; import { advanceFilters } from "../../pageobject/utils/advanceFilterHelpers"; describe("Facility Homepage Function", () => { @@ -15,7 +14,6 @@ describe("Facility Homepage Function", () => { const facilityNotify = new FacilityNotify(); const facilityPage = new FacilityPage(); const manageUserPage = new ManageUserPage(); - const userPage = new UserPage(); const facilitiesAlias = "downloadFacilitiesCSV"; const doctorsAlias = "downloadDoctorsCSV"; const triagesAlias = "downloadTriagesCSV"; @@ -29,7 +27,7 @@ describe("Facility Homepage Function", () => { const notificationMessage = "Test Notification"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -41,9 +39,13 @@ describe("Facility Homepage Function", () => { it("Verify the Facility card button redirection", () => { // view cns button - manageUserPage.typeFacilitySearch(facilityName); - facilityPage.verifyFacilityBadgeContent(facilityName); - manageUserPage.assertFacilityInCard(facilityName); + facilityHome.typeFacilitySearch(facilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName, + true, + ); + facilityHome.assertFacilityInCard(facilityName); facilityHome.clickViewCnsButton(); facilityHome.verifyCnsUrl(); facilityHome.navigateBack(); @@ -68,17 +70,21 @@ describe("Facility Homepage Function", () => { advanceFilters.selectLocalBody(localBody); advanceFilters.selectFacilityType(facilityType); advanceFilters.applySelectedFilter(); - facilityPage.verifyStateBadgeContent(stateName); - facilityPage.verifyDistrictBadgeContent(district); - facilityPage.verifyLocalBodyBadgeContent(localBody); - facilityPage.verifyFacilityTypeBadgeContent(facilityType); - manageUserPage.assertFacilityInCard(facilityName); + advanceFilters.verifyFilterBadgePresence("State", stateName, true); + advanceFilters.verifyFilterBadgePresence("District", district, true); + advanceFilters.verifyFilterBadgePresence( + "Facility type", + facilityType, + true, + ); + advanceFilters.verifyFilterBadgePresence("Local Body", localBody, true); + facilityHome.assertFacilityInCard(facilityName); advanceFilters.clickAdvancedFiltersButton(); advanceFilters.clickClearAdvanceFilters(); - userPage.verifyDataTestIdNotVisible("State"); - userPage.verifyDataTestIdNotVisible("District"); - userPage.verifyDataTestIdNotVisible("Facility type"); - userPage.verifyDataTestIdNotVisible("Local Body"); + advanceFilters.verifyFilterBadgePresence("State", "", false); + advanceFilters.verifyFilterBadgePresence("District", "", false); + advanceFilters.verifyFilterBadgePresence("Facility type", "", false); + advanceFilters.verifyFilterBadgePresence("Local Body", "", false); }); it("Search a facility in homepage and pagination", () => { @@ -88,9 +94,13 @@ describe("Facility Homepage Function", () => { pageNavigation.navigateToPreviousPage(); pageNavigation.verifyCurrentPageNumber(1); // search for a facility - manageUserPage.typeFacilitySearch(facilityName); - facilityPage.verifyFacilityBadgeContent(facilityName); - manageUserPage.assertFacilityInCard(facilityName); + facilityHome.typeFacilitySearch(facilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName, + true, + ); + facilityHome.assertFacilityInCard(facilityName); facilityHome.verifyURLContains(facilityName); }); @@ -124,9 +134,13 @@ describe("Facility Homepage Function", () => { advanceFilters.selectLocalBody(localBody); advanceFilters.applySelectedFilter(); // go to cns page in the facility details page - manageUserPage.typeFacilitySearch(facilityName); - facilityPage.verifyFacilityBadgeContent(facilityName); - manageUserPage.assertFacilityInCard(facilityName); + facilityHome.typeFacilitySearch(facilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName, + true, + ); + facilityHome.assertFacilityInCard(facilityName); facilityHome.clickViewFacilityDetails(); facilityHome.clickFacilityCnsButton(); facilityHome.verifyCnsUrl(); @@ -140,13 +154,17 @@ describe("Facility Homepage Function", () => { it("Verify Notice Board Functionality", () => { // search facility and verify it's loaded or not - manageUserPage.interceptFacilitySearchReq(); - manageUserPage.typeFacilitySearch(facilityName); - manageUserPage.verifyFacilitySearchReq(); + facilityHome.interceptFacilitySearchReq(); + facilityHome.typeFacilitySearch(facilityName); + facilityHome.verifyFacilitySearchReq(); // verify facility name and card reflection facilityNotify.verifyUrlContains("Dummy+Facility+40"); - facilityPage.verifyFacilityBadgeContent(facilityName); - manageUserPage.assertFacilityInCard(facilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName, + true, + ); + facilityHome.assertFacilityInCard(facilityName); // send notification to a facility facilityHome.clickFacilityNotifyButton(); facilityNotify.verifyFacilityName(facilityName); diff --git a/cypress/e2e/facility_spec/FacilityInventory.cy.ts b/cypress/e2e/facility_spec/FacilityInventory.cy.ts index a9f32984efc..b3f77479763 100644 --- a/cypress/e2e/facility_spec/FacilityInventory.cy.ts +++ b/cypress/e2e/facility_spec/FacilityInventory.cy.ts @@ -9,7 +9,7 @@ describe("Inventory Management Section", () => { const inventoryName = "PPE"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/facility_spec/FacilityLocation.cy.ts b/cypress/e2e/facility_spec/FacilityLocation.cy.ts index 19c43d4dcf4..b4d153b16ed 100644 --- a/cypress/e2e/facility_spec/FacilityLocation.cy.ts +++ b/cypress/e2e/facility_spec/FacilityLocation.cy.ts @@ -1,3 +1,4 @@ +import LoginPage from "pageobject/Login/LoginPage"; import { pageNavigation } from "pageobject/utils/paginationHelpers"; import { v4 as uuidv4 } from "uuid"; @@ -13,6 +14,7 @@ describe("Location Management Section", () => { const facilityPage = new FacilityPage(); const facilityLocation = new FacilityLocation(); const facilityHome = new FacilityHome(); + const loginPage = new LoginPage(); const EXPECTED_LOCATION_ERROR_MESSAGES = [ "Name is required", @@ -46,7 +48,7 @@ describe("Location Management Section", () => { const serialNumber = Math.floor(Math.random() * 10 ** 10).toString(); before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/facility_spec/FacilityManage.cy.ts b/cypress/e2e/facility_spec/FacilityManage.cy.ts index 02c14958ccf..9f1523768c1 100644 --- a/cypress/e2e/facility_spec/FacilityManage.cy.ts +++ b/cypress/e2e/facility_spec/FacilityManage.cy.ts @@ -1,3 +1,6 @@ +import FacilityHome from "pageobject/Facility/FacilityHome"; +import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; + import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import FacilityManage from "../../pageobject/Facility/FacilityManage"; import LoginPage from "../../pageobject/Login/LoginPage"; @@ -6,16 +9,18 @@ describe("Facility Manage Functions", () => { const loginPage = new LoginPage(); const facilityManage = new FacilityManage(); const facilityPage = new FacilityPage(); + const facilityHome = new FacilityHome(); const facilityName = "Dummy Facility 40"; const facilityMiddlewareUpdateButton = "Update"; const facilityMiddleware = "dev-middleware.coronasafe.live"; const facilityUpdatedMiddleware = "updated.coronasafe.live"; const facilityMiddlewareSuccessfullNotification = "Facility middleware updated successfully"; - // const facilityHfridUpdateButton = "Link Health Facility"; - // const facilityHfridToastNotificationText = /Health Facility config updated successfully|Health ID registration failed/; - // const facilityHfrId = "IN180000018"; - // const facilityUpdatedHfrId = uuidv4(); + const facilityHfridUpdateButton = "Link Health Facility"; + const facilityHfridToastNotificationText = + /Health Facility config updated successfully|Health ID registration failed/; + const facilityHfrId = "IN180000018"; + const facilityUpdatedHfrId = "IN180000020"; const doctorCapacity = "5"; const doctorModifiedCapacity = "7"; const totalCapacity = "100"; @@ -24,7 +29,7 @@ describe("Facility Manage Functions", () => { const currentUpdatedOccupied = "100"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -33,8 +38,12 @@ describe("Facility Manage Functions", () => { cy.restoreLocalStorage(); cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/"); - facilityPage.typeFacilitySearch(facilityName); - facilityPage.verifyFacilityBadgeContent(facilityName); + facilityHome.typeFacilitySearch(facilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + facilityName, + true, + ); facilityPage.visitAlreadyCreatedFacility(); }); @@ -76,37 +85,36 @@ describe("Facility Manage Functions", () => { facilityManage.verifyMiddlewareAddressValue(facilityUpdatedMiddleware); }); - // TODO: enable this test after configuring testing specs for plugs - // it("Configure Facility Health ID", () => { - // facilityPage.clickManageFacilityDropdown(); - // facilityManage.clickFacilityConfigureButton(); - // // verify mandatory field error message - // facilityManage.clearHfrId(); - // facilityManage.clickButtonWithText(facilityHfridUpdateButton); - // facilityManage.checkErrorMessageVisibility( - // "Health Facility Id is required", - // ); - // // add facility health ID and verify notification - // facilityManage.typeHfrId(facilityHfrId); - // facilityManage.clickButtonWithText(facilityHfridUpdateButton); - // facilityManage.verifySuccessMessageVisibilityAndContent( - // facilityHfridToastNotificationText, - // true, - // ); - // // update the existing middleware - // facilityPage.clickManageFacilityDropdown(); - // facilityManage.clickFacilityConfigureButton(); - // facilityManage.typeHfrId(facilityUpdatedHfrId); - // facilityManage.clickButtonWithText(facilityHfridUpdateButton); - // facilityManage.verifySuccessMessageVisibilityAndContent( - // facilityHfridToastNotificationText, - // true, - // ); - // // verify its reflection - // facilityPage.clickManageFacilityDropdown(); - // facilityManage.clickFacilityConfigureButton(); - // facilityManage.verifyHfrIdValue(facilityUpdatedHfrId); - // }); + it("Configure Facility Health ID", () => { + facilityPage.clickManageFacilityDropdown(); + facilityManage.clickFacilityConfigureButton(); + // verify mandatory field error message + facilityManage.clearHfrId(); + facilityManage.clickButtonWithText(facilityHfridUpdateButton); + facilityManage.checkErrorMessageVisibility( + "Health Facility Id is required", + ); + // add facility health ID and verify notification + facilityManage.typeHfrId(facilityHfrId); + facilityManage.clickButtonWithText(facilityHfridUpdateButton); + facilityManage.verifySuccessMessageVisibilityAndContent( + facilityHfridToastNotificationText, + true, + ); + // update the existing middleware + facilityPage.clickManageFacilityDropdown(); + facilityManage.clickFacilityConfigureButton(); + facilityManage.typeHfrId(facilityUpdatedHfrId); + facilityManage.clickButtonWithText(facilityHfridUpdateButton); + facilityManage.verifySuccessMessageVisibilityAndContent( + facilityHfridToastNotificationText, + true, + ); + // verify its reflection + facilityPage.clickManageFacilityDropdown(); + facilityManage.clickFacilityConfigureButton(); + facilityManage.verifyHfrIdValue(facilityUpdatedHfrId); + }); it("Modify doctor capacity in Facility detail page", () => { // Add a doctor capacity diff --git a/cypress/e2e/hcx_spec/HcxClaims.cy.ts b/cypress/e2e/hcx_spec/HcxClaims.cy.ts index b698bb7ffd8..ccaa628febb 100644 --- a/cypress/e2e/hcx_spec/HcxClaims.cy.ts +++ b/cypress/e2e/hcx_spec/HcxClaims.cy.ts @@ -18,7 +18,7 @@ describe("HCX Claims configuration and approval workflow", () => { const patientInsurerName = "Demo Payor"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientBedManagement.cy.ts b/cypress/e2e/patient_spec/PatientBedManagement.cy.ts index 94f0869db9b..fbc31ff9698 100644 --- a/cypress/e2e/patient_spec/PatientBedManagement.cy.ts +++ b/cypress/e2e/patient_spec/PatientBedManagement.cy.ts @@ -15,7 +15,7 @@ describe("Patient swtich bed functionality", () => { const switchPatientTwo = "Dummy Patient Seven"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts b/cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts index 3eacd9b718f..4191d63b3e2 100644 --- a/cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts +++ b/cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts @@ -38,7 +38,7 @@ describe("Patient Consultation in multiple combination", () => { const patientIpNumber = `${Math.floor(Math.random() * 90 + 10)}/${Math.floor(Math.random() * 9000 + 1000)}`; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientConsultationDischarge.cy.ts b/cypress/e2e/patient_spec/PatientConsultationDischarge.cy.ts index 9e234c860da..b7ef6936804 100644 --- a/cypress/e2e/patient_spec/PatientConsultationDischarge.cy.ts +++ b/cypress/e2e/patient_spec/PatientConsultationDischarge.cy.ts @@ -20,7 +20,7 @@ describe("Patient Discharge based on multiple reason", () => { const doctorName = "Custom Doctor"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientDoctorConnect.cy.ts b/cypress/e2e/patient_spec/PatientDoctorConnect.cy.ts index 474af286b21..9dd43da4e13 100644 --- a/cypress/e2e/patient_spec/PatientDoctorConnect.cy.ts +++ b/cypress/e2e/patient_spec/PatientDoctorConnect.cy.ts @@ -13,7 +13,7 @@ describe("Patient Doctor Connect in consultation page", () => { const teleIcuUser = "Tester Doctor"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientDoctorNotes.cy.ts b/cypress/e2e/patient_spec/PatientDoctorNotes.cy.ts index d227d68ddcb..4fe19329af1 100644 --- a/cypress/e2e/patient_spec/PatientDoctorNotes.cy.ts +++ b/cypress/e2e/patient_spec/PatientDoctorNotes.cy.ts @@ -14,7 +14,7 @@ describe("Patient Discussion notes in the consultation page", () => { const discussionNotesSuccessMessage = "Note added successfully"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientFileUpload.cy.ts b/cypress/e2e/patient_spec/PatientFileUpload.cy.ts index dd3098163ec..ebf85d2cfad 100644 --- a/cypress/e2e/patient_spec/PatientFileUpload.cy.ts +++ b/cypress/e2e/patient_spec/PatientFileUpload.cy.ts @@ -18,7 +18,7 @@ function runTests( const patientNameTwo = "Dummy Patient Four"; const patientNameThree = "Dummy Patient Five"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -63,7 +63,7 @@ function runTests( it("User-level Based Permission for File Modification", () => { // Login as Nurse 1 - loginPage.login("dummynurse1", "Coronasafe@123"); + loginPage.loginByRole("nurse"); cy.reload(); // Visit the patient details page patientPage.visitPatient(patientNameThree); @@ -85,13 +85,13 @@ function runTests( cy.closeNotification(); patientFileUpload.verifyUploadFilePresence(newFileName); // Login as Nurse 2 - loginPage.login("dummynurse2", "Coronasafe@123"); + loginPage.loginByRole("nurse2"); cy.reload(); // Verify the file edit option is not available patientFileUpload.verifyUploadFilePresence(newFileName); patientFileUpload.verifyFileRenameOption(false); // Login as District Admin - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.reload(); // Verify the file edit option is available patientFileUpload.verifyUploadFilePresence(newFileName); diff --git a/cypress/e2e/patient_spec/PatientHomepage.cy.ts b/cypress/e2e/patient_spec/PatientHomepage.cy.ts index ac3e3f311ca..a120e282a2d 100644 --- a/cypress/e2e/patient_spec/PatientHomepage.cy.ts +++ b/cypress/e2e/patient_spec/PatientHomepage.cy.ts @@ -27,7 +27,7 @@ describe("Patient Homepage present functionalities", () => { const patientToDateBadge = "2023-12-07"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientInvestigation.cy.ts b/cypress/e2e/patient_spec/PatientInvestigation.cy.ts index 350614d0c9a..27d68aa257f 100644 --- a/cypress/e2e/patient_spec/PatientInvestigation.cy.ts +++ b/cypress/e2e/patient_spec/PatientInvestigation.cy.ts @@ -10,7 +10,7 @@ describe("Patient Investigation Creation from Patient consultation page", () => const patientName = "Dummy Patient Thirteen"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts index cfb739c8343..ec5aef250dc 100644 --- a/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts +++ b/cypress/e2e/patient_spec/PatientLogUpdate.cy.ts @@ -41,7 +41,7 @@ describe("Patient Log Update in Normal, Critical and TeleIcu", () => { const domicilaryPatient = "Dummy Patient Eleven"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientPrescription.cy.ts b/cypress/e2e/patient_spec/PatientPrescription.cy.ts index 96e6e23b1aa..61f8067eea0 100644 --- a/cypress/e2e/patient_spec/PatientPrescription.cy.ts +++ b/cypress/e2e/patient_spec/PatientPrescription.cy.ts @@ -15,7 +15,7 @@ const medicineIndicator = "Test Indicator"; describe("Patient Medicine Administration", () => { before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/patient_spec/PatientRegistration.cy.ts b/cypress/e2e/patient_spec/PatientRegistration.cy.ts index 2da35c840e0..a7c869401cd 100644 --- a/cypress/e2e/patient_spec/PatientRegistration.cy.ts +++ b/cypress/e2e/patient_spec/PatientRegistration.cy.ts @@ -70,7 +70,7 @@ describe("Patient Creation with consultation", () => { const patientOccupation = "Student"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/resource_spec/ResourcesAdvanceFilters.cy.ts b/cypress/e2e/resource_spec/ResourcesAdvanceFilters.cy.ts index aafc03680ee..33e11b4987a 100644 --- a/cypress/e2e/resource_spec/ResourcesAdvanceFilters.cy.ts +++ b/cypress/e2e/resource_spec/ResourcesAdvanceFilters.cy.ts @@ -1,6 +1,10 @@ +import LoginPage from "pageobject/Login/LoginPage"; + +const loginPage = new LoginPage(); + describe("Resource filter", () => { before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/resource_spec/ResourcesHomepage.cy.ts b/cypress/e2e/resource_spec/ResourcesHomepage.cy.ts index 02818638b3a..23077a71ed8 100644 --- a/cypress/e2e/resource_spec/ResourcesHomepage.cy.ts +++ b/cypress/e2e/resource_spec/ResourcesHomepage.cy.ts @@ -1,3 +1,5 @@ +import FacilityHome from "pageobject/Facility/FacilityHome"; + import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import LoginPage from "../../pageobject/Login/LoginPage"; import ResourcePage from "../../pageobject/Resource/ResourcePage"; @@ -7,10 +9,11 @@ describe("Resource Page", () => { const loginPage = new LoginPage(); const resourcePage = new ResourcePage(); const facilityPage = new FacilityPage(); + const facilityHome = new FacilityHome(); const phone_number = "9999999999"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -39,8 +42,8 @@ describe("Resource Page", () => { }); it("Create a resource request", () => { - cy.visit("/facility"); - cy.get("#facility-search").click().clear().type("dummy facility 40"); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch("dummy facility 40"); cy.intercept("GET", "**/api/v1/facility/**").as("loadFacilities"); cy.get("#facility-details").click(); cy.wait("@loadFacilities").its("response.statusCode").should("eq", 200); diff --git a/cypress/e2e/sample_test_spec/SampleTestAdvanceFilters.cy.ts b/cypress/e2e/sample_test_spec/SampleTestAdvanceFilters.cy.ts index ad2e57b7433..562eb22a75e 100644 --- a/cypress/e2e/sample_test_spec/SampleTestAdvanceFilters.cy.ts +++ b/cypress/e2e/sample_test_spec/SampleTestAdvanceFilters.cy.ts @@ -1,6 +1,10 @@ +import LoginPage from "pageobject/Login/LoginPage"; + +const loginPage = new LoginPage(); + describe("Sample Filter", () => { before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts b/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts index 98d69ccff41..491da5ee7ad 100644 --- a/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts +++ b/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts @@ -1,6 +1,10 @@ +import LoginPage from "pageobject/Login/LoginPage"; + +const loginPage = new LoginPage(); + describe("Sample List", () => { before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts b/cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts index da4d8aabd20..a4b26d328e5 100644 --- a/cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts +++ b/cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts @@ -24,7 +24,7 @@ describe("Sample Test", () => { const sampleTestResult = "Awaiting"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/shifting_spec/ShiftingAdvanceFilters.cy.ts b/cypress/e2e/shifting_spec/ShiftingAdvanceFilters.cy.ts index 01c1cbebd3a..1a773350b2d 100644 --- a/cypress/e2e/shifting_spec/ShiftingAdvanceFilters.cy.ts +++ b/cypress/e2e/shifting_spec/ShiftingAdvanceFilters.cy.ts @@ -1,12 +1,14 @@ +import LoginPage from "pageobject/Login/LoginPage"; import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; import ShiftingPage from "../../pageobject/Shift/ShiftFilters"; describe("Shifting section filter", () => { const shiftingPage = new ShiftingPage(); + const loginPage = new LoginPage(); before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/shifting_spec/ShiftingHomepage.cy.ts b/cypress/e2e/shifting_spec/ShiftingHomepage.cy.ts index a0a637f97f1..a94de68591d 100644 --- a/cypress/e2e/shifting_spec/ShiftingHomepage.cy.ts +++ b/cypress/e2e/shifting_spec/ShiftingHomepage.cy.ts @@ -1,6 +1,10 @@ +import LoginPage from "pageobject/Login/LoginPage"; + +const loginPage = new LoginPage(); + describe("Shifting Page", () => { before(() => { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); diff --git a/cypress/e2e/users_spec/UsersCreation.cy.ts b/cypress/e2e/users_spec/UsersCreation.cy.ts index 5212165a915..1c720e7df12 100644 --- a/cypress/e2e/users_spec/UsersCreation.cy.ts +++ b/cypress/e2e/users_spec/UsersCreation.cy.ts @@ -1,5 +1,7 @@ +import FacilityHome from "pageobject/Facility/FacilityHome"; import ManageUserPage from "pageobject/Users/ManageUserPage"; import UserProfilePage from "pageobject/Users/UserProfilePage"; +import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; import FacilityPage from "../../pageobject/Facility/FacilityCreation"; import LoginPage from "../../pageobject/Login/LoginPage"; @@ -17,6 +19,7 @@ describe("User Creation", () => { const manageUserPage = new ManageUserPage(); const userCreationPage = new UserCreationPage(); const facilityPage = new FacilityPage(); + const facilityHome = new FacilityHome(); const phoneNumber = generatePhoneNumber(); const emergencyPhoneNumber = generateEmergencyPhoneNumber(); const fillFacilityName = "Dummy Facility 40"; @@ -77,7 +80,7 @@ describe("User Creation", () => { const newUserDob = "25081999"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -178,9 +181,13 @@ describe("User Creation", () => { }); it("view user redirection from facility page", () => { - cy.visit("/facility"); - cy.get("#facility-search").click().clear().type(fillFacilityName); - facilityPage.verifyFacilityBadgeContent(fillFacilityName); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch(fillFacilityName); + advanceFilters.verifyFilterBadgePresence( + "Facility/District Name", + fillFacilityName, + true, + ); facilityPage.visitAlreadyCreatedFacility(); facilityPage.clickManageFacilityDropdown(); facilityPage.clickViewUsersOption(); diff --git a/cypress/e2e/users_spec/UsersHomepage.cy.ts b/cypress/e2e/users_spec/UsersHomepage.cy.ts index b32bb859e4e..8d86482645b 100644 --- a/cypress/e2e/users_spec/UsersHomepage.cy.ts +++ b/cypress/e2e/users_spec/UsersHomepage.cy.ts @@ -20,7 +20,7 @@ describe("User Homepage", () => { const doctorUserName = "dev-doctor2"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -43,30 +43,28 @@ describe("User Homepage", () => { advanceFilters.applySelectedFilter(); userPage.checkUsernameText(nurseUserName); // Verify the badges related to the data - userPage.verifyDataTestIdText("First Name", `First Name: ${firstName}`); - userPage.verifyDataTestIdText("Last Name", `Last Name: ${lastName}`); - userPage.verifyDataTestIdText( - "Phone Number", - `Phone Number: +91${phoneNumber}`, - ); - userPage.verifyDataTestIdText( + advanceFilters.verifyFilterBadgePresence("First Name", firstName, true); + advanceFilters.verifyFilterBadgePresence("Last Name", lastName, true); + advanceFilters.verifyFilterBadgePresence("Phone Number", phoneNumber, true); + advanceFilters.verifyFilterBadgePresence( "WhatsApp no.", - `WhatsApp no.: +91${altPhoneNumber}`, + altPhoneNumber, + true, ); - userPage.verifyDataTestIdText("Role", `Role: ${role}`); - userPage.verifyDataTestIdText( + advanceFilters.verifyFilterBadgePresence("Role", role, true); + advanceFilters.verifyFilterBadgePresence( "Home Facility", - `Home Facility: ${homeFacility}`, + homeFacility, + true, ); advanceFilters.clickAdvancedFiltersButton(); advanceFilters.clickClearAdvanceFilters(); - userPage.verifyDataTestIdNotVisible("First Name"); - userPage.verifyDataTestIdNotVisible("Last Name"); - userPage.verifyDataTestIdNotVisible("Phone Number"); - userPage.verifyDataTestIdNotVisible("WhatsApp no."); - userPage.verifyDataTestIdNotVisible("Role"); - userPage.verifyDataTestIdNotVisible("Home Facility"); - userPage.verifyDataTestIdNotVisible("District"); + advanceFilters.verifyFilterBadgePresence("First Name", "", false); + advanceFilters.verifyFilterBadgePresence("Last Name", "", false); + advanceFilters.verifyFilterBadgePresence("Phone Number", "", false); + advanceFilters.verifyFilterBadgePresence("WhatsApp no.", "", false); + advanceFilters.verifyFilterBadgePresence("Role", "", false); + advanceFilters.verifyFilterBadgePresence("Home Facility", "", false); }); it("Search by username", () => { diff --git a/cypress/e2e/users_spec/UsersManage.cy.ts b/cypress/e2e/users_spec/UsersManage.cy.ts index 74baee3deac..41557e87756 100644 --- a/cypress/e2e/users_spec/UsersManage.cy.ts +++ b/cypress/e2e/users_spec/UsersManage.cy.ts @@ -1,3 +1,4 @@ +import FacilityHome from "pageobject/Facility/FacilityHome"; import { advanceFilters } from "pageobject/utils/advanceFilterHelpers"; import LoginPage from "../../pageobject/Login/LoginPage"; @@ -8,6 +9,7 @@ describe("Manage User", () => { const loginPage = new LoginPage(); const userPage = new UserPage(); const manageUserPage = new ManageUserPage(); + const facilityHome = new FacilityHome(); const usernameToLinkFacilitydoc1 = "dummydoctor4"; const usernameToLinkFacilitydoc2 = "dummydoctor5"; const usernameToLinkFacilitydoc3 = "dummydoctor6"; @@ -22,7 +24,7 @@ describe("Manage User", () => { const linkedskill = "General Medicine"; before(() => { - loginPage.loginAsDistrictAdmin(); + loginPage.loginByRole("districtAdmin"); cy.saveLocalStorage(); }); @@ -68,9 +70,9 @@ describe("Manage User", () => { manageUserPage.assertSkillInAddedUserSkills(linkedskill); manageUserPage.clickCloseSlideOver(); // verifying the doctor connect - manageUserPage.navigateToFacility(); - manageUserPage.typeFacilitySearch(facilitytolinkskill); - manageUserPage.assertFacilityInCard(facilitytolinkskill); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch(facilitytolinkskill); + facilityHome.assertFacilityInCard(facilitytolinkskill); manageUserPage.clickFacilityPatients(); manageUserPage.clickDoctorConnectButton(); manageUserPage.assertSkillIndoctorconnect(linkedskill); @@ -134,9 +136,9 @@ describe("Manage User", () => { 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); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch(facilitytolinkusername); + facilityHome.assertFacilityInCard(facilitytolinkusername); manageUserPage.clickFacilityPatients(); manageUserPage.clickDoctorConnectButton(); manageUserPage.assertDoctorConnectVisibility(usernamerealname); diff --git a/cypress/e2e/users_spec/UsersProfile.cy.ts b/cypress/e2e/users_spec/UsersProfile.cy.ts index 32b812a188f..551fba4c0f1 100644 --- a/cypress/e2e/users_spec/UsersProfile.cy.ts +++ b/cypress/e2e/users_spec/UsersProfile.cy.ts @@ -1,3 +1,5 @@ +import FacilityHome from "pageobject/Facility/FacilityHome"; + import LoginPage from "../../pageobject/Login/LoginPage"; import ManageUserPage from "../../pageobject/Users/ManageUserPage"; import UserProfilePage from "../../pageobject/Users/UserProfilePage"; @@ -6,6 +8,7 @@ describe("Manage User Profile", () => { const loginPage = new LoginPage(); const userProfilePage = new UserProfilePage(); const manageUserPage = new ManageUserPage(); + const facilityHome = new FacilityHome(); const date_of_birth = "01011999"; const gender = "Male"; @@ -19,7 +22,7 @@ describe("Manage User Profile", () => { const facilitySearch = "Dummy Facility 40"; before(() => { - loginPage.loginAsDevDoctor(); + loginPage.loginByRole("devDoctor"); cy.saveLocalStorage(); }); @@ -65,9 +68,9 @@ describe("Manage User Profile", () => { userProfilePage.clickUpdateButton(); userProfilePage.assertVideoConnectLink("https://www.test.com"); // Go to particular facility doctor connect and verify the video connect link is present - manageUserPage.navigateToFacility(); - manageUserPage.typeFacilitySearch(facilitySearch); - manageUserPage.assertFacilityInCard(facilitySearch); + facilityHome.navigateToFacilityHomepage(); + facilityHome.typeFacilitySearch(facilitySearch); + facilityHome.assertFacilityInCard(facilitySearch); manageUserPage.clickFacilityPatients(); manageUserPage.clickDoctorConnectButton(); manageUserPage.assertVideoConnectLink("Dev Doctor", "https://www.test.com"); diff --git a/cypress/pageobject/Asset/AssetCreation.ts b/cypress/pageobject/Asset/AssetCreation.ts index ec631768154..5e590a0f7fd 100644 --- a/cypress/pageobject/Asset/AssetCreation.ts +++ b/cypress/pageobject/Asset/AssetCreation.ts @@ -208,51 +208,6 @@ export class AssetPage { ); } - selectImportFacility(facilityName: string) { - cy.get("input[name='facilities']") - .type(facilityName) - .then(() => { - cy.get("[role='option']").contains(facilityName).click(); - }); - } - - selectassetimportbutton() { - cy.get("[data-testid=import-asset-button]").click(); - } - - selectJsonExportButton() { - cy.intercept("GET", "**/api/v1/asset/?**json=true**").as("getJsonexport"); - cy.get("#export-json-option").click(); - cy.wait("@getJsonexport").its("response.statusCode").should("eq", 200); - } - - selectCsvExportButton() { - cy.intercept("GET", "**/api/v1/asset/?**csv=true**").as("getCsvexport"); - cy.get("#export-csv-option").click(); - cy.wait("@getCsvexport").its("response.statusCode").should("eq", 200); - } - - selectImportOption() { - cy.get(".import-assets-button").click(); - } - - importAssetFile() { - cy.get("[data-testid=import-file]") - .selectFile("cypress/fixtures/sample-asset.xlsx", { force: true }) - .wait(100); - } - - selectImportLocation(locationName: string) { - cy.get("[data-testid=select-import-location]").click(); - cy.get("li[role=option]").contains(locationName).click(); - } - - clickImportAsset() { - cy.intercept("POST", "**/api/v1/asset/").as("importAsset"); - cy.get("#submit").contains("Import").click(); - cy.wait("@importAsset").its("response.statusCode").should("eq", 201); - } - clickupdatedetailbutton() { cy.get("[data-testid=asset-update-button]").click(); } diff --git a/cypress/pageobject/Asset/AssetFilters.ts b/cypress/pageobject/Asset/AssetFilters.ts index 7e7b5013d5d..b562841a598 100644 --- a/cypress/pageobject/Asset/AssetFilters.ts +++ b/cypress/pageobject/Asset/AssetFilters.ts @@ -1,68 +1,7 @@ export class AssetFilters { - filterAssets( - facilityName: string, - assetStatus: string, - assetClass: string, - assetLocation: string, - ) { - cy.contains("Advanced Filters").click(); - cy.get("input[name='Facilities']") - .click() - .type(facilityName) - .then(() => { - cy.get("[role='option']").contains(facilityName).click(); - }); - cy.get("#asset-status") - .click() - .then(() => { - cy.get("[role='option']").contains(assetStatus).click(); - }); - cy.get("#asset-class") - .click() - .then(() => { - cy.get("[role='option']").contains(assetClass).click(); - }); - cy.get("#Facilities-location") - .click() - .type(assetLocation) - .then(() => { - cy.get("[role='option']").contains(assetLocation).click(); - }); - cy.contains("Apply").click(); - } - clearFilters() { - cy.intercept("GET", "**/api/v1/asset/**").as("clearAssets"); - cy.get("#clear-filter").click(); - cy.wait("@clearAssets").its("response.statusCode").should("eq", 200); - cy.location("pathname").should("match", /\/assets$/); - cy.url().then((url) => { - const queryParams = new URL(url).searchParams; - let allEmpty = true; - const blacklistedKeys = ["page", "limit", "offset"]; - - queryParams.forEach((value, key) => { - if (value !== "" && !blacklistedKeys.includes(key)) { - allEmpty = false; - } - }); - - expect(allEmpty).to.be.true; - }); - } - clickslideoverbackbutton() { - cy.get("#close-slide-over").click(); - } - // Assertions - assertFacilityText(text: string) { - cy.get("[data-testid=Facility]").should("contain", text); - } - assertAssetClassText(text: string) { - cy.get("[data-testid='Asset Class']").should("contain", text); - } - assertStatusText(text: string) { - cy.get("[data-testid=Status]").should("contain", text); - } - assertLocationText(text: string) { - cy.get("[data-testid=Location]").should("contain", text); + filterAssets(assetStatus: string, assetClass: string, assetLocation: string) { + cy.clickAndSelectOption("#asset-status", assetStatus); + cy.clickAndSelectOption("#asset-class", assetClass); + cy.typeAndSelectOption("#Facilities-location", assetLocation); } } diff --git a/cypress/pageobject/Asset/AssetHome.ts b/cypress/pageobject/Asset/AssetHome.ts new file mode 100644 index 00000000000..e127b785100 --- /dev/null +++ b/cypress/pageobject/Asset/AssetHome.ts @@ -0,0 +1,112 @@ +export class AssetHome { + clickAssetByName(assetName: string) { + cy.intercept("GET", "**/api/v1/asset/**").as("clearAssets"); + cy.get("[data-testid='created-asset-list']").contains(assetName).click(); + cy.wait("@clearAssets").its("response.statusCode").should("eq", 200); + } + + typeAssetSearch(name: string) { + cy.get("#asset-search").click().type(name); + } + + verifyAssetIsPresent(assetName: string) { + cy.get("[data-testid=created-asset-list]") + .first() + .should("contain", assetName); + } + + clickAssetDetailsUpdateButton() { + cy.verifyAndClickElement("[data-testid='asset-update-button']", "Update"); + } + + clearAndTypeQRCode(qrCode: string) { + cy.get("#qr_code_id").clear(); + cy.get("#qr_code_id").click().type(qrCode); + } + + clearAndTypeSerialNumber(serialNumber: string) { + cy.get("#serial-number").clear(); + cy.get("#serial-number").click().type(serialNumber); + } + + clickAssetSubmitButton() { + cy.intercept("GET", "**/api/v1/asset/**").as("getAssets"); + cy.get("#submit").click(); + cy.wait("@getAssets").its("response.statusCode").should("eq", 200); + } + + clickAssetUpdateSubmitButton() { + cy.intercept("GET", "**/api/v1/asset/**").as("getAssets"); + cy.clickSubmitButton("Update"); + cy.wait("@getAssets").its("response.statusCode").should("eq", 200); + } + + navigateToAssetsPage() { + cy.visit("/assets"); + } + + verifyAssetListContains(dummyCameraText: string) { + cy.get("[data-testid='created-asset-list']").should( + "contain", + dummyCameraText, + ); + } + + scanAssetQR() { + cy.contains("Scan Asset QR").click().wait(1000); + cy.get("video").should("exist"); + cy.get("button").contains("Close Scanner").should("exist").click(); + } + + selectImportFacility(facilityName: string) { + cy.get("input[name='facilities']") + .type(facilityName) + .then(() => { + cy.get("[role='option']").contains(facilityName).click(); + }); + } + + selectAssetImportButton(action: "click" | "verifyNotExist"): void { + const selector = "[data-testid=import-asset-button]"; + if (action === "click") { + cy.get(selector).click(); + } else if (action === "verifyNotExist") { + cy.get(selector).should("not.exist"); + } + } + + selectJsonExportButton() { + cy.intercept("GET", "**/api/v1/asset/?**json=true**").as("getJsonexport"); + cy.get("#export-json-option").click(); + cy.wait("@getJsonexport").its("response.statusCode").should("eq", 200); + } + + selectCsvExportButton() { + cy.intercept("GET", "**/api/v1/asset/?**csv=true**").as("getCsvexport"); + cy.get("#export-csv-option").click(); + cy.wait("@getCsvexport").its("response.statusCode").should("eq", 200); + } + + selectImportOption() { + cy.get(".import-assets-button").click(); + } + + importAssetFile() { + cy.get("[data-testid=import-file]") + .selectFile("cypress/fixtures/sample-asset.xlsx", { force: true }) + .wait(100); + } + + selectImportLocation(locationName: string) { + cy.clickAndSelectOption( + "[data-testid=select-import-location]", + locationName, + ); + } + + clickImportAsset() { + cy.intercept("POST", "**/api/v1/asset/").as("importAsset"); + cy.clickSubmitButton("Import"); + cy.wait("@importAsset").its("response.statusCode").should("eq", 201); + } +} diff --git a/cypress/pageobject/Asset/AssetPagination.ts b/cypress/pageobject/Asset/AssetPagination.ts deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/cypress/pageobject/Asset/AssetQRScan.ts b/cypress/pageobject/Asset/AssetQRScan.ts deleted file mode 100644 index a88f378f02f..00000000000 --- a/cypress/pageobject/Asset/AssetQRScan.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class AssetQRScanPage { - scanAssetQR() { - cy.contains("Scan Asset QR").click().wait(1000); - cy.get("video").should("exist"); - cy.get("button").contains("Close Scanner").should("exist").click(); - } -} diff --git a/cypress/pageobject/Asset/AssetSearch.ts b/cypress/pageobject/Asset/AssetSearch.ts deleted file mode 100644 index 653c7bdd89c..00000000000 --- a/cypress/pageobject/Asset/AssetSearch.ts +++ /dev/null @@ -1,60 +0,0 @@ -export class AssetSearchPage { - typeSearchKeyword(keyword: string) { - cy.get("#search").click().clear(); - cy.get("#search").click().type(keyword); - } - - pressEnter() { - cy.get("[name='search']").type("{enter}"); - } - - clickAssetByName(assetName: string) { - cy.intercept("GET", "**/api/v1/asset/**").as("clearAssets"); - cy.get("[data-testid='created-asset-list']").contains(assetName).click(); - cy.wait("@clearAssets").its("response.statusCode").should("eq", 200); - } - - verifyBadgeContent(expectedText: string) { - cy.get("[data-testid='Name/Serial No./QR ID']").should( - "contain", - expectedText, - ); - } - - verifyAssetIsPresent(assetName: string) { - cy.get("[data-testid=created-asset-list]") - .first() - .should("contain", assetName); - } - - clickUpdateButton() { - cy.get("[data-testid='asset-update-button']").contains("Update").click(); - } - - clearAndTypeQRCode(qrCode: string) { - cy.get("#qr_code_id").clear(); - cy.get("#qr_code_id").click().type(qrCode); - } - - clearAndTypeSerialNumber(serialNumber: string) { - cy.get("#serial-number").clear(); - cy.get("#serial-number").click().type(serialNumber); - } - - clickAssetSubmitButton() { - cy.intercept("GET", "**/api/v1/asset/**").as("getAssets"); - cy.get("#submit").click(); - cy.wait("@getAssets").its("response.statusCode").should("eq", 200); - } - - visitAssetsPage() { - cy.visit("/assets"); - } - - verifyAssetListContains(dummyCameraText: string) { - cy.get("[data-testid='created-asset-list']").should( - "contain", - dummyCameraText, - ); - } -} diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index f3cf8268703..4c064956fcc 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -9,10 +9,6 @@ class FacilityPage { .should("eq", 200); } - typeFacilitySearch(facilityName: string) { - cy.get("#facility-search").click().clear().type(facilityName); - } - selectFacilityType(facility: string) { advanceFilters.selectFacilityType(facility); } @@ -312,29 +308,6 @@ class FacilityPage { cy.get("h1.text-3xl.font-bold", { timeout: 10000 }).should("be.visible"); } - verifyFacilityBadgeContent(expectedText: string) { - cy.get("[data-testid='Facility/District Name']").should( - "contain", - expectedText, - ); - } - - verifyStateBadgeContent(expectedText: string) { - cy.get("[data-testid='State']").should("contain", expectedText); - } - - verifyDistrictBadgeContent(expectedText: string) { - cy.get("[data-testid='District']").should("contain", expectedText); - } - - verifyLocalBodyBadgeContent(expectedText: string) { - cy.get("[data-testid='Local Body']").should("contain", expectedText); - } - - verifyFacilityTypeBadgeContent(expectedText: string) { - cy.get("[data-testid='Facility type']").should("contain", expectedText); - } - verifyfacilitycreateassetredirection() { cy.url().should("include", "/assets/new"); } diff --git a/cypress/pageobject/Facility/FacilityHome.ts b/cypress/pageobject/Facility/FacilityHome.ts index 55dfd9aa87e..95d89b6c8a2 100644 --- a/cypress/pageobject/Facility/FacilityHome.ts +++ b/cypress/pageobject/Facility/FacilityHome.ts @@ -1,7 +1,6 @@ class FacilityHome { // Selectors exportButton = "#export-button"; - searchButton = "#facility-search"; menuItem = "[role='menuitem']"; // Operations @@ -10,8 +9,24 @@ class FacilityHome { cy.get(this.exportButton).click(); } - clickSearchButton() { - cy.get(this.searchButton).click(); + navigateToFacilityHomepage() { + cy.visit("/facility"); + } + + assertFacilityInCard(facilityName: string) { + cy.get("#facility-name-card").should("contain", facilityName); + } + + interceptFacilitySearchReq() { + cy.intercept("GET", "**/api/v1/facility/**").as("searchFacility"); + } + + verifyFacilitySearchReq() { + cy.wait("@searchFacility").its("response.statusCode").should("eq", 200); + } + + typeFacilitySearch(facilityName: string) { + cy.get("#facility-search").click().clear().type(facilityName); } clickMenuItem(itemName: string) { diff --git a/cypress/pageobject/Login/LoginPage.ts b/cypress/pageobject/Login/LoginPage.ts index 714004023f7..481c6ec3045 100644 --- a/cypress/pageobject/Login/LoginPage.ts +++ b/cypress/pageobject/Login/LoginPage.ts @@ -1,16 +1,12 @@ -// LoginPage.ts +import { users } from "../utils/userConfig"; class LoginPage { - loginAsDistrictAdmin(): void { - cy.loginByApi("devdistrictadmin", "Coronasafe@123"); - } - - loginAsDevDoctor(): void { - cy.loginByApi("devdoctor", "Coronasafe@123"); - } - - loginAsStaff(): void { - cy.loginByApi("staffdev", "Coronasafe@123"); + loginByRole(role: keyof typeof users): void { + const user = users[role]; + if (!user) { + throw new Error(`Role "${role}" is not defined in userConfig`); + } + cy.loginByApi(user.username, user.password); } loginManuallyAsDistrictAdmin(isCorrectCredentials: boolean = true): void { @@ -29,10 +25,6 @@ class LoginPage { cy.clickSubmitButton("Login"); } - login(username: string, password: string): void { - cy.loginByApi(username, password); - } - ensureLoggedIn(): void { cy.get("#user-profile-name").click(); cy.get("#sign-out-button").scrollIntoView(); diff --git a/cypress/pageobject/Users/ManageUserPage.ts b/cypress/pageobject/Users/ManageUserPage.ts index ea54a0d4977..01871acd97d 100644 --- a/cypress/pageobject/Users/ManageUserPage.ts +++ b/cypress/pageobject/Users/ManageUserPage.ts @@ -90,26 +90,6 @@ export class ManageUserPage { ); } - navigateToFacility() { - cy.visit("/facility"); - } - - typeFacilitySearch(facilityName: string) { - cy.get("#facility-search").click().clear().type(facilityName); - } - - interceptFacilitySearchReq() { - cy.intercept("GET", "**/api/v1/facility/**").as("searchFacility"); - } - - verifyFacilitySearchReq() { - cy.wait("@searchFacility").its("response.statusCode").should("eq", 200); - } - - assertFacilityInCard(facilityName: string) { - cy.get("#facility-name-card").should("contain", facilityName); - } - clickFacilityPatients() { cy.get("#facility-patients").should("be.visible"); cy.get("#facility-patients").click(); diff --git a/cypress/pageobject/Users/UserSearch.ts b/cypress/pageobject/Users/UserSearch.ts index 6b727aa2040..9d996abd83f 100644 --- a/cypress/pageobject/Users/UserSearch.ts +++ b/cypress/pageobject/Users/UserSearch.ts @@ -68,14 +68,6 @@ export class UserPage { cy.typeAndSelectOption("input[name='home_facility']", facility); } - verifyDataTestIdText(testId: string, text: string) { - cy.get(`[data-testid="${testId}"]`).contains(text).should("be.visible"); - } - - verifyDataTestIdNotVisible(testId: string) { - cy.get(`[data-testid="${testId}"]`).should("not.be.visible"); - } - verifyMultipleBadgesWithSameId(alreadylinkedusersviews: string[]) { cy.get("#user-view-name").then(($elements) => { const userViews = $elements diff --git a/cypress/pageobject/utils/advanceFilterHelpers.ts b/cypress/pageobject/utils/advanceFilterHelpers.ts index a624311c197..22925fc2c23 100644 --- a/cypress/pageobject/utils/advanceFilterHelpers.ts +++ b/cypress/pageobject/utils/advanceFilterHelpers.ts @@ -23,7 +23,28 @@ export const advanceFilters = { cy.clickAndSelectOption("#facility_type", facilityType); }, + typeFacilityName(facilityName: string) { + cy.typeAndSelectOption("input[name='Facilities']", facilityName); + }, + + clickslideoverbackbutton() { + cy.get("#close-slide-over").click(); + }, + clickClearAdvanceFilters() { cy.verifyAndClickElement("#clear-filter", "Clear"); }, + + verifyFilterBadgePresence( + badgeTestId: string, + text: string, + visible: boolean = true, + ) { + const badgeElement = cy.get(`[data-testid="${badgeTestId}"]`); + if (visible) { + badgeElement.contains(text).should("be.visible"); + } else { + badgeElement.should("not.be.visible"); + } + }, }; diff --git a/cypress/pageobject/utils/userConfig.ts b/cypress/pageobject/utils/userConfig.ts new file mode 100644 index 00000000000..270fbfba10a --- /dev/null +++ b/cypress/pageobject/utils/userConfig.ts @@ -0,0 +1,8 @@ +export const users = { + districtAdmin: { username: "devdistrictadmin", password: "Coronasafe@123" }, + devDoctor: { username: "devdoctor", password: "Coronasafe@123" }, + nurse: { username: "dummynurse1", password: "Coronasafe@123" }, + nurse2: { username: "dummynurse2", password: "Coronasafe@123" }, +}; + +export const nonAdminRoles = ["devDoctor", "nurse"] as const; diff --git a/package-lock.json b/package-lock.json index 2b1c83617d0..cf929b13efc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,14 +21,14 @@ "@pnotify/mobile": "^5.2.0", "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", - "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-popover": "^1.1.2", "@radix-ui/react-scroll-area": "^1.2.0", + "@radix-ui/react-icons": "^1.3.2", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-toast": "^1.2.2", - "@radix-ui/react-tooltip": "^1.1.3", - "@sentry/browser": "^8.37.1", + "@radix-ui/react-tooltip": "^1.1.4", + "@sentry/browser": "^8.42.0", "@yudiel/react-qr-scanner": "^2.0.8", "bowser": "^2.11.0", "browser-image-compression": "^2.0.2", @@ -3907,12 +3907,12 @@ } }, "node_modules/@radix-ui/react-icons": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@radix-ui/react-icons/-/react-icons-1.3.1.tgz", - "integrity": "sha512-QvYompk0X+8Yjlo/Fv4McrzxohDdM5GgLHyQcPpcsPvlOSXCGFjdbuyGL5dzRbg0GpknAjQJJZzdiRK7iWVuFQ==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@radix-ui/react-icons/-/react-icons-1.3.2.tgz", + "integrity": "sha512-fyQIhGDhzfc9pK2kH6Pl9c4BDJGfMkPqkyIgYDthyNYoNg3wVhoJMMh19WS4Up/1KMPFVpNsT2q3WmXn2N1m6g==", "license": "MIT", "peerDependencies": { - "react": "^16.x || ^17.x || ^18.x || ^19.x" + "react": "^16.x || ^17.x || ^18.x || ^19.0.0 || ^19.0.0-rc" } }, "node_modules/@radix-ui/react-id": { @@ -4278,9 +4278,9 @@ } }, "node_modules/@radix-ui/react-tooltip": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.1.3.tgz", - "integrity": "sha512-Z4w1FIS0BqVFI2c1jZvb/uDVJijJjJ2ZMuPV81oVgTZ7g3BZxobplnMVvXtFWgtozdvYJ+MFWtwkM5S2HnAong==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.1.4.tgz", + "integrity": "sha512-QpObUH/ZlpaO4YgHSaYzrLO2VuO+ZBFFgGzjMUPwtiYnAzzNNDPJeEGRrT7qNOrWm/Jr08M1vlp+vTHtnSQ0Uw==", "license": "MIT", "dependencies": { "@radix-ui/primitive": "1.1.0", @@ -4839,58 +4839,50 @@ ] }, "node_modules/@sentry-internal/browser-utils": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry-internal/browser-utils/-/browser-utils-8.37.1.tgz", - "integrity": "sha512-OSR/V5GCsSCG7iapWtXCT/y22uo3HlawdEgfM1NIKk1mkP15UyGQtGEzZDdih2H+SNuX1mp9jQLTjr5FFp1A5w==", + "version": "8.42.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/browser-utils/-/browser-utils-8.42.0.tgz", + "integrity": "sha512-xzgRI0wglKYsPrna574w1t38aftuvo44gjOKFvPNGPnYfiW9y4m+64kUz3JFbtanvOrKPcaITpdYiB4DeJXEbA==", "license": "MIT", "dependencies": { - "@sentry/core": "8.37.1", - "@sentry/types": "8.37.1", - "@sentry/utils": "8.37.1" + "@sentry/core": "8.42.0" }, "engines": { "node": ">=14.18" } }, "node_modules/@sentry-internal/feedback": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry-internal/feedback/-/feedback-8.37.1.tgz", - "integrity": "sha512-Se25NXbSapgS2S+JssR5YZ48b3OY4UGmAuBOafgnMW91LXMxRNWRbehZuNUmjjHwuywABMxjgu+Yp5uJDATX+g==", + "version": "8.42.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/feedback/-/feedback-8.42.0.tgz", + "integrity": "sha512-dkIw5Wdukwzngg5gNJ0QcK48LyJaMAnBspqTqZ3ItR01STi6Z+6+/Bt5XgmrvDgRD+FNBinflc5zMmfdFXXhvw==", "license": "MIT", "dependencies": { - "@sentry/core": "8.37.1", - "@sentry/types": "8.37.1", - "@sentry/utils": "8.37.1" + "@sentry/core": "8.42.0" }, "engines": { "node": ">=14.18" } }, "node_modules/@sentry-internal/replay": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry-internal/replay/-/replay-8.37.1.tgz", - "integrity": "sha512-E/Plhisk/pXJjOdOU12sg8m/APTXTA21iEniidP6jW3/+O0tD/H/UovEqa4odNTqxPMa798xHQSQNt5loYiaLA==", + "version": "8.42.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/replay/-/replay-8.42.0.tgz", + "integrity": "sha512-oNcJEBlDfXnRFYC5Mxj5fairyZHNqlnU4g8kPuztB9G5zlsyLgWfPxzcn1ixVQunth2/WZRklDi4o1ZfyHww7w==", "license": "MIT", "dependencies": { - "@sentry-internal/browser-utils": "8.37.1", - "@sentry/core": "8.37.1", - "@sentry/types": "8.37.1", - "@sentry/utils": "8.37.1" + "@sentry-internal/browser-utils": "8.42.0", + "@sentry/core": "8.42.0" }, "engines": { "node": ">=14.18" } }, "node_modules/@sentry-internal/replay-canvas": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry-internal/replay-canvas/-/replay-canvas-8.37.1.tgz", - "integrity": "sha512-1JLAaPtn1VL5vblB0BMELFV0D+KUm/iMGsrl4/JpRm0Ws5ESzQl33DhXVv1IX/ZAbx9i14EjR7MG9+Hj70tieQ==", + "version": "8.42.0", + "resolved": "https://registry.npmjs.org/@sentry-internal/replay-canvas/-/replay-canvas-8.42.0.tgz", + "integrity": "sha512-XrPErqVhPsPh/oFLVKvz7Wb+Fi2J1zCPLeZCxWqFuPWI2agRyLVu0KvqJyzSpSrRAEJC/XFzuSVILlYlXXSfgA==", "license": "MIT", "dependencies": { - "@sentry-internal/replay": "8.37.1", - "@sentry/core": "8.37.1", - "@sentry/types": "8.37.1", - "@sentry/utils": "8.37.1" + "@sentry-internal/replay": "8.42.0", + "@sentry/core": "8.42.0" }, "engines": { "node": ">=14.18" @@ -4949,32 +4941,26 @@ } }, "node_modules/@sentry/browser": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-8.37.1.tgz", - "integrity": "sha512-5ym+iGiIpjIKKpMWi9S3/tXh9xneS+jqxwRTJqed3cb8i4ydfMAAP8sM3U8xMCWWABpWyIUW+fpewC0tkhE1aQ==", + "version": "8.42.0", + "resolved": "https://registry.npmjs.org/@sentry/browser/-/browser-8.42.0.tgz", + "integrity": "sha512-lStrEk609KJHwXfDrOgoYVVoFFExixHywxSExk7ZDtwj2YPv6r6Y1gogvgr7dAZj7jWzadHkxZ33l9EOSJBfug==", "license": "MIT", "dependencies": { - "@sentry-internal/browser-utils": "8.37.1", - "@sentry-internal/feedback": "8.37.1", - "@sentry-internal/replay": "8.37.1", - "@sentry-internal/replay-canvas": "8.37.1", - "@sentry/core": "8.37.1", - "@sentry/types": "8.37.1", - "@sentry/utils": "8.37.1" + "@sentry-internal/browser-utils": "8.42.0", + "@sentry-internal/feedback": "8.42.0", + "@sentry-internal/replay": "8.42.0", + "@sentry-internal/replay-canvas": "8.42.0", + "@sentry/core": "8.42.0" }, "engines": { "node": ">=14.18" } }, "node_modules/@sentry/core": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry/core/-/core-8.37.1.tgz", - "integrity": "sha512-82csXby589iDupM3VgCHJeWZagUyEEaDnbFcoZ/Z91QX2Sjq8FcF5OsforoXjw09i0XTFqlkFAnQVpDBmMXcpQ==", + "version": "8.42.0", + "resolved": "https://registry.npmjs.org/@sentry/core/-/core-8.42.0.tgz", + "integrity": "sha512-ac6O3pgoIbU6rpwz6LlwW0wp3/GAHuSI0C5IsTgIY6baN8rOBnlAtG6KrHDDkGmUQ2srxkDJu9n1O6Td3cBCqw==", "license": "MIT", - "dependencies": { - "@sentry/types": "8.37.1", - "@sentry/utils": "8.37.1" - }, "engines": { "node": ">=14.18" } @@ -5086,27 +5072,6 @@ "node": ">=8" } }, - "node_modules/@sentry/types": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry/types/-/types-8.37.1.tgz", - "integrity": "sha512-ryMOTROLSLINKFEbHWvi7GigNrsQhsaScw2NddybJGztJQ5UhxIGESnxGxWCufBmWFDwd7+5u0jDPCVUJybp7w==", - "license": "MIT", - "engines": { - "node": ">=14.18" - } - }, - "node_modules/@sentry/utils": { - "version": "8.37.1", - "resolved": "https://registry.npmjs.org/@sentry/utils/-/utils-8.37.1.tgz", - "integrity": "sha512-Qtn2IfpII12K17txG/ZtTci35XYjYi4CxbQ3j7nXY7toGv/+MqPXwV5q2i9g94XaSXlE5Wy9/hoCZoZpZs/djA==", - "license": "MIT", - "dependencies": { - "@sentry/types": "8.37.1" - }, - "engines": { - "node": ">=14.18" - } - }, "node_modules/@surma/rollup-plugin-off-main-thread": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-2.2.3.tgz", diff --git a/package.json b/package.json index cdc55470bcb..012fef4552c 100644 --- a/package.json +++ b/package.json @@ -60,14 +60,14 @@ "@pnotify/mobile": "^5.2.0", "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", - "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-popover": "^1.1.2", "@radix-ui/react-scroll-area": "^1.2.0", + "@radix-ui/react-icons": "^1.3.2", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-toast": "^1.2.2", - "@radix-ui/react-tooltip": "^1.1.3", - "@sentry/browser": "^8.37.1", + "@radix-ui/react-tooltip": "^1.1.4", + "@sentry/browser": "^8.42.0", "@yudiel/react-qr-scanner": "^2.0.8", "bowser": "^2.11.0", "browser-image-compression": "^2.0.2", diff --git a/public/locale/en.json b/public/locale/en.json index 8fa414a49ee..f86d78fa3aa 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1386,6 +1386,7 @@ "upload_headings__patient": "Upload New Patient File", "upload_headings__sample_report": "Upload Sample Report", "upload_headings__supporting_info": "Upload Supporting Info", + "upload_report": "Upload Report", "uploading": "Uploading", "use_existing_abha_address": "Use Existing ABHA Address", "user_deleted_successfuly": "User Deleted Successfuly", diff --git a/src/CAREUI/misc/PrintPreview.tsx b/src/CAREUI/misc/PrintPreview.tsx index 53eda1339ac..daf79ecbb34 100644 --- a/src/CAREUI/misc/PrintPreview.tsx +++ b/src/CAREUI/misc/PrintPreview.tsx @@ -8,7 +8,8 @@ import { ZoomTransform, } from "@/CAREUI/interactive/Zoom"; -import ButtonV2 from "@/components/Common/ButtonV2"; +import { Button } from "@/components/ui/button"; + import Page from "@/components/Common/Page"; import useBreakpoints from "@/hooks/useBreakpoints"; @@ -30,10 +31,10 @@ export default function PrintPreview(props: Props) {
- +
diff --git a/src/components/Assets/AssetsList.tsx b/src/components/Assets/AssetsList.tsx index eceee4887e8..f48723f2784 100644 --- a/src/components/Assets/AssetsList.tsx +++ b/src/components/Assets/AssetsList.tsx @@ -377,6 +377,7 @@ const AssetsList = () => { />
updateQuery({ [e.name]: e.value })} diff --git a/src/components/Patient/PatientHome.tsx b/src/components/Patient/PatientHome.tsx index d6b9844b699..518ac33bdf2 100644 --- a/src/components/Patient/PatientHome.tsx +++ b/src/components/Patient/PatientHome.tsx @@ -376,10 +376,22 @@ export const PatientHome = (props: { .treating_physician_object, )}

-

+ {!!skillsQuery.data?.results?.length && formatSkills(skillsQuery.data?.results)} -

+ {(skillsQuery.data?.results?.length || 0) > 3 && ( +
    + {skillsQuery.data?.results.map((skill) => ( +
  • + {skill.skill_object.name} +
  • + ))} +
+ )} +
)} diff --git a/src/components/Patient/UpdateStatusDialog.tsx b/src/components/Patient/UpdateStatusDialog.tsx index 9414ba9bb95..e9a767847aa 100644 --- a/src/components/Patient/UpdateStatusDialog.tsx +++ b/src/components/Patient/UpdateStatusDialog.tsx @@ -1,31 +1,28 @@ -import { useEffect, useReducer, useState } from "react"; +import { useEffect, useReducer } from "react"; import { useTranslation } from "react-i18next"; import CareIcon from "@/CAREUI/icons/CareIcon"; -import { Submit } from "@/components/Common/ButtonV2"; +import { Button } from "@/components/ui/button"; + import ConfirmDialog from "@/components/Common/ConfirmDialog"; import { LinearProgressWithLabel } from "@/components/Files/FileUpload"; import CheckBoxFormField from "@/components/Form/FormFields/CheckBoxFormField"; import { SelectFormField } from "@/components/Form/FormFields/SelectFormField"; import TextFormField from "@/components/Form/FormFields/TextFormField"; import { FieldChangeEvent } from "@/components/Form/FormFields/Utils"; -import { - CreateFileResponse, - SampleTestModel, -} from "@/components/Patient/models"; + +import useFileUpload from "@/hooks/useFileUpload"; import { - HEADER_CONTENT_TYPES, SAMPLE_FLOW_RULES, SAMPLE_TEST_RESULT, SAMPLE_TEST_STATUS, } from "@/common/constants"; import * as Notification from "@/Utils/Notifications"; -import routes from "@/Utils/request/api"; -import request from "@/Utils/request/request"; -import uploadFile from "@/Utils/request/uploadFile"; + +import { SampleTestModel } from "./models"; interface Props { sample: SampleTestModel; @@ -34,7 +31,6 @@ interface Props { } const statusChoices = [...SAMPLE_TEST_STATUS]; - const statusFlow = { ...SAMPLE_FLOW_RULES }; const initForm: any = { @@ -60,17 +56,16 @@ const updateStatusReducer = (state = initialState, action: any) => { return state; } }; - const UpdateStatusDialog = (props: Props) => { const { t } = useTranslation(); const { sample, handleOk, handleCancel } = props; const [state, dispatch] = useReducer(updateStatusReducer, initialState); - const [file, setfile] = useState(); - const [contentType, setcontentType] = useState(""); - const [uploadPercent, setUploadPercent] = useState(0); - const [uploadStarted, setUploadStarted] = useState(false); - const [uploadDone, setUploadDone] = useState(false); + const fileUpload = useFileUpload({ + type: "SAMPLE_MANAGEMENT", + allowedExtensions: ["pdf", "jpg", "jpeg", "png"], + allowNameFallback: true, + }); const currentStatus = SAMPLE_TEST_STATUS.find( (i) => i.text === sample.status, ); @@ -104,79 +99,26 @@ const UpdateStatusDialog = (props: Props) => { dispatch({ type: "set_form", form }); }; - const uploadfile = (data: CreateFileResponse) => { - const url = data.signed_url; - const internal_name = data.internal_name; - - const f = file; - if (f === undefined) return; - const newFile = new File([f], `${internal_name}`); - - uploadFile( - url, - newFile, - "PUT", - { - "Content-Type": contentType, - "Content-disposition": "inline", - }, - (xhr: XMLHttpRequest) => { - if (xhr.status >= 200 && xhr.status < 300) { - setUploadStarted(false); - setUploadDone(true); - request(routes.editUpload, { - pathParams: { - id: data.id, - fileType: "SAMPLE_MANAGEMENT", - associatingId: sample.id?.toString() ?? "", - }, - body: { upload_completed: true }, - }); - Notification.Success({ msg: "File Uploaded Successfully" }); + const handleUpload = async () => { + if (fileUpload.files.length > 0) { + if (!fileUpload.fileNames[0]) { + Notification.Error({ + msg: "Please enter a file name before uploading", + }); + return; + } + if (sample.id) { + await fileUpload.handleFileUpload(sample.id); + if (!fileUpload.error) { + return; } else { - setUploadStarted(false); + Notification.Error({ msg: `Upload failed: ${fileUpload.error}` }); } - }, - setUploadPercent, - () => { - setUploadStarted(false); - }, - ); - }; - - const onFileChange = (e: React.ChangeEvent) => { - if (e.target.files == null) { - throw new Error("Error finding e.target.files"); - } - setfile(e.target.files[0]); - const fileName = e.target.files[0].name; - const ext: string = fileName.split(".")[1]; - setcontentType( - HEADER_CONTENT_TYPES[ext as keyof typeof HEADER_CONTENT_TYPES], - ); - return e.target.files[0]; - }; - const handleUpload = async () => { - const f = file; - if (f === undefined) return; - const category = "UNSPECIFIED"; - const name = f.name; - setUploadStarted(true); - setUploadDone(false); - - const { data } = await request(routes.createUpload, { - body: { - original_name: name, - file_type: "SAMPLE_MANAGEMENT", - name: `${sample.patient_name} Sample Report`, - associating_id: sample.id ?? "", - file_category: category, - mime_type: contentType, - }, - }); - - if (data) { - uploadfile(data); + } else { + Notification.Error({ msg: "Sample ID is missing" }); + } + } else { + Notification.Error({ msg: "No file selected for upload" }); } }; @@ -218,32 +160,58 @@ const UpdateStatusDialog = (props: Props) => { onChange={handleChange} /> - Upload Report : + {t("upload_report")}: - {uploadStarted ? ( - - ) : ( -
-