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

Fixed the cypress env config file and removed hardcoded fallback #9184

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

nihal467
Copy link
Member

@nihal467 nihal467 commented Nov 22, 2024

Proposed Changes

  • Fixes #issue_number
  • Change 1
  • Change 2
  • More?

@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

  • New Features
    • Enhanced configuration to load environment variables from a .env file for improved flexibility.
    • Updated the method of setting the API_URL, streamlining how the application retrieves its API endpoint.
    • Improved user interface and accessibility for the audio recording controls in the AudioCaptureDialog component.
  • Bug Fixes
    • Reduced wait time in the recordAudio method for a more responsive recording experience.

@nihal467 nihal467 requested a review from a team as a code owner November 22, 2024 08:25
Copy link

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

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4c5f182
Status: ✅  Deploy successful!
Preview URL: https://53a05c0c.care-fe.pages.dev
Branch Preview URL: https://cypress-env.care-fe.pages.dev

View logs

Copy link
Contributor

coderabbitai bot commented Nov 22, 2024

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes in this pull request primarily involve modifications to the cypress.config.ts file, where an import statement for the dotenv package has been added to facilitate loading environment variables from a .env file. Additionally, the assignment of API_URL has been updated to directly use process.env.REACT_CARE_API_URL, removing the previous fallback mechanism. The PatientFileUpload class has seen a reduction in wait time for audio recording, while the AudioCaptureDialog component has been enhanced for accessibility with a new id attribute.

Changes

File Change Summary
cypress.config.ts Added import for dotenv and called dotenv.config(). Updated API_URL assignment to directly use process.env.REACT_CARE_API_URL without a fallback.
cypress/pageobject/Patient/PatientFileupload.ts Reduced wait time in recordAudio method from 5000ms to 2000ms before clicking #start-recording and adjusted timing for stopping the recording.
src/components/Files/AudioCaptureDialog.tsx Added id attribute to the div containing the start recording button for improved accessibility.

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • khavinshankar

🐰 In the config, a change so bright,
With dotenv now, the vars take flight.
API URL, now clear and true,
No fallback needed, just the new.
Hopping along, the tests will run,
With these updates, we'll have some fun! 🌟


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 22, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 4c5f182
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/674070906b1ea40008804e5f
😎 Deploy Preview https://deploy-preview-9184--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 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 (1)
cypress.config.ts (1)

3-3: Consider improving dotenv import and configuration.

  1. Use default import for dotenv instead of namespace import
  2. Add error handling for dotenv configuration
-import * as dotenv from "dotenv";
+import dotenv from "dotenv";

-dotenv.config();
+try {
+  const result = dotenv.config();
+  if (result.error) {
+    console.error('Error loading .env file:', result.error);
+  }
+} catch (error) {
+  console.error('Error configuring dotenv:', error);
+}

Also applies to: 6-6

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 10369c5 and 5f8bbb1.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • cypress.config.ts (2 hunks)
🔇 Additional comments (1)
cypress.config.ts (1)

38-40: ⚠️ Potential issue

Verify environment variable handling.

  1. Removing the fallback value for API_URL could cause runtime issues if REACT_CARE_API_URL is undefined
  2. Inconsistent handling between API_URL (no fallback) and ENABLE_HCX (has fallback)

Consider adding validation:

 env: {
-  API_URL: process.env.REACT_CARE_API_URL,
+  API_URL: process.env.REACT_CARE_API_URL || (() => {
+    throw new Error('REACT_CARE_API_URL environment variable is required');
+  })(),
   ENABLE_HCX: process.env.REACT_ENABLE_HCX ?? false,
 },

Copy link

cypress bot commented Nov 22, 2024

CARE    Run #3944

Run Properties:  status check passed Passed #3944  •  git commit 4d5929f8d4: Fixed the cypress env config file and removed hardcoded fallback
Project CARE
Branch Review cypress-env
Run status status check passed Passed #3944
Run duration 05m 10s
Commit git commit 4d5929f8d4: Fixed the cypress env config file and removed hardcoded fallback
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 135
View all changes introduced in this branch ↗︎

@nihal467 nihal467 self-assigned this Nov 22, 2024
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5f8bbb1 and 4d5929f.

📒 Files selected for processing (2)
  • cypress/pageobject/Patient/PatientFileupload.ts (1 hunks)
  • src/components/Files/AudioCaptureDialog.tsx (1 hunks)
🔇 Additional comments (1)
src/components/Files/AudioCaptureDialog.tsx (1)

136-136: LGTM! Adding ID improves test stability.

The addition of id="start-recording" provides a more reliable selector for Cypress tests.

Let's verify if the reduced wait time in Cypress tests (from 5000ms to 2000ms) is reliable:

✅ Verification successful

Based on the shell script results, I can see that:

  1. The getUserMedia operation in AudioCaptureDialog.tsx is asynchronous and affects the recording button's availability
  2. The Cypress test file (PatientFileupload.ts) shows that after clicking the start recording button, there's a 2000ms wait before clicking stop
  3. The component handles microphone permissions asynchronously before enabling recording

Let's verify if there are any other timing-related operations in the component:


Reduced wait time in tests is reliable for AudioCaptureDialog component

The 2000ms wait time is appropriate because:

  1. The component handles microphone permissions asynchronously before enabling recording
  2. The timer starts only after permissions are granted and recording begins
  3. The component has proper state management (WAITING_TO_RECORD, RECORDING, PERMISSION_DENIED, RECORDED)
  4. The test waits for the stable #start-recording selector before interacting
  5. No other async operations block the recording functionality after permissions are granted
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential race conditions or timing issues in the component

# Look for async operations that might affect the recording button's availability
rg -A 5 "getUserMedia|setTimeout|setInterval|Promise" src/components/Files/AudioCaptureDialog.tsx

# Check if there are any other Cypress commands with longer wait times
rg -A 5 "cy\.wait|cy\.intercept" cypress/

Length of output: 64117


Script:

#!/bin/bash
# Check for timer-related code and state management in AudioCaptureDialog.tsx
rg -A 10 "timer\.|useState|useEffect" src/components/Files/AudioCaptureDialog.tsx

Length of output: 2305

Comment on lines +23 to +25
cy.wait(2000);
cy.get("#start-recording").click();
cy.wait(2000);
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

Consider replacing hard-coded waits with proper element state checks

The current implementation uses multiple cy.wait() calls with hard-coded timeouts, which could make tests flaky. Consider making the following improvements:

  recordAudio() {
    cy.get("#record-audio").click();
-   cy.wait(2000);
-   cy.get("#start-recording").click();
-   cy.wait(2000);
+   cy.get("#start-recording")
+     .should("be.visible")
+     .and("be.enabled")
+     .click();
+   // Wait for recording to start
+   cy.get("#recording-indicator")
+     .should("be.visible")
+     .and("have.class", "recording");
    cy.get("#stop-recording").click();
-   cy.wait(1000);
+   // Wait for recording to complete
+   cy.get("#recording-indicator")
+     .should("not.have.class", "recording");
    cy.get("#save-recording").click();
  }

This refactor:

  1. Removes arbitrary wait times
  2. Adds proper element state checks
  3. Makes the test more reliable by waiting for actual UI states
  4. Follows Cypress best practices for handling async operations

Note: Adjust the selectors (#recording-indicator) and classes (recording) according to your actual implementation.

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

@rithviknishad rithviknishad merged commit 2fdffa2 into develop Nov 22, 2024
22 checks passed
@rithviknishad rithviknishad deleted the cypress-env branch November 22, 2024 11:57
Copy link

@nihal467 @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
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants