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

New Cypress Test | Create Partial Investigation Log Update #9034

Merged
merged 5 commits into from
Nov 11, 2024

Conversation

nihal467
Copy link
Member

@nihal467 nihal467 commented Nov 6, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced an end-to-end test suite for creating patient investigations.
    • Added methods for multi-selection of investigation options and logging lab results in the patient investigation workflow.
    • Enhanced button accessibility with new identifiers for logging lab results, viewing investigations, and printing investigations.
    • Added a test case for exporting the live patient list based on a specified date range, including validation for notifications and pagination checks.
  • Bug Fixes

    • Streamlined interaction methods by removing unnecessary scrolling actions.
  • Documentation

    • Updated test structure to ensure isolation and independent execution.

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

Walkthrough

The changes introduce an end-to-end test suite for patient investigations using Cypress, encapsulated in the new file PatientInvestigation.cy.ts. This suite includes test scenarios for creating investigations from the patient consultation page. Additionally, modifications to the PatientInvestigation class streamline element interactions by removing unnecessary scrolling and adding methods for logging lab results and selecting investigation options. New id properties are also added to the ButtonV2 components in both the ConsultationInvestigationsTab and ViewInvestigations to enhance accessibility.

Changes

File Path Change Summary
cypress/e2e/patient_spec/PatientInvestigation.cy.ts Introduced a new end-to-end test suite for patient investigations, including test setup and execution.
cypress/pageobject/Patient/PatientInvestigation.ts Removed scrollIntoView() calls from methods; added selectInvestigationOption() and clickLogLabResults() methods.
src/components/Facility/ConsultationDetails/ConsultationInvestigationsTab.tsx Added id property with value "log-lab-results" to ButtonV2 component.
src/components/Facility/Investigations/ViewInvestigations.tsx Added id properties "view-investigation" and "print-investigation" to ButtonV2 components.

Assessment against linked issues

Objective Addressed Explanation
Create cypress test for patient investigation workflow (8768)

Possibly related PRs

Suggested labels

needs testing, needs review

Suggested reviewers

  • rithviknishad

Poem

In the land of tests, we hop and play,
Creating investigations, hip-hip-hooray!
With Cypress we leap, no scrolls in our way,
Logging lab results, brightening the day!
A button now shines, with an ID so neat,
In the world of code, we dance on our feet! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4ce556c and fc3eccd.

📒 Files selected for processing (1)
  • cypress/e2e/patient_spec/PatientHomepage.cy.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • cypress/e2e/patient_spec/PatientHomepage.cy.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Nov 6, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit fc3eccd
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6731c3659e29f90008d76136
😎 Deploy Preview https://deploy-preview-9034--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

cloudflare-workers-and-pages bot commented Nov 6, 2024

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: fc3eccd
Status: ✅  Deploy successful!
Preview URL: https://9d8d18d0.care-fe.pages.dev
Branch Preview URL: https://investigation-test.care-fe.pages.dev

View logs

Copy link

cypress bot commented Nov 6, 2024

CARE    Run #3863

Run Properties:  status check passed Passed #3863  •  git commit fc3eccdd10: New Cypress Test | Create Investigation Log Update
Project CARE
Branch Review investigation-test
Run status status check passed Passed #3863
Run duration 04m 55s
Commit git commit fc3eccdd10: New Cypress Test | Create Investigation Log Update
Committer Mohammed Nihal
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 127
View all changes introduced in this branch ↗︎

@nihal467 nihal467 marked this pull request as ready for review November 11, 2024 05:56
@nihal467 nihal467 requested a review from a team as a code owner November 11, 2024 05:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
cypress/pageobject/Patient/PatientInvestigation.ts (1)

20-22: LGTM! The new method follows page object pattern.

The implementation is clean and consistent with other methods in the class.

Consider adding JSDoc documentation for better maintainability:

