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

Add Cypress Test Suite for Sample Test Request Workflow #8977

Merged

Conversation

JavidSumra
Copy link
Contributor

@JavidSumra JavidSumra commented Nov 1, 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

Release Notes

  • New Features

    • Introduced a new test suite for automated testing of the sample test functionality.
    • Added a button in the mobile view for requesting a sample test, improving user interaction.
  • Improvements

    • Enhanced accessibility with new id attributes for various form fields and components across the patient management interface.
    • Improved rendering logic for patient details and sample test information.
    • Enhanced functionality for handling patient details within the consultation process.
    • Streamlined button interactions by standardizing submission methods across various components.
    • Added a new command for clicking cancel buttons, improving user interaction.
    • Updated test cases to ensure accurate interactions with the user interface.
  • Bug Fixes

    • Improved error handling in patient transfer and volunteer assignment processes.

These updates enhance user experience and ensure robust functionality within the sample test management system.

@JavidSumra JavidSumra requested a review from a team as a code owner November 1, 2024 09:52
Copy link

netlify bot commented Nov 1, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit b220acd
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/673b76ef10573500083db16c
😎 Deploy Preview https://deploy-preview-8977--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
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

This pull request introduces a new Cypress test specification for requesting a sample test, encapsulated in SampleTestRequest.cy.ts. It implements a structured test suite that verifies the functionality of the sample request process. Additionally, various components related to patient management have been updated to enhance accessibility and user interaction, including new id attributes for form fields and buttons, improved error handling, and the addition of a sample request button in the PatientHome component.

Changes

File Path Change Summary
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts New test suite and test case for requesting a sample test, including setup and verification steps.
cypress/pageobject/Sample/SampleTestCreate.ts Introduction of SampleTestPage class with methods for interacting with the sample request page.
src/components/Patient/PatientHome.tsx Added a button for requesting a sample test and improved error handling in patient transfer and volunteer assignment functions.
src/components/Patient/SampleTest.tsx Added id attributes to form fields and buttons for accessibility.
src/components/Patient/SampleTestCard.tsx Introduced id attributes to various div elements for improved accessibility.
src/components/Patient/SampleViewAdmin.tsx Added id attributes to elements for patient name and search input for better accessibility.
src/components/Patient/SampleDetails.tsx Added id attributes to patient-related information spans for enhanced accessibility.
cypress/pageobject/Patient/PatientConsultation.ts Added methods for intercepting and verifying patient details API responses.
cypress/e2e/facility_spec/FacilityHomepage.cy.ts Renamed method calls from cy.submitButton to cy.clickSubmitButton for consistency.
cypress/e2e/facility_spec/FacilityLocation.cy.ts Updated method calls from cy.submitButton to cy.clickSubmitButton in location management tests.
cypress/e2e/hcx_spec/HcxClaims.cy.ts Changed method calls from cy.submitButton to cy.clickSubmitButton in HCX claims tests.
cypress/e2e/patient_spec/PatientConsultationCreation.cy.ts Replaced instances of cy.submitButton with cy.clickSubmitButton in patient consultation tests.
cypress/e2e/patient_spec/PatientConsultationDischarge.cy.ts Updated method calls from cy.submitButton to cy.clickSubmitButton in discharge tests.
cypress/e2e/patient_spec/PatientInvestigation.cy.ts Changed method call from cy.submitButton to cy.clickSubmitButton for investigations.
cypress/e2e/patient_spec/PatientLogUpdate.cy.ts Replaced cy.submitButton with cy.clickSubmitButton in log update tests.
cypress/e2e/patient_spec/PatientPrescription.cy.ts Updated method calls from cy.submitButton to cy.clickSubmitButton in prescription tests.
cypress/pageobject/Facility/FacilityCreation.ts Changed confirmDeleteFacility method to use cy.clickSubmitButton for delete confirmation.
cypress/pageobject/Login/LoginPage.ts Updated login methods to use cy.clickSubmitButton for login submission.
cypress/pageobject/Patient/PatientCreation.ts Modified methods to use cy.clickSubmitButton for facility selection and patient age confirmation.
cypress/pageobject/Patient/PatientFileupload.ts Changed submitButton to clickSubmitButton in file upload methods.
cypress/support/commands.ts Renamed submitButton to clickSubmitButton and added clickCancelButton command.
cypress/support/index.ts Updated method signatures to reflect changes in button submission methods.

