Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrin2005 committed Dec 28, 2024
1 parent ce00cdf commit a2d1d38
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 11 deletions.
12 changes: 10 additions & 2 deletions cypress/e2e/patient_spec/PatientInvestigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
});
Expand Down
111 changes: 102 additions & 9 deletions cypress/pageobject/Patient/PatientInvestigation.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit a2d1d38

Please sign in to comment.