Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added encounter-notes cypress test #10538

Closed
78 changes: 78 additions & 0 deletions cypress/e2e/patient_spec/encouter-notes.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { FacilityCreation } from "@/pageObject/facility/FacilityCreation";
import { PatientEncounter } from "@/pageObject/Patients/PatientEncounter";

const facilityCreation = new FacilityCreation();
const patientEncounter = new PatientEncounter();

describe("Encounter Notes - Threads, Messages, and Notes", () => {
beforeEach(() => {
cy.loginByApi("devdoctor"); // logging in as doctor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.loginByApi("devdoctor"); // logging in as doctor
cy.loginByApi("devdoctor"); // logging in as doctor
  • since we are connected to develop backend temporarily, create a new user manually in the develop, add it to the fixture file and use that in your test

cy.visit("/");
facilityCreation.selectFacility("GHC Trikaripur");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
facilityCreation.selectFacility("GHC Trikaripur");
facilityCreation.selectFacility("GHC Payyanur");

use the facility GHC Payyanur

});

it("create multiple threads and add messages", () => {
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.openNotesTab()


// first Thread
cy.contains("button", "New Thread").click();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.contains("button", "New Thread").click();
cy.contains("button", "New Thread").click();

as the per given guidelines, use the command function, cy.verifyandclickelement() to click on any button with text. Make sure you uses a proper data-cy test id's or element id ,

cy.get("input[placeholder='Enter discussion title...']").type("Test Discussion final");
cy.contains("button", "Create").click();
cy.get("form").within(() => {
cy.get("textarea").type("This is a test message fianl!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cy.get("textarea").type("This is a test message fianl!");
cy.get("textarea").type("This is a test message fianl!");

use combination of single line message as well as multi line text as well

cy.get('button[type="submit"]').click();
});



// second thread
cy.contains("button", "New Thread").click();
cy.get("input[placeholder='Enter discussion title...']").type("Test Discussion 100");
cy.contains("button", "Create").click();
cy.get("form").within(() => {
cy.get("textarea").type("This is a test message 100!");
cy.get('button[type="submit"]').click();
});

cy.intercept("POST", "https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Separate test cases for different user roles.

The test case mixes doctor and nurse actions, which violates the single responsibility principle for tests. Consider splitting this into two separate test cases for better maintainability and clarity.

-  cy.intercept("POST", "https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");
-
-    
-
-    // logging as nurse
-    cy.loginByApi("devnurse");
-    cy.visit("/");
-    facilityCreation.selectFacility("GHC Trikaripur");
-    patientEncounter.navigateToEncounters().openFirstEncounterDetails().openNotesTab();
+  });
+
+  it("create multiple threads and add messages as nurse", () => {
+    cy.loginByApi("devnurse");
+    cy.visit("/");
+    facilityCreation.selectFacility("GHC Trikaripur");
+    patientEncounter
+      .navigateToEncounters()
+      .openFirstEncounterDetails()
+      .openNotesTab();

Also applies to: 45-49

🧰 Tools
🪛 ESLint

[error] 41-42: Replace ··cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as("logoutRequest");⏎ with cy.intercept("POST",·"https://careapi.ohc.network/api/v1/auth/logout/").as(⏎······"logoutRequest",

(prettier/prettier)




// logging as nurse
cy.loginByApi("devnurse");
cy.visit("/");
facilityCreation.selectFacility("GHC Trikaripur");
patientEncounter.navigateToEncounters().openFirstEncounterDetails().openNotesTab();
});

it("create a new note in the Notes tab", () => {
patientEncounter
.navigateToEncounters()
.openFirstEncounterDetails()
.openNotesTab()

// first thread in nurse login
cy.contains("button", "New Thread").click();
cy.get("input[placeholder='Enter discussion title...']").type("Test Discussion 200");
cy.contains("button", "Create").click();
cy.get("form").within(() => {
cy.get("textarea").type("This is a test message 200!");
cy.get('button[type="submit"]').click();
});



// second thread in nurse login
cy.contains("button", "New Thread").click();
cy.get("input[placeholder='Enter discussion title...']").type("Test Discussion 300");
cy.contains("button", "Create").click();
cy.get("form").within(() => {
cy.get("textarea").type("This is a test message 300!");
cy.get('button[type="submit"]').click();
});
});
});
22 changes: 22 additions & 0 deletions cypress/pageObject/Patients/PatientEncounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ export class PatientEncounter {
return this;
}

openSettingsTab() {
cy.get('[data-sidebar="content"]').contains("Settings").click();
return this;
}

openNotesTab() {
cy.get('#encounter_tab_nav').contains("Notes").click();
return this;
}
Comment on lines +34 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Fix formatting issues.

The method logic is correct, but there are some formatting issues to address.

Apply this diff to fix the formatting:

- openNotesTab() {
-    cy.get('#encounter_tab_nav').contains("Notes").click();
+ openNotesTab() {
+    cy.get("#encounter_tab_nav").contains("Notes").click();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
openNotesTab() {
cy.get('#encounter_tab_nav').contains("Notes").click();
return this;
}
openNotesTab() {
cy.get("#encounter_tab_nav").contains("Notes").click();
return this;
}
🧰 Tools
🪛 ESLint

[error] 35-35: Insert ·

(prettier/prettier)


[error] 36-36: Replace '#encounter_tab_nav' with "#encounter_tab_nav"

(prettier/prettier)


addMessageToThread(message: string) {
cy.get('textarea[placeholder="Type your message"]').type(message);
// Click the submit button
cy.get('button[type="submit"]').click();
}
Comment on lines +39 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve test maintainability and method chaining.

The method has several areas for improvement:

  1. Use data-cy attributes for more reliable selectors
  2. Return this to support method chaining

Apply this diff to improve the method:

  addMessageToThread(message: string) {
-    cy.get('textarea[placeholder="Type your message"]').type(message);
-    // Click the submit button
-    cy.get('button[type="submit"]').click();
+    cy.get('[data-cy="message-input"]').type(message);
+    cy.get('[data-cy="submit-message"]').click();
+    return this;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
addMessageToThread(message: string) {
cy.get('textarea[placeholder="Type your message"]').type(message);
// Click the submit button
cy.get('button[type="submit"]').click();
}
addMessageToThread(message: string) {
cy.get('[data-cy="message-input"]').type(message);
cy.get('[data-cy="submit-message"]').click();
return this;
}


startNewConversation() {
cy.contains("button", "Start New Discussion").should("be.visible").click();
return this;
}


// Questionnaire actions
addQuestionnaire(questionnaireName: string) {
cy.get('[data-cy="add-questionnaire-button"]').click();
Expand Down