+  /**
+   * Clicks the "Log Lab Results" button in the investigation tab
+   */
   clickLogLabResults() {
     cy.verifyAndClickElement("#log-lab-results", "Log Lab Results");
   }
cypress/e2e/patient_spec/PatientInvestigation.cy.ts (1)

1-4: Standardize import paths and add type definitions.

The import statements mix relative (../../pageobject/Login/LoginPage) and absolute paths (pageobject/Patient/PatientCreation). Consider standardizing to absolute paths for better maintainability.

-import { PatientPage } from "pageobject/Patient/PatientCreation";
-import PatientInvestigation from "pageobject/Patient/PatientInvestigation";
-import LoginPage from "../../pageobject/Login/LoginPage";
+import { PatientPage } from "@/pageobject/Patient/PatientCreation";
+import { PatientInvestigation } from "@/pageobject/Patient/PatientInvestigation";
+import { LoginPage } from "@/pageobject/Login/LoginPage";
src/components/Facility/ConsultationDetails/ConsultationInvestigationsTab.tsx (1)

20-20: LGTM! Good addition for test automation.

The addition of the id attribute enhances the component's testability and aligns well with the PR's objective of implementing Cypress tests for the patient investigation workflow.

Consider using a constant for the ID to maintain consistency and prevent typos between the component and test files. Example:

// In a shared constants file
export const TEST_IDS = {
  LOG_LAB_RESULTS_BUTTON: 'log-lab-results'
} as const;

Then use it like:

id={TEST_IDS.LOG_LAB_RESULTS_BUTTON}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c27f595 and a5a3c44.

📒 Files selected for processing (3)
  • cypress/e2e/patient_spec/PatientInvestigation.cy.ts (1 hunks)
  • cypress/pageobject/Patient/PatientInvestigation.ts (1 hunks)
  • src/components/Facility/ConsultationDetails/ConsultationInvestigationsTab.tsx (1 hunks)
🔇 Additional comments (2)
cypress/pageobject/Patient/PatientInvestigation.ts (1)

20-22: Verify test coverage for the new method.

Let's ensure the new method is properly utilized in the test suite.

✅ Verification successful

Test integration verified successfully

The clickLogLabResults() method is properly integrated and used in the test suite:

  • Correctly used in PatientInvestigation.cy.ts as part of an investigation creation test flow
  • No duplicate implementations of the log-lab-results selector found
  • The selector usage is consistent across the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new method is used in the test suite and there are no duplicate implementations

# Test 1: Check if the test file exists and uses clickLogLabResults
echo "Checking for test usage of clickLogLabResults..."
rg -l "clickLogLabResults" "cypress/e2e/patient_spec/PatientInvestigation.cy.ts"

# Test 2: Verify no duplicate implementations of log lab results clicking exist
echo "Checking for potential duplicate implementations..."
rg -g "!PatientInvestigation.ts" "cy\..*log-lab-results"

Length of output: 409


Script:

#!/bin/bash
# Let's check the actual content of the test file to verify proper usage
echo "Checking the test file content..."
rg "clickLogLabResults" -A 5 -B 5 "cypress/e2e/patient_spec/PatientInvestigation.cy.ts"

# Also verify the selector usage in other files to ensure consistency
echo "Checking for any other log-lab-results selector usage..."
rg "#log-lab-results" -A 2 -B 2

Length of output: 1046

cypress/e2e/patient_spec/PatientInvestigation.cy.ts (1)

27-30: Verify custom command implementation.

The test uses custom commands like clickAndMultiSelectOption. Let's verify its implementation for robustness.

✅ Verification successful

Let me gather more information about the custom command implementation since the previous search didn't show the actual implementation.


Custom command implementation looks robust and well-typed

