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

Cypress tests for File Uploads #10774

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

rajku-dev
Copy link
Contributor

@rajku-dev rajku-dev commented Feb 22, 2025

Proposed Changes

  • Fixes (Partly) Create a new cypress test to verify file upload functionalities #10385
  • Cypress test for single Patient file upload
  • Cypress test for multiple Patient files upload
  • Cypress test for Audio file upload
  • Cypress tests for Archive, Download, Rename Patient file
  • Verify archived files are not accessible by any users
  • Check whether a file upload by a user is accessible by another user
  • Cypress test for Convert to PDF
  • Cypress test for Encounter Files

@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

  • Tests
    • Expanded automated tests to validate the complete patient file management workflow, covering single and multiple file uploads, audio recording, renaming, and archiving.
    • Enhanced interface element identifiers on file management screens to ensure consistent interactions and improved overall reliability.
    • Introduced new data attributes for improved testability across various components related to file management and audio capture.

@rajku-dev rajku-dev requested a review from a team as a code owner February 22, 2025 18:56
Copy link
Contributor

coderabbitai bot commented Feb 22, 2025

Walkthrough

A new Cypress test suite for patient file management has been added, covering functionalities such as single/multiple file uploads, audio recording, file renaming, and archiving. A new page object class, PatientFiles, encapsulates various methods for these operations and their API verifications. Additionally, multiple components and a hook have been updated with data-cy attributes to enhance testability without altering core functionality. No exported or public entities were modified.

Changes

File(s) Change Summary
cypress/e2e/patient_spec/patient_files.cy.ts Introduces a new Cypress test suite for patient file management, including tests for file uploads, audio recording, renaming, and archiving.
cypress/pageObject/Patients/PatientFiles.ts Adds a new PatientFiles class with methods for interacting with patient file functionalities and verifying API calls.
src/components/Files/AudioCaptureDialog.tsx, src/components/Files/FileUploadDialog.tsx, src/components/Files/FilesTab.tsx, src/components/Files/ArchivedFileDialog.tsx, src/hooks/useFileUpload.tsx, src/hooks/useFileManager.tsx Adds data-cy attributes to buttons and elements to improve testability for audio capture, file upload, and file management.

Sequence Diagram(s)

sequenceDiagram
    participant Nurse
    participant Cypress
    participant FilesPage
    participant API
    Nurse->>Cypress: Log in and navigate to encounter details
    Cypress->>FilesPage: Open patient files tab
    FilesPage-->>Cypress: Display file management options
    Cypress->>FilesPage: Initiate file upload / audio recording / renaming / archiving
    FilesPage->>API: Trigger corresponding API call
    API-->>FilesPage: Return success response
    FilesPage-->>Cypress: Update UI and verify actions
Loading

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad

Poem

Oh, what a hop, what a delightful spree,
New tests and tweaks for files now set free.
Data-cy carrots scattered all around,
Uploads and recordings in code abound.
With a twitch of my whiskers, I cheer with glee—
Code bunnies rejoice, for progress we see!
🐰🥕 Hop to the rhythm of quality!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95e71af and f388be1.

📒 Files selected for processing (5)
  • cypress/e2e/patient_spec/patient_files.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientFiles.ts (1 hunks)
  • src/components/Files/ArchivedFileDialog.tsx (1 hunks)
  • src/components/Files/FilesTab.tsx (12 hunks)
  • src/hooks/useFileManager.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/hooks/useFileManager.tsx
  • src/components/Files/ArchivedFileDialog.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • cypress/pageObject/Patients/PatientFiles.ts
  • cypress/e2e/patient_spec/patient_files.cy.ts
  • src/components/Files/FilesTab.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Test
  • GitHub Check: OSSAR-Scan
  • GitHub Check: CodeQL-Build
  • GitHub Check: cypress-run (1)
  • GitHub Check: lint

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Feb 22, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit f388be1
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ba9ed4c91cb4000868e11b
😎 Deploy Preview https://deploy-preview-10774.preview.ohc.network
📱 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

🧹 Nitpick comments (2)
cypress/e2e/patient_spec/patient_files.cy.ts (2)

88-127: Consider adding audio content verification.

The test case thoroughly covers UI interactions and API calls. However, consider adding verification for:

  • Audio file content or size after recording
  • Successful download by checking file existence in downloads folder

Apply this diff to add file verification:

 .verifySingleFileUploadSuccess(fileUploadSuccessToast)
 .filterActiveFiles()
-.verifyFilesAdded([audioDisplayName])
+.verifyFilesAdded([audioDisplayName])
+// Verify file size is greater than 0
+.then(() => {
+  cy.readFile(`cypress/downloads/${audioDisplayName}`).should('have.length.gt', 0)
+})

169-169: Track the planned "Convert to PDF" test.

The TODO comment aligns with the PR objectives, which mention that the "Convert to PDF" test is planned but not yet completed.

Would you like me to help implement the "Convert to PDF" test case or create an issue to track this task?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 327a2b8 and 95e71af.

⛔ Files ignored due to path filters (3)
  • cypress/fixtures/sample_file.xlsx is excluded by !**/*.xlsx
  • cypress/fixtures/sample_img1.png is excluded by !**/*.png
  • cypress/fixtures/sample_img2.png is excluded by !**/*.png
📒 Files selected for processing (6)
  • cypress/e2e/patient_spec/patient_files.cy.ts (1 hunks)
  • cypress/pageObject/Patients/PatientFiles.ts (1 hunks)
  • src/components/Files/AudioCaptureDialog.tsx (4 hunks)
  • src/components/Files/FileUploadDialog.tsx (1 hunks)
  • src/components/Files/FilesTab.tsx (5 hunks)
  • src/hooks/useFileUpload.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • src/components/Files/FileUploadDialog.tsx
  • src/hooks/useFileUpload.tsx
  • src/components/Files/AudioCaptureDialog.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (5)
cypress/e2e/patient_spec/patient_files.cy.ts (3)

60-72: LGTM! Well-structured test case for single file upload.

The test case follows good practices by:

  • Using page object pattern for maintainability
  • Verifying both UI interactions and API calls
  • Checking validation errors and success messages
  • Confirming file presence in the UI

74-86: LGTM! Well-structured test case for multiple file uploads.

The test case follows good practices by:

  • Reusing page object methods for maintainability
  • Verifying both UI interactions and API calls
  • Checking validation errors and success messages
  • Confirming multiple files presence in the UI

129-167: LGTM! Comprehensive test case for file lifecycle.

The test case effectively covers the complete file lifecycle:

  • Initial file upload
  • File rename operation
  • File archive operation
  • Archive reason verification
cypress/pageObject/Patients/PatientFiles.ts (1)

1-238: LGTM! Well-designed page object class.

The PatientFiles class follows best practices:

  • Implements page object pattern for better maintainability
  • Uses method chaining for fluent API
  • Provides comprehensive coverage of file management operations
  • Includes proper error handling and verifications
src/components/Files/FilesTab.tsx (1)

285-285: LGTM! Good test coverage with data-cy attributes.

The added data-cy attributes enhance testability by providing reliable selectors for:

  • File options button
  • Add files button
  • Record audio button
  • File rows

Also applies to: 398-398, 441-441, 544-544

@rajku-dev
Copy link
Contributor Author

rajku-dev commented Feb 22, 2025

all of them running fine in local, but creating duplicate file names when re-run, since it targets same patient every time
also due to paging, newly added files move to last page
any suggestions @nihal467

@github-actions github-actions bot added needs-triage question Further information is requested labels Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant