diff --git a/cypress/e2e/assets_spec/AssetHomepage.cy.ts b/cypress/e2e/assets_spec/AssetHomepage.cy.ts index f462bda4327..57c315bb0c4 100644 --- a/cypress/e2e/assets_spec/AssetHomepage.cy.ts +++ b/cypress/e2e/assets_spec/AssetHomepage.cy.ts @@ -99,9 +99,9 @@ describe("Asset Tab", () => { it("Export asset", () => { assetPage.selectassetimportbutton(); cy.wait(2000); - assetPage.selectjsonexportbutton(); + assetPage.selectJsonExportButton(); assetPage.selectassetimportbutton(); - assetPage.selectcsvexportbutton(); + assetPage.selectCsvExportButton(); }); afterEach(() => { diff --git a/cypress/e2e/assets_spec/AssetsCreation.cy.ts b/cypress/e2e/assets_spec/AssetsCreation.cy.ts index 1bcd984a7a3..6d94108b362 100644 --- a/cypress/e2e/assets_spec/AssetsCreation.cy.ts +++ b/cypress/e2e/assets_spec/AssetsCreation.cy.ts @@ -129,7 +129,7 @@ describe("Asset", () => { "d5694af2-21e2-4a39-9bad-2fb98d9818bd", ); assetPage.clickConfigureAsset(); - assetPage.verifyAssetConfiguration(200); + assetPage.verifyAssetConfiguration(); }); it("Add an vital monitor asset and configure it", () => { diff --git a/cypress/e2e/patient_spec/PatientFileUpload.ts b/cypress/e2e/patient_spec/PatientFileUpload.ts index 9d6852d16e7..7e5a3073179 100644 --- a/cypress/e2e/patient_spec/PatientFileUpload.ts +++ b/cypress/e2e/patient_spec/PatientFileUpload.ts @@ -5,7 +5,10 @@ const loginPage = new LoginPage(); const patientPage = new PatientPage(); const patientFileUpload = new PatientFileUpload(); -function runTests(testDescription, visitPatientFileUploadSection) { +function runTests( + testDescription: string, + visitPatientFileUploadSection: () => void, +) { describe(testDescription, () => { const cypressAudioName = "cypress audio"; const cypressFileName = "cypress name"; diff --git a/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts b/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts index 1af1cfc5cb4..98d69ccff41 100644 --- a/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts +++ b/cypress/e2e/sample_test_spec/SampleTestHomepage.cy.ts @@ -13,18 +13,14 @@ describe("Sample List", () => { it("Search by District name", () => { cy.intercept(/\/api\/v1\/test_sample/).as("test_sample"); cy.get("[name='district_name']").type("Test"); - cy.wait("@test_sample").then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); + cy.wait("@test_sample").its("response.statusCode").should("eq", 200); cy.url().should("include", "Test"); }); it("Search by Patient Name", () => { cy.intercept(/\/api\/v1\/test_sample/).as("test_sample"); cy.get("[name='patient_name']").type("Test"); - cy.wait("@test_sample").then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); + cy.wait("@test_sample").its("response.statusCode").should("eq", 200); cy.url().should("include", "Test"); }); diff --git a/cypress/pageobject/Asset/AssetCreation.ts b/cypress/pageobject/Asset/AssetCreation.ts index 41d3c4ca8d0..d6991e82ff0 100644 --- a/cypress/pageobject/Asset/AssetCreation.ts +++ b/cypress/pageobject/Asset/AssetCreation.ts @@ -149,10 +149,8 @@ export class AssetPage { cy.intercept(/\/api\/v1\/asset/).as("asset"); } - verifyAssetConfiguration(statusCode: number) { - cy.wait("@asset").then((interception) => { - expect(interception.response.statusCode).to.equal(statusCode); - }); + verifyAssetConfiguration() { + cy.wait("@asset").its("response.statusCode").should("eq", 200); } clickConfigureAsset() { @@ -222,22 +220,16 @@ export class AssetPage { cy.get("[data-testid=import-asset-button]").click(); } - selectjsonexportbutton() { + selectJsonExportButton() { cy.intercept("GET", "**/api/v1/asset/?**json=true**").as("getJsonexport"); cy.get("#export-json-option").click(); - cy.wait("@getJsonexport").then(({ request, response }) => { - expect(response.statusCode).to.eq(200); - expect(request.url).to.include("json=true"); - }); + cy.wait("@getJsonexport").its("response.statusCode").should("eq", 200); } - selectcsvexportbutton() { + selectCsvExportButton() { cy.intercept("GET", "**/api/v1/asset/?**csv=true**").as("getCsvexport"); cy.get("#export-csv-option").click(); - cy.wait("@getCsvexport").then(({ request, response }) => { - expect(response.statusCode).to.eq(200); - expect(request.url).to.include("csv=true"); - }); + cy.wait("@getCsvexport").its("response.statusCode").should("eq", 200); } selectImportOption() { diff --git a/cypress/pageobject/Asset/AssetFilters.ts b/cypress/pageobject/Asset/AssetFilters.ts index ac83ca97c0b..5a942b22f47 100644 --- a/cypress/pageobject/Asset/AssetFilters.ts +++ b/cypress/pageobject/Asset/AssetFilters.ts @@ -56,16 +56,16 @@ export class AssetFilters { cy.get("#close-slide-over").click(); } // Assertions - assertFacilityText(text) { + assertFacilityText(text: string) { cy.get("[data-testid=Facility]").should("contain", text); } - assertAssetClassText(text) { + assertAssetClassText(text: string) { cy.get("[data-testid='Asset Class']").should("contain", text); } - assertStatusText(text) { + assertStatusText(text: string) { cy.get("[data-testid=Status]").should("contain", text); } - assertLocationText(text) { + assertLocationText(text: string) { cy.get("[data-testid=Location]").should("contain", text); } } diff --git a/cypress/pageobject/Facility/FacilityCreation.ts b/cypress/pageobject/Facility/FacilityCreation.ts index a1676e625dd..26f387935ac 100644 --- a/cypress/pageobject/Facility/FacilityCreation.ts +++ b/cypress/pageobject/Facility/FacilityCreation.ts @@ -9,7 +9,7 @@ class FacilityPage { .should("eq", 200); } - typeFacilitySearch(facilityName) { + typeFacilitySearch(facilityName: string) { cy.get("#search").click().clear(); cy.get("#search").click().type(facilityName); } @@ -21,7 +21,7 @@ class FacilityPage { cy.get("#manage-facility-dropdown button").should("be.visible"); } - clickUpdateFacilityType(facilityType) { + clickUpdateFacilityType(facilityType: string) { cy.get("#facility_type") .click() .then(() => { @@ -225,11 +225,11 @@ class FacilityPage { } fillTriageEntryFields( - visited, - homeQuarantine, - isolation, - referred, - confirmedPositive, + visited: string, + homeQuarantine: string, + isolation: string, + referred: string, + confirmedPositive: string, ) { cy.get("#num_patients_visited").clear().click().type(visited); cy.get("#num_patients_home_quarantine") @@ -244,7 +244,7 @@ class FacilityPage { .type(confirmedPositive); } - fillEntryDate(date) { + fillEntryDate(date: string) { cy.get("#entry_date").click(); cy.get("#date-input").click().type(date); } @@ -253,13 +253,13 @@ class FacilityPage { cy.get("#edit-button").click(); } - clickButtonsMultipleTimes(selector) { + clickButtonsMultipleTimes(selector: string) { cy.get(selector).each(($button) => { cy.wrap($button).click(); }); } - verifyTriageTableContains(value) { + verifyTriageTableContains(value: string) { cy.get("#triage-table").contains(value); } @@ -430,7 +430,7 @@ class FacilityPage { return cy.get("#district"); } - selectStateOnPincode(stateName) { + selectStateOnPincode(stateName: string) { this.getStateElement() .scrollIntoView() .wait(2000) @@ -444,7 +444,7 @@ class FacilityPage { }); } - selectDistrictOnPincode(districtName) { + selectDistrictOnPincode(districtName: string) { this.getDistrictElement() .scrollIntoView() .wait(2000) diff --git a/cypress/pageobject/Facility/FacilityHome.ts b/cypress/pageobject/Facility/FacilityHome.ts index 956c374ada4..e021171ff0a 100644 --- a/cypress/pageobject/Facility/FacilityHome.ts +++ b/cypress/pageobject/Facility/FacilityHome.ts @@ -53,7 +53,7 @@ class FacilityHome { cy.get("#facility-detailspage-cns").click(); } - selectLocation(location) { + selectLocation(location: string) { cy.get("#location").click().type(location); cy.get("li[role=option]").contains(location).click(); } @@ -99,7 +99,7 @@ class FacilityHome { return cy.url(); } - verifyURLContains(searchText) { + verifyURLContains(searchText: string) { const encodedText = encodeURIComponent(searchText).replace(/%20/g, "+"); this.getURL().should("include", `search=${encodedText}`); } diff --git a/cypress/pageobject/Facility/FacilityManage.ts b/cypress/pageobject/Facility/FacilityManage.ts index 9e41d5d0290..52a432abe59 100644 --- a/cypress/pageobject/Facility/FacilityManage.ts +++ b/cypress/pageobject/Facility/FacilityManage.ts @@ -7,17 +7,17 @@ class FacilityManage { cy.get("#upload-cover-image").should("be.visible"); } - uploadCoverImage(fileName) { + uploadCoverImage(fileName: string) { cy.get("#upload-cover-image") .selectFile(`cypress/fixtures/${fileName}`, { force: true }) .wait(100); // Adjust the wait time as needed } - verifyTotalDoctorCapacity(expectedCapacity) { + verifyTotalDoctorCapacity(expectedCapacity: string) { cy.get("#facility-doctor-totalcapacity").contains(expectedCapacity); } - verifyFacilityBedCapacity(expectedCapacity) { + verifyFacilityBedCapacity(expectedCapacity: string) { cy.get("#facility-bed-capacity-details").contains(expectedCapacity); } @@ -51,15 +51,15 @@ class FacilityManage { cy.get("#middleware_address").should("be.visible"); } - clickButtonWithText(text) { + clickButtonWithText(text: string) { cy.get("button#submit").contains(text).click(); } - checkErrorMessageVisibility(text) { + checkErrorMessageVisibility(text: string) { cy.get(".error-text").contains(text).should("be.visible"); } - typeMiddlewareAddress(address) { + typeMiddlewareAddress(address: string) { cy.get("#middleware_address").click().clear().click().type(address); } @@ -67,11 +67,14 @@ class FacilityManage { cy.get("#hf_id").click().clear(); } - typeHfrId(address) { + typeHfrId(address: string) { cy.get("#hf_id").click().clear().click().type(address); } - verifySuccessMessageVisibilityAndContent(text, isRegex = false) { + verifySuccessMessageVisibilityAndContent( + text: string | RegExp, + isRegex = false, + ) { if (isRegex) { cy.get(".pnotify-text").should("be.visible").contains(text); } else { @@ -79,11 +82,11 @@ class FacilityManage { } } - verifyMiddlewareAddressValue(expectedValue) { + verifyMiddlewareAddressValue(expectedValue: string) { cy.get("#middleware_address").should("have.value", expectedValue); } - verifyHfrIdValue(expectedValue) { + verifyHfrIdValue(expectedValue: string) { cy.get("#hf_id").should("have.value", expectedValue); } diff --git a/cypress/pageobject/Patient/PatientConsultation.ts b/cypress/pageobject/Patient/PatientConsultation.ts index cc5b8e19465..21da5243500 100644 --- a/cypress/pageobject/Patient/PatientConsultation.ts +++ b/cypress/pageobject/Patient/PatientConsultation.ts @@ -6,9 +6,10 @@ export class PatientConsultationPage { cy.clickAndSelectOption("#route_to_facility", status); } - typeAndMultiSelectSymptoms(input, symptoms) { + typeAndMultiSelectSymptoms(input: string, symptoms: string[]) { cy.typeAndMultiSelectOption("#additional_symptoms", input, symptoms); } + selectSymptomsDate(date: string) { cy.clickAndTypeDate("#symptoms_onset_date", date); } @@ -48,7 +49,7 @@ export class PatientConsultationPage { cy.get("#death_confirmed_doctor").click().type(doctor); } - selectPatientDiagnosis(icdCode, statusId) { + selectPatientDiagnosis(icdCode: string, statusId: string) { cy.searchAndSelectOption("#icd11-search", icdCode); cy.get("#diagnosis-list") .contains("Add as") @@ -92,7 +93,7 @@ export class PatientConsultationPage { cy.clickAndSelectOption("#principal-diagnosis-select", diagnosis); } - verifyTextInConsultation(selector, text) { + verifyTextInConsultation(selector: string, text: string) { cy.get(selector).scrollIntoView(); cy.get(selector).contains(text).should("be.visible"); } diff --git a/cypress/pageobject/Patient/PatientCreation.ts b/cypress/pageobject/Patient/PatientCreation.ts index e037f0888f0..0ec505a47a0 100644 --- a/cypress/pageobject/Patient/PatientCreation.ts +++ b/cypress/pageobject/Patient/PatientCreation.ts @@ -10,7 +10,7 @@ export class PatientPage { cy.wait("@getFacilities").its("response.statusCode").should("eq", 200); } - visitPatient(patientName) { + visitPatient(patientName: string) { cy.get("#name").click().type(patientName); cy.intercept("GET", "**/api/v1/consultation/**").as("getPatient"); cy.get("#patient-name-list").contains(patientName).click(); @@ -165,16 +165,16 @@ export class PatientPage { } verifyPatientDashboardDetails( - gender, - age, - patientName, - phoneNumber, - emergencyPhoneNumber, - yearOfBirth, - bloodGroup, - occupation, - socioeconomicStatus = null, - domesticHealthcareSupport = null, + gender: string, + age: number, + patientName: string, + phoneNumber: string, + emergencyPhoneNumber: string, + yearOfBirth: string, + bloodGroup: string, + occupation: string, + socioeconomicStatus: string | null = null, + domesticHealthcareSupport: string | null = null, isAntenatal = false, isPostPartum = false, ) { @@ -202,12 +202,12 @@ export class PatientPage { } verifyPatientLocationDetails( - patientAddress, - patientPincode, - patientState, - patientDistrict, - patientLocalbody, - patientWard, + patientAddress: string, + patientPincode: number, + patientState: string, + patientDistrict: string, + patientLocalbody: string, + patientWard: string, ) { cy.get("[data-testid=patient-details]").then(($dashboard) => { cy.url().should("include", "/facility/"); diff --git a/cypress/pageobject/Patient/PatientHome.ts b/cypress/pageobject/Patient/PatientHome.ts index d2f4efdc877..4f953adf78b 100644 --- a/cypress/pageobject/Patient/PatientHome.ts +++ b/cypress/pageobject/Patient/PatientHome.ts @@ -27,11 +27,7 @@ class PatientHome { } verifyPatientExportRequest() { - cy.wait("@getPatients").then((interception) => { - expect(interception.request.url).to.include("/api/v1/patient/"); - expect(interception.request.url).to.include("&csv"); - expect(interception.response.statusCode).to.eq(200); - }); + cy.wait("@getPatients").its("response.statusCode").should("eq", 200); } typePatientModifiedBeforeDate(startDate: string) { diff --git a/cypress/pageobject/Patient/PatientInsurance.ts b/cypress/pageobject/Patient/PatientInsurance.ts index bdd571e9d0c..1b91d27b629 100644 --- a/cypress/pageobject/Patient/PatientInsurance.ts +++ b/cypress/pageobject/Patient/PatientInsurance.ts @@ -47,11 +47,11 @@ class PatientInsurance { } verifyPatientPolicyDetails( - subscriberId, - policyId, - insurerId, - insurerName, - isHcxEnabled, + subscriberId: string, + policyId: string, + insurerId: string, + insurerName: string, + isHcxEnabled: string, ) { cy.get("[data-testid=patient-details]").then(($dashboard) => { cy.url().should("include", "/facility/"); diff --git a/cypress/pageobject/Patient/PatientLogupdate.ts b/cypress/pageobject/Patient/PatientLogupdate.ts index add3fbb0590..b2822d03353 100644 --- a/cypress/pageobject/Patient/PatientLogupdate.ts +++ b/cypress/pageobject/Patient/PatientLogupdate.ts @@ -32,7 +32,7 @@ class PatientLogupdate { cy.get("#other_details").click().type(details); } - typeAndMultiSelectSymptoms(input, symptoms) { + typeAndMultiSelectSymptoms(input: string, symptoms: string[]) { cy.typeAndMultiSelectOption("#additional_symptoms", input, symptoms); } selectSymptomsDate(date: string) { @@ -74,14 +74,14 @@ class PatientLogupdate { cy.get("#rhythm_detail").click().type(rhythm); } - clickLogUpdateViewDetails(element, patientCategory) { + clickLogUpdateViewDetails(element: string, patientCategory: string) { cy.get(element).scrollIntoView(); cy.verifyContentPresence(element, [patientCategory]); cy.get(element).first().contains("View Details").click(); cy.wait(3000); } - clickLogUpdateUpdateLog(element, patientCategory) { + clickLogUpdateUpdateLog(element: string, patientCategory: string) { cy.get(element).scrollIntoView(); cy.verifyContentPresence(element, [patientCategory]); cy.get(element).first().contains("Update Log").click(); @@ -93,7 +93,7 @@ class PatientLogupdate { cy.wait(3000); } - clickClearButtonInElement(elementId) { + clickClearButtonInElement(elementId: string) { cy.get(elementId).find("#clear-button").click(); } diff --git a/cypress/pageobject/Patient/PatientMedicalHistory.ts b/cypress/pageobject/Patient/PatientMedicalHistory.ts index a0dbdd0131a..93fdd1b38b3 100644 --- a/cypress/pageobject/Patient/PatientMedicalHistory.ts +++ b/cypress/pageobject/Patient/PatientMedicalHistory.ts @@ -11,7 +11,7 @@ class PatientMedicalHistory { cy.get("#allergies").click().type(allergies); } - typeMedicalHistory(index, text) { + typeMedicalHistory(index: number, text: string) { cy.get(`#medical_history_check_${index}`).click(); cy.get(`#medical_history_${index}`).click().type(text); } @@ -22,16 +22,16 @@ class PatientMedicalHistory { } verifyPatientMedicalDetails( - patientPresentHealth, - patientOngoingMedication, - patientAllergies, - patientSymptoms1, - patientSymptoms2, - patientSymptoms3, - patientSymptoms4, - patientSymptoms5, - patientSymptoms6, - patientSymptoms7, + patientPresentHealth: string, + patientOngoingMedication: string, + patientAllergies: string, + patientSymptoms1: string, + patientSymptoms2: string, + patientSymptoms3: string, + patientSymptoms4: string, + patientSymptoms5: string, + patientSymptoms6: string, + patientSymptoms7: string, ) { cy.get("[data-testid=patient-details]").then(($dashboard) => { cy.url().should("include", "/facility/"); diff --git a/cypress/pageobject/Resource/ResourcePage.ts b/cypress/pageobject/Resource/ResourcePage.ts index e4078fcb317..730d3dd9148 100644 --- a/cypress/pageobject/Resource/ResourcePage.ts +++ b/cypress/pageobject/Resource/ResourcePage.ts @@ -4,9 +4,9 @@ class ResourcePage { cy.get("svg.care-svg-icon__baseline.care-l-export").each(($button) => { cy.intercept(/\/api\/v1\/resource/).as("resource_download"); cy.wrap($button).click({ force: true }); - cy.wait("@resource_download").then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); + cy.wait("@resource_download") + .its("response.statusCode") + .should("eq", 200); }); } @@ -19,9 +19,7 @@ class ResourcePage { } verifyCompletedResources() { - cy.wait("@resource").then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); + cy.wait("@resource").its("response.statusCode").should("eq", 200); cy.contains("button", "Active").should("have.class", "text-primary-500"); cy.contains("button", "Completed").should("have.class", "text-white"); } @@ -31,9 +29,7 @@ class ResourcePage { } verifyActiveResources() { - cy.wait("@resource").then((interception) => { - expect(interception.response.statusCode).to.equal(200); - }); + cy.wait("@resource").its("response.statusCode").should("eq", 200); cy.contains("button", "Active").should("have.class", "text-white"); cy.contains("button", "Completed").should("have.class", "text-primary-500"); } diff --git a/cypress/pageobject/Users/ManageUserPage.ts b/cypress/pageobject/Users/ManageUserPage.ts index f3e0deca53b..a9ac1374085 100644 --- a/cypress/pageobject/Users/ManageUserPage.ts +++ b/cypress/pageobject/Users/ManageUserPage.ts @@ -1,5 +1,5 @@ export class ManageUserPage { - assertHomeFacility(expectedText) { + assertHomeFacility(expectedText: string) { cy.get("#home_facility").should("contain.text", expectedText); } @@ -7,11 +7,11 @@ export class ManageUserPage { cy.get("#facilities").click(); } - selectFacilityFromDropdown(facilityName) { + selectFacilityFromDropdown(facilityName: string) { cy.searchAndSelectOption("input[name='facility']", facilityName); } - selectSkillFromDropdown(skill) { + selectSkillFromDropdown(skill: string) { cy.searchAndSelectOption("input[name='skill']", skill); } @@ -19,11 +19,11 @@ export class ManageUserPage { cy.get("#link-facility").click(); } - assertLinkedFacility(facilityName) { + assertLinkedFacility(facilityName: string) { cy.get("#linked-facility-list").should("contain.text", facilityName); } - assertnotLinkedFacility(facilityName) { + assertnotLinkedFacility(facilityName: string) { cy.get("#linked-facility-list").should("not.contain", facilityName); } @@ -31,11 +31,11 @@ export class ManageUserPage { cy.get("#linked-facility-list").should("not.exist"); } - assertHomeFacilitylink(facilityName) { + assertHomeFacilitylink(facilityName: string) { cy.get("#home-facility").should("contain.text", facilityName); } - assertFacilityNotInDropdown(facilityName) { + assertFacilityNotInDropdown(facilityName: string) { cy.get("input[name='facility']").click().type(facilityName); cy.get("[role='option']").should("not.exist"); } @@ -93,12 +93,12 @@ export class ManageUserPage { cy.visit("/facility"); } - typeFacilitySearch(facilityName) { + typeFacilitySearch(facilityName: string) { cy.get("#search").click().clear(); cy.get("#search").click().type(facilityName); } - assertFacilityInCard(facilityName) { + assertFacilityInCard(facilityName: string) { cy.get("#facility-name-card").should("contain", facilityName); } @@ -117,13 +117,13 @@ export class ManageUserPage { cy.wait("@getSkills").its("response.statusCode").should("eq", 200); } - assertSkillInAlreadyLinkedSkills(skillName) { + assertSkillInAlreadyLinkedSkills(skillName: string) { cy.get("#already-linked-skills") .contains(skillName) .should("have.length", 1); } - assertSkillIndoctorconnect(skillName) { + assertSkillIndoctorconnect(skillName: string) { cy.get("#doctor-connect-home-doctor") .contains(skillName) .should("have.length", 1); @@ -137,11 +137,11 @@ export class ManageUserPage { cy.get("#unlink-skill").click(); } - assertSkillInAddedUserSkills(skillName) { + assertSkillInAddedUserSkills(skillName: string) { cy.get("#added-user-skills").should("contain", skillName); } - assertDoctorConnectVisibility(realName) { + assertDoctorConnectVisibility(realName: string) { cy.get('*[id="doctor-connect-home-doctor"]').should( "contain.text", realName, diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 86d048e5f41..320f19d8b0e 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -38,8 +38,8 @@ Cypress.Commands.add("refreshApiLogin", (username, password) => { Cypress.Commands.add("loginByApi", (username, password) => { cy.log(`Logging in the user: ${username}:${password}`); cy.task("readFileMaybe", "cypress/fixtures/token.json").then( - (tkn: string) => { - const token = JSON.parse(tkn); + (tkn: unknown) => { + const token = JSON.parse(tkn as string); // Cast tkn to string if (tkn && token.access && token.username === username) { cy.request({ method: "POST", @@ -66,21 +66,6 @@ Cypress.Commands.add("loginByApi", (username, password) => { ); }); -Cypress.Commands.add( - "awaitUrl", - (url: string, disableLoginVerification = false) => { - cy.intercept(/getcurrentuser/).as("currentuser"); - cy.visit(url); - disableLoginVerification - ? cy.wait("@currentuser") - : cy.wait("@currentuser").its("response.statusCode").should("eq", 200); - }, -); - -Cypress.Commands.add("verifyNotification", (text) => { - return cy.get(".pnotify-container").should("exist").contains(text); -}); - Cypress.on("uncaught:exception", () => { // returning false here prevents Cypress from // failing the test @@ -94,19 +79,44 @@ Cypress.on("uncaught:exception", () => { * Waits until the selector finds an attached element, then yields it (wrapped). * selectorFn, if provided, is passed $(document). Don't use cy methods inside selectorFn. */ -Cypress.Commands.add("getAttached", (selector) => { +Cypress.Commands.add("getAttached", (selector: string) => { const getElement = - typeof selector === "function" ? selector : ($d) => $d.find(selector); - let $el = null; + typeof selector === "function" + ? selector + : ($d: JQuery) => + $d.find(selector) as unknown as JQuery; + + let $el: JQuery | null = null; + return cy .document() - .should(($d) => { + .should(($d: Document) => { $el = getElement(Cypress.$($d)); - expect(Cypress.dom.isDetached($el)).to.be.false; + // Ensure $el is an HTMLElement before checking if it is detached + if ($el.length && $el[0] instanceof HTMLElement) { + expect(Cypress.dom.isDetached($el[0])).to.be.false; // Access the first HTMLElement + } else { + throw new Error("Element is not an HTMLElement or is detached."); + } }) .then(() => cy.wrap($el)); }); +Cypress.Commands.add( + "awaitUrl", + (url: string, disableLoginVerification = false) => { + cy.intercept(/getcurrentuser/).as("currentuser"); + cy.visit(url); + disableLoginVerification + ? cy.wait("@currentuser") + : cy.wait("@currentuser").its("response.statusCode").should("eq", 200); + }, +); + +Cypress.Commands.add("verifyNotification", (text) => { + return cy.get(".pnotify-container").should("exist").contains(text); +}); + Cypress.Commands.add("clearAllFilters", () => { return cy.get("#clear-all-filters").click(); }); diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index 9c019786170..0fd7f9e340b 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { - "baseUrl": "../node_modules", + "baseUrl": "./", "target": "es5", "lib": ["es5", "dom", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020"], "types": ["cypress"], "typeRoots": ["./support"], "resolveJsonModule": true }, - "include": ["**/*.ts", "support/commands.js"], -} + "include": ["**/*.cy.ts", "support/commands.ts","**/*.ts"], +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 59a22853fd5..6d2da7a4750 100644 --- a/package-lock.json +++ b/package-lock.json @@ -76,10 +76,11 @@ "@types/react-csv": "^1.1.10", "@types/react-dom": "^18.3.0", "@types/react-google-recaptcha": "^2.1.9", + "@types/uuid": "^10.0.0", "@typescript-eslint/eslint-plugin": "^7.18.0", "@vitejs/plugin-react-swc": "^3.6.0", "autoprefixer": "^10.4.19", - "cypress": "^13.14.2", + "cypress": "^13.15.0", "cypress-localstorage-commands": "^2.2.5", "cypress-split": "^1.23.2", "eslint-config-prettier": "^9.1.0", @@ -4709,6 +4710,12 @@ "resolved": "https://registry.npmjs.org/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz", "integrity": "sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA==" }, + "node_modules/@types/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==", + "dev": true + }, "node_modules/@types/yauzl": { "version": "2.10.3", "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz", diff --git a/package.json b/package.json index 68de432e82e..eb1c851bc0d 100644 --- a/package.json +++ b/package.json @@ -111,10 +111,11 @@ "@types/react-csv": "^1.1.10", "@types/react-dom": "^18.3.0", "@types/react-google-recaptcha": "^2.1.9", + "@types/uuid": "^10.0.0", "@typescript-eslint/eslint-plugin": "^7.18.0", "@vitejs/plugin-react-swc": "^3.6.0", "autoprefixer": "^10.4.19", - "cypress": "^13.14.2", + "cypress": "^13.15.0", "cypress-localstorage-commands": "^2.2.5", "cypress-split": "^1.23.2", "eslint-config-prettier": "^9.1.0",