The clickAndMultiSelectOption command is properly implemented with:

  • TypeScript type definitions in cypress/support/index.ts
  • Clear implementation in cypress/support/commands.ts that:
    • Handles both single and array inputs
    • Uses proper Cypress commands for element interaction
    • Follows a clear flow: click → select options → close dropdown
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for custom command definitions
echo "Searching for clickAndMultiSelectOption command definition..."
rg -A 10 "Cypress.Commands.add\('clickAndMultiSelectOption'" cypress/support/

echo "Checking for proper typing of custom commands..."
rg -l "declare global" cypress/support/

Length of output: 392


Script:

#!/bin/bash
# Search with broader pattern to find the command implementation
echo "Searching for clickAndMultiSelectOption implementation..."
rg -A 10 "clickAndMultiSelectOption" cypress/support/

# Also check index.ts since it was found to have global declarations
echo "Checking index.ts content..."
cat cypress/support/index.ts

Length of output: 3352

Comment on lines 23 to 33
it("Create a investigation for a patient and verify its reflection", () => {
patientPage.visitPatient(patientName);
patientInvestigation.clickInvestigationTab();
patientInvestigation.clickLogLabResults();
cy.clickAndMultiSelectOption("#investigations", [
"Haematology",
"Urine Test",
]);
cy.submitButton("Save Investigation");
cy.verifyNotification("Please Enter at least one value");
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Enhance test coverage and add assertions.

The current test only covers the error path. Consider adding:

  1. Positive test scenarios (successful investigation creation)
  2. Assertions for UI state changes
  3. Verification of investigation data persistence

Example additional test:

it("should successfully create and save an investigation", () => {
  patientPage.visitPatient(patientName);
  patientInvestigation.clickInvestigationTab();
  patientInvestigation.clickLogLabResults();
  
  // Select investigations
  cy.clickAndMultiSelectOption("#investigations", ["Haematology"]);
  
  // Fill required values
  cy.get('[data-testid="haemoglobin-input"]').type("14.5");
  
  // Save and verify
  cy.submitButton("Save Investigation");
  cy.verifyNotification("Investigation saved successfully");
  
  // Verify investigation appears in the list
  cy.get('[data-testid="investigations-list"]')
    .should("contain", "Haematology")
    .and("contain", "14.5");
});

Comment on lines +6 to +11
describe("Patient Investigation Creation from Patient consultation page", () => {
const loginPage = new LoginPage();
const patientPage = new PatientPage();
const patientInvestigation = new PatientInvestigation();
const patientName = "Dummy Patient 12";

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 data management and suite description.

The hardcoded patient name ("Dummy Patient 12") should be moved to a test data fixture for better maintainability. Also, consider making the test suite description more specific to the functionality being tested.

+import testData from '../../fixtures/patient.json';
+
-describe("Patient Investigation Creation from Patient consultation page", () => {
+describe("Patient Investigation Workflow - Consultation Page", () => {
   const loginPage = new LoginPage();
   const patientPage = new PatientPage();
   const patientInvestigation = new PatientInvestigation();
-  const patientName = "Dummy Patient 12";
+  const { patientName } = testData;

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +35 to +37
afterEach(() => {
cy.saveLocalStorage();
});
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

Add proper test data cleanup.

The afterEach hook only handles localStorage. Consider adding cleanup steps to ensure complete test isolation:

  1. Delete created investigations
  2. Reset any modified patient data
 afterEach(() => {
   cy.saveLocalStorage();
+  // Clean up created investigations
+  cy.task('dbCleanup', { 
+    collection: 'investigations',
+    filter: { patientName }
+  });
 });

Committable suggestion skipped: line range outside the PR's diff.

@nihal467 nihal467 changed the title New Cypress Test | Create Investigation Log Update New Cypress Test | Create Partial Investigation Log Update Nov 11, 2024
@rithviknishad rithviknishad merged commit 5d95dc6 into develop Nov 11, 2024
58 checks passed
@rithviknishad rithviknishad deleted the investigation-test branch November 11, 2024 09:16
Copy link

@nihal467 Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create cypress test for patient investigation workflow in the consultation page
2 participants