cypress/pageObject/Patients/PatientEncounter.ts
export class PatientEncounter { // Navigation navigateToEncounters() { cy.get('[data-sidebar="content"]').contains("Encounters").click(); return this; } openFirstEncounterDetails() { cy.get('[data-cy="encounter-list-cards"]') .first() .contains("View Details") .click(); return this; } Similar blocks of code found in 2 locations. Consider refactoring. searchEncounter(patientName: string) { cy.get('[data-cy="search-encounter"]').click(); cy.typeIntoField("#encounter-search", patientName); cy.get('[data-cy="search-encounter"]').click(); return this; } clickUpdateEncounter() { cy.verifyAndClickElement( '[data-cy="update-encounter-option"]', "Update Encounter", ); return this; } verifyEncounterPatientInfo(contents: string[]) { cy.verifyContentPresence("#patient-infobadges", contents); return this; } // Questionnaire actions addQuestionnaire(questionnaireName: string) { cy.typeAndSelectOption( '[data-cy="add-questionnaire-button"]', questionnaireName, false, ); return this; } fillQuestionnaire(answers: Record<string, string>) { Object.entries(answers).forEach(([field, value]) => { // Handle both text inputs and select dropdowns cy.get(`[data-cy="question-${field}"]`).then(($el) => { if ($el.is("select")) { cy.wrap($el).select(value); } else { // Find the actual input element within the container cy.wrap($el).find("input, textarea").click().type(value); } }); }); return this; } verifyOverviewValues(expectedValues: string[]) { cy.verifyContentPresence('[data-cy="encounter-overview"]', expectedValues); return this; } clickPatientDetailsButton() { cy.get('[data-cy="patient-details-button"]') .filter(":visible") .first() .click(); return this; } clickPatientEditButton() { cy.verifyAndClickElement('[data-cy="edit-patient-button"]', "Edit"); return this; } clickEncounterMarkAsComplete() { cy.verifyAndClickElement( '[data-cy="mark-encounter-complete"]', "Mark as Complete", ); return this; } clickConfirmEncounterAsComplete() { cy.intercept("GET", "**/api/v1/encounter/**").as("getEncounter"); cy.verifyAndClickElement( '[data-cy="confirm-encounter-complete"]', "Mark as Complete", ); cy.wait("@getEncounter").then((interception) => { expect(interception.response?.statusCode).to.eq(200); // Verify status code expect(interception.response?.body).to.have.property( "status", "completed", ); }); return this; } assertEncounterCompleteSuccess() { cy.verifyNotification("Encounter Complete"); return this; } clickInProgressEncounterFilter() { cy.intercept("GET", "**/api/v1/encounter/**").as("getEncounters"); cy.verifyAndClickElement('[data-cy="in-progress-filter"]', "In Progress"); cy.wait("@getEncounters", { timeout: 10000 }).then((interception) => { expect(interception.request.url).to.include("status=in_progress"); expect(interception.response.statusCode).to.eq(200); }); return this; }}