Assessment against linked issues

Objective Addressed Explanation
Create a Cypress test to request a Sample Test and verify its reflection (8926)
Follow the Page Object Model (POM) approach in the test (8926)
Ensure the normal workflow is functional (8926)
Verify modifications are reflected properly (8926)
Verify visibility in the sample test dashboard (8926) Verification of dashboard visibility is not explicitly covered in the tests.

Possibly related PRs

Suggested labels

tested

Suggested reviewers

  • rithviknishad
  • khavinshankar

🐰 "In the meadow where bunnies play,
A new test hops in, brightening the day.
With buttons and fields, all set to go,
Sample requests now flow like a show!
Accessibility's charm, in every detail,
A joyful leap, on this coding trail!" 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

cypress/pageobject/Sample/SampleTestCreate.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in '.eslintrc.json': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /.eslintrc.json
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec01aa and b220acd.

📒 Files selected for processing (1)
  • cypress/pageobject/Sample/SampleTestCreate.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • cypress/pageobject/Sample/SampleTestCreate.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
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: 8

🧹 Outside diff range and nitpick comments (8)
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts (1)

1-8: Consider improving test data management and type safety.

  1. Move test data to a separate fixture file for better maintainability and reusability.
  2. Add TypeScript type annotations for the constants.
 import { SampleTestPage } from "pageobject/Sample/SampleTestCreate";
+import testData from '../fixtures/sampleTest.json';
 
 describe("Sample Test", () => {
   const sampleTestPage = new SampleTestPage();
-  const sampleTestType = "BA/ETA",
-    icmrCategory = "Cat 0",
-    icmrLabel = "Test Icmr Label";
+  const sampleTestType: string = testData.sampleTestType;
+  const icmrCategory: string = testData.icmrCategory;
+  const icmrLabel: string = testData.icmrLabel;
cypress/pageobject/Sample/SampleTestCreate.ts (2)

1-4: Add TypeScript type annotations and improve documentation.

Consider adding type annotations and converting the inline comment to JSDoc format for better TypeScript integration and documentation.

 export class SampleTestPage {
-  sampleTestReportHistory = 0;
-  patientName = ""; // to search for patient in sample page
+  private sampleTestReportHistory: number = 0;
+  /** Patient name used for searching in the sample page */
+  private patientName: string = "";

1-79: Consider architectural improvements for better maintainability and debugging.

While the Page Object Model implementation is good, consider these architectural improvements:

  1. Add logging for better debugging capabilities
  2. Create custom Cypress commands for common operations
  3. Implement retry strategies for flaky operations
  4. Consider splitting into smaller, more focused classes (e.g., separate navigation, form handling, and verification)
src/components/Patient/SampleTest.tsx (3)

230-230: Consider adding validation and improving accessibility for ICMR Category.

While the id="icmr-category" addition is good for testing, consider these improvements:

  1. Add validation in validateForm() to ensure a valid category is selected.
  2. Move the ICMR categories explanation to a separate component or tooltip for better maintainability and accessibility.

256-260: Consider adding format validation for ICMR Label.

While the field has required validation, consider adding:

  1. Pattern validation to ensure the ICMR label follows the expected format
  2. Helper text to guide users on the expected format

Example implementation:

 <TextFormField
   {...field("icmr_label", "ICMR Label")}
   required
   id="icmr-label"
+  pattern="[A-Z0-9-]+"
+  helperText="Enter the ICMR label in uppercase with numbers and hyphens only"
 />

Line range hint 1-326: Consider architectural improvements for better maintainability.

While the changes for testing are good, consider these architectural improvements:

  1. Extract form validation logic into a custom hook for reusability
  2. Move ICMR categories to a configuration file
  3. Consider using a form library like React Hook Form or Formik for better form handling
src/components/Patient/SampleViewAdmin.tsx (1)

349-349: LGTM! Consider consistent ID naming.

The addition of id="search_patient_name" improves test automation capabilities. For consistency across the codebase, consider using either kebab-case (like sample-card) or snake_case (like current) for all IDs.

src/components/Patient/PatientInfoCard.tsx (1)

Line range hint 1-673: Consider breaking down the component for better maintainability.

The PatientInfoCard component handles multiple responsibilities and could benefit from being split into smaller, more focused components. Consider:

  1. Extracting modal-related logic into separate components
  2. Creating a dedicated component for the patient info section
  3. Moving the dropdown menu options into a separate component
  4. Consolidating modal state management using a reducer

This would improve code maintainability, readability, and testing.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a65d7ec and c6e12eb.

📒 Files selected for processing (7)
  • cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts (1 hunks)
  • cypress/pageobject/Sample/SampleTestCreate.ts (1 hunks)
  • src/components/Patient/PatientHome.tsx (1 hunks)
  • src/components/Patient/PatientInfoCard.tsx (1 hunks)
  • src/components/Patient/SampleTest.tsx (4 hunks)
  • src/components/Patient/SampleTestCard.tsx (1 hunks)
  • src/components/Patient/SampleViewAdmin.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/components/Patient/SampleTestCard.tsx
🔇 Additional comments (4)
src/components/Patient/SampleTest.tsx (2)

215-215: LGTM! Verify test coverage for sample type selection.

The addition of id="sample-type" enhances test targeting. The field is properly integrated with form state and validation.

Let's verify the test coverage:

✅ Verification successful

The sample-type field is properly tested in the Cypress test suite

The added id="sample-type" attribute is being utilized effectively in the test suite:

  • Implemented in the page object pattern (SampleTestCreate.ts)
  • Used in E2E test flow (SampleTestRequest.cy.ts)
  • Properly validated with visibility checks before interaction
  • Integrated into the complete form submission workflow
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test cases targeting the sample-type field
rg -l 'sample-type' cypress/

Length of output: 585


Script:

#!/bin/bash
# Let's search more broadly for any test files related to sample testing
fd . cypress/ -e ts -e js | xargs rg -l "sample.*test" -i

# Also search specifically for the sample type selector in test files
rg -A 5 "#sample-type" cypress/

Length of output: 738


Script:

#!/bin/bash
# Let's check the actual test implementation to verify the sample type testing
rg -A 10 "selectSampleType" cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts

Length of output: 436


322-326: LGTM! Verify test coverage for form submission.

The addition of id="sample-test-submit-btn" enhances test targeting. The submission logic is comprehensive.

Let's verify the test coverage:

src/components/Patient/SampleViewAdmin.tsx (1)

149-149: LGTM! Good test automation support.

The addition of id="sample-card" improves test automation capabilities by making the sample card element easily identifiable in Cypress tests.

src/components/Patient/PatientInfoCard.tsx (1)

258-258: LGTM! Adding span wrapper improves accessibility.

The addition of a span element with id="patient-name" enhances DOM accessibility and makes it easier to target the patient's name for testing or styling purposes.

cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts Outdated Show resolved Hide resolved
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts Outdated Show resolved Hide resolved
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts Outdated Show resolved Hide resolved
cypress/pageobject/Sample/SampleTestCreate.ts Outdated Show resolved Hide resolved
cypress/pageobject/Sample/SampleTestCreate.ts Outdated Show resolved Hide resolved
cypress/pageobject/Sample/SampleTestCreate.ts Outdated Show resolved Hide resolved
cypress/pageobject/Sample/SampleTestCreate.ts Outdated Show resolved Hide resolved
src/components/Patient/PatientHome.tsx Show resolved Hide resolved
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts Outdated Show resolved Hide resolved
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts Outdated Show resolved Hide resolved
cypress/e2e/sample_test_spec/SampleTestRequest.cy.ts Outdated Show resolved Hide resolved
cypress/pageobject/Sample/SampleTestCreate.ts Outdated Show resolved Hide resolved
cypress/pageobject/Sample/SampleTestCreate.ts Outdated Show resolved Hide resolved
@nihal467
Copy link
Member

nihal467 commented Nov 5, 2024

@JavidSumra

  • in general, use already existing helper function in commands.ts file and already declared reusable function
  • for any form submission or new page load, add cy. intercept to make sure the API responds properly and the page is fully loaded before your next line of test is executed
  • never use classes if there is a possibility we can add id to the elements
  • always do a manual test of the workflow you are planning to write test and plan properly before start coding

@JavidSumra JavidSumra requested a review from nihal467 November 5, 2024 11:17
@nihal467 nihal467 linked an issue Nov 18, 2024 that may be closed by this pull request
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: 0

🧹 Outside diff range and nitpick comments (2)
cypress/e2e/users_spec/UsersManage.cy.ts (2)

Line range hint 1-192: Consider enhancing test maintainability with beforeEach setup.

While the current implementation works well, consider moving the common setup steps (like advanced filter operations) into the beforeEach block to reduce code duplication and improve maintainability.

Example refactor:

describe("Manage User", () => {
  // ... existing setup ...

  // Add shared test data
  const testData = {
    facilityToLinkSkill: "Dummy Facility 40",
    linkedSkill: "General Medicine",
    // ... other test data ...
  };

  beforeEach(() => {
    cy.restoreLocalStorage();
    cy.clearLocalStorage(/filters--.+/);
    cy.awaitUrl("/users");
    
    // Add common setup for doctor skill tests
    cy.wrap(testData).as('testData');
  });

  // Specific test setup helper
  const setupDoctorSkillTest = () => {
    advanceFilters.clickAdvancedFiltersButton();
    userPage.typeInFirstName(firstNameUserSkill);
    userPage.typeInLastName(lastNameUserSkill);
    userPage.selectHomeFacility(facilitytolinkskill);
    advanceFilters.applySelectedFilter();
  };

  it("linking skills for a doctor users and verify its reflection in doctor connect", () => {
    setupDoctorSkillTest();
    // ... rest of the test ...
  });
});

Line range hint 1-192: Consider adding intercepts for API calls.

As mentioned in the PR comments by nihal467, adding cy.intercept for form submissions and page loads would make the tests more reliable by ensuring proper API responses and page loads.

Example enhancement:

// Add at the top of the file
const ENDPOINTS = {
  LINK_SKILL: '**/api/v1/skill/link',
  USER_PROFILE: '**/api/v1/user/profile',
  // Add other endpoints
};

it("linking skills for a doctor users and verify its reflection in doctor connect", () => {
  // Intercept API calls
  cy.intercept('POST', ENDPOINTS.LINK_SKILL).as('linkSkill');
  cy.intercept('GET', ENDPOINTS.USER_PROFILE).as('userProfile');

  // ... existing test steps ...

  // Wait for API responses
  cy.wait('@linkSkill');
  cy.wait('@userProfile');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8a73752 and 1b8b464.

📒 Files selected for processing (1)
  • cypress/e2e/users_spec/UsersManage.cy.ts (1 hunks)
🔇 Additional comments (1)
cypress/e2e/users_spec/UsersManage.cy.ts (1)

63-63: LGTM! The home facility selection enhances test reliability.

The addition of selectHomeFacility helps narrow down the user search results before skill linking, making the test more robust and deterministic.

@nihal467 nihal467 added tested reviewed reviewed by a core member and removed needs testing needs review labels Nov 18, 2024
@khavinshankar khavinshankar merged commit b17eb22 into ohcnetwork:develop Nov 19, 2024
20 checks passed
Copy link

@JavidSumra 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! 🙌

Rishith25 pushed a commit to Rishith25/care_fe that referenced this pull request Nov 25, 2024
)

Co-authored-by: Mohammed Nihal <57055998+nihal467@users.noreply.github.com>
UdaySagar-Git pushed a commit to UdaySagar-Git/care_fe that referenced this pull request Dec 3, 2024
)

Co-authored-by: Mohammed Nihal <57055998+nihal467@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Jan 15, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewed reviewed by a core member tested
Projects
None yet
4 participants