diff --git a/cypress/e2e/patient_spec/PatientInvestigation.cy.ts b/cypress/e2e/patient_spec/PatientInvestigation.cy.ts index 706be899dd8..478ec6907c7 100644 --- a/cypress/e2e/patient_spec/PatientInvestigation.cy.ts +++ b/cypress/e2e/patient_spec/PatientInvestigation.cy.ts @@ -24,12 +24,19 @@ describe("Patient Investigation Creation from Patient consultation page", () => patientPage.visitPatient(patientName); cy.url().should("include", "/patient"); + cy.log("Clicking investigation tab"); patientInvestigation.clickInvestigationTab(); - cy.get("#consultation_tab_nav").should("exist"); + cy.get("#consultation_tab_nav").should("be.visible").should("exist"); + cy.log("Attempting to click log lab results"); + cy.wait(2000); patientInvestigation.clickLogLabResults(); - cy.get("#log-lab-results").should("exist"); + cy.get("#log-lab-results", { timeout: 15000 }) + .should("be.visible") + .should("exist"); + + cy.log("Selecting investigation options"); patientInvestigation.selectInvestigationOption([ "Haematology", "Urine Test", @@ -39,6 +46,7 @@ describe("Patient Investigation Creation from Patient consultation page", () => .contains("Save Investigation") .should("be.visible") .click(); + cy.verifyNotification("Please Enter at least one value"); cy.closeNotification(); }); diff --git a/cypress/pageobject/Patient/PatientInvestigation.ts b/cypress/pageobject/Patient/PatientInvestigation.ts index 1fed12a2388..1fa2e0eef87 100644 --- a/cypress/pageobject/Patient/PatientInvestigation.ts +++ b/cypress/pageobject/Patient/PatientInvestigation.ts @@ -1,33 +1,126 @@ class PatientInvestigation { + private elements = { + addInvestigation: () => cy.get("#investigation"), + investigationTab: () => cy.get("#consultation_tab_nav"), + searchPatientInvestigation: () => cy.get("#search-patient-investigation"), + investigationGroup: () => cy.get("#investigation-group"), + investigationCheckbox: () => cy.get("#investigation-checkbox"), + investigationSelect: () => cy.get("#investigation-select"), + logLabResults: () => cy.get("#log-lab-results"), + investigationFrequency: () => cy.get("#investigation-frequency"), + }; + clickAddInvestigation() { - cy.verifyAndClickElement("#investigation", "Add Investigation"); + cy.log("Clicking Add Investigation"); + this.elements + .addInvestigation() + .should("be.visible") + .contains("Add Investigation") + .click(); + cy.wait(1000); } clickInvestigationTab() { - cy.verifyAndClickElement("#consultation_tab_nav", "Investigations"); + cy.log("Clicking Investigation Tab"); + this.elements + .investigationTab() + .should("be.visible") + .contains("Investigations") + .click(); + cy.wait(2000); } selectInvestigation(investigation: string) { - cy.get("#search-patient-investigation").type(investigation); - cy.verifyAndClickElement("#investigation-group", investigation); - cy.verifyAndClickElement("#investigation", "Investigation No. 1"); + cy.log(`Selecting Investigation: ${investigation}`); + + this.elements + .searchPatientInvestigation() + .should("be.visible") + .clear() + .type(investigation, { delay: 100 }); + + this.elements + .investigationGroup() + .contains(investigation) + .should("be.visible") + .click(); + + this.elements + .addInvestigation() + .contains("Investigation No. 1") + .should("be.visible") + .click(); } clickInvestigationCheckbox() { - cy.get("#investigation-checkbox").click(); + cy.log("Clicking Investigation Checkbox"); + this.elements + .investigationCheckbox() + .should("be.visible") + .should("be.enabled") + .click(); } selectInvestigationOption(options: string[]) { - cy.clickAndMultiSelectOption("#investigation-select", options); + cy.log("Selecting Investigation Options:", options); + + this.elements + .investigationSelect() + .should("exist") + .should("be.visible") + .click(); + + options.forEach((option) => { + cy.get("[role='option']") + .contains(option) + .should("be.visible") + .then(($el) => { + if ($el.length > 0) { + cy.wrap($el).click(); + } else { + throw new Error(`Option "${option}" not found in dropdown`); + } + }); + }); + + cy.get("body").click(0, 0); + cy.wait(500); } clickLogLabResults() { - cy.verifyAndClickElement("#log-lab-results", "Log Lab Results"); + cy.log("Clicking Log Lab Results"); + + this.elements.logLabResults().scrollIntoView().should("be.visible"); + + cy.wait(1000); + + this.elements + .logLabResults() + .contains("Log Lab Results") + .should("be.visible") + .should("be.enabled") + .click(); + + cy.wait(2000); } selectInvestigationFrequency(frequency: string) { - cy.get("#investigation-frequency").click(); + cy.log(`Selecting Investigation Frequency: ${frequency}`); + + this.elements.investigationFrequency().should("be.visible").click(); + cy.contains("button", frequency).should("be.visible").click(); + + cy.wait(500); + } + + verifyElementPresent(selector: string, timeout = 10000) { + return cy.get(selector, { timeout }).should("exist").should("be.visible"); + } + + waitForLoading() { + cy.get("#loading-indicator", { timeout: 10000 }).should("not.exist"); } } + export default PatientInvestigation;