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

improve code coverage of src/screens/EventManagement #3149

Merged

Conversation

prathmesh703
Copy link
Contributor

@prathmesh703 prathmesh703 commented Jan 5, 2025

What kind of change does this PR introduce?

refactoring,code-coverage

Issue Number:

Fixes #3024 ,Fixes #2546

Did you add tests for your changes?

no

Snapshots/Videos:

Screenshot 2025-01-05 112400
Screenshot 2025-01-05 112424

Summary

refactor of src/screens/EventManagement test file from jest to vitest
added test cases are written for the file src/screens/EventManagement.tsx

Does this PR introduce a breaking change?

NO

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • Tests

    • Enhanced unit test coverage for the Event Management component.
    • Added comprehensive test scenarios for navigation, tab management, and responsive dropdown interactions.
    • Improved testing methodology using React Testing Library and Vitest.
    • Updated the test suite organization for better clarity and focus on user interactions.
  • Refactor

    • Simplified dropdown item click handling in the Event Management component.
    • Streamlined switch statement control flow.
    • Removed unnecessary default case in tab selection logic.

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

Walkthrough

This pull request focuses on refactoring the EventManagement component's testing suite from Jest to Vitest. The changes include creating a new comprehensive test specification file (EventManagement.spec.tsx) with improved test coverage, removing the old test file, and making minor simplifications to the component's implementation. The primary goals are to improve code coverage, migrate to Vitest, and streamline the component's dropdown and tab management logic.

Changes

File Change Summary
src/screens/EventManagement/EventManagement.spec.tsx New test specification file with comprehensive unit tests using Vitest and React Testing Library
src/screens/EventManagement/EventManagement.test.tsx Deleted old test file
src/screens/EventManagement/EventManagement.tsx Simplified dropdown item onClick handling and removed unnecessary default case in switch statement

Assessment against linked issues

Objective Addressed Explanation
Improve Code Coverage [#3024]
Migrate from Jest to Vitest [#2546]

Possibly related PRs

Suggested Labels

refactor

Suggested Reviewers

  • pranshugupta54
  • varshith257

Poem

🐰 In the realm of code, tests dance and twirl,
Vitest and React, a testing pearl
EventManagement's journey, smooth and bright
Coverage soaring to a perfect height
Refactored with love, by a coding rabbit's might! 🧪


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6f1b86 and 7a42eb8.

📒 Files selected for processing (2)
  • src/screens/EventManagement/EventManagement.spec.tsx (1 hunks)
  • src/screens/EventManagement/EventManagement.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/screens/EventManagement/EventManagement.tsx
  • src/screens/EventManagement/EventManagement.spec.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test Application
  • GitHub Check: Analyse Code With CodeQL (javascript)

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.

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

github-actions bot commented Jan 5, 2025

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

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 (3)
src/screens/EventManagement/EventManagement.tsx (2)

203-205: Consider expanding accessibility attributes for the dropdown items.

While the implementation correctly switches the tab, it might be beneficial to include ARIA labels or roles to enhance screen reader support. For example, adding aria-label or role="menuitem" can improve usability for assistive technologies.


270-272: Remove or clarify commented-out default case.

Since you already handle the default tab via useState('dashboard'), keeping these commented-out lines may cause confusion. Removing them or clarifying their purpose helps maintain a clean codebase.

- // no use of default here as the default tab is the dashboard selected in useState
- // default:
- //   return null;
src/screens/EventManagement/EventManagement.spec.tsx (1)

57-66: Use consistent mocking patterns.

Great job mocking useParams. For future maintainability, consider collectively defining all mocks (e.g., for useNavigate, useParams) in a single place or helper function. This helps streamline testing and ensures consistency across various tests.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7bcc58 and 7da0f8b.

📒 Files selected for processing (3)
  • src/screens/EventManagement/EventManagement.spec.tsx (1 hunks)
  • src/screens/EventManagement/EventManagement.test.tsx (0 hunks)
  • src/screens/EventManagement/EventManagement.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • src/screens/EventManagement/EventManagement.test.tsx
🔇 Additional comments (3)
src/screens/EventManagement/EventManagement.spec.tsx (3)

1-19: Enhance test coverage for edge cases.

The setup code and mocking are comprehensive. However, consider adding tests to handle edge cases such as invalid orgId/eventId that only partially match the required parameters, or tests for partial localStorage states (e.g., missing AdminFor key). This can detect rare scenarios where user data might be inconsistent.

Would you like me to propose additional test cases or scripts to verify coverage for these edge scenarios?


164-185: Verify consistent handling of invalid tabs.

Currently, the test sets the tab to 'invalid' and expects the dashboard tab to show by default. Although this behavior is correct, consider explicitly handling an invalid tab in the component logic for clearer code flow, rather than silently showing the default.


223-250: Validate UI feedback when switching tabs from the dropdown.

These tests assert that the dropdown item gets the 'text-secondary' class after being clicked. Confirm in manual testing or storybook that the user receives a clear, visible cue that the tab changed (e.g., updated content area or highlighting).

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 5, 2025
@prathmesh703 prathmesh703 changed the title code coverage improve code coverage of src/screens/EventManagement Jan 5, 2025
@AVtheking
Copy link
Contributor

please fix the failing test cases

@prathmesh703
Copy link
Contributor Author

@AVtheking when i'm running the failed test locally it is giving me more 20 % coverage
Screenshot 2025-01-05 140450

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.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7da0f8b and 05649f5.

📒 Files selected for processing (1)
  • jest.config.js (1 hunks)

jest.config.js Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.92%. Comparing base (bcfb41f) to head (7a42eb8).
Report is 6 commits behind head on develop-postgres.

Additional details and impacted files
@@                  Coverage Diff                  @@
##           develop-postgres    #3149       +/-   ##
=====================================================
+ Coverage             16.54%   89.92%   +73.38%     
=====================================================
  Files                   308      329       +21     
  Lines                  7810     8526      +716     
  Branches               1701     1913      +212     
=====================================================
+ Hits                   1292     7667     +6375     
+ Misses                 6429      627     -5802     
- Partials                 89      232      +143     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 5, 2025
@prathmesh703
Copy link
Contributor Author

@AVtheking can you please review the PR or let me know if anything i wanted to do ?

@palisadoes
Copy link
Contributor

  1. The tests are failing. There is nothing functional to review.
  2. Please fix the failing tests

image

@prathmesh703
Copy link
Contributor Author

@palisadoes fixed the failing tests

@palisadoes
Copy link
Contributor

Please fix the conflicting file

@prathmesh703
Copy link
Contributor Author

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

✅ Actions performed

Full review triggered.

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: 2

🧹 Nitpick comments (3)
src/screens/EventManagement/EventManagement.spec.tsx (3)

208-216: Extract repeated tab options array to reduce duplication.

The tab options array is duplicated. Consider extracting it to a constant at the top of the test file.

+const TAB_OPTIONS = [
+  'dashboard',
+  'registrants',
+  'attendance',
+  'agendas',
+  'actions',
+  'volunteers',
+  'statistics',
+];

 describe('Responsive Dropdown Tests', () => {
   // ... existing code ...

   it('renders dropdown with all options', async () => {
     // ... existing code ...

-    const tabOptions = [
-      'dashboard',
-      'registrants',
-      'attendance',
-      'agendas',
-      'actions',
-      'volunteers',
-      'statistics',
-    ];

-    tabOptions.forEach((option) => {
+    TAB_OPTIONS.forEach((option) => {
       expect(screen.getByTestId(`${option}DropdownItem`)).toBeInTheDocument();
     });
   });

   it('switches tabs through dropdown selection', async () => {
     // ... existing code ...

-    const tabOptions = [
-      'dashboard',
-      'registrants',
-      'attendance',
-      'agendas',
-      'actions',
-      'volunteers',
-      'statistics',
-    ];

-    for (const option of tabOptions) {
+    for (const option of TAB_OPTIONS) {
       // ... existing code ...
     }
   });
 });

Also applies to: 231-239


196-221: Add accessibility tests for the dropdown.

Consider adding tests to verify that the dropdown is keyboard accessible and properly labeled for screen readers.

it('is keyboard accessible', async () => {
  renderEventManagement();
  
  const toggle = screen.getByTestId('tabsDropdownToggle');
  expect(toggle).toHaveAttribute('aria-expanded', 'false');
  
  await act(async () => {
    toggle.focus();
    userEvent.keyboard('{Enter}');
  });
  
  expect(toggle).toHaveAttribute('aria-expanded', 'true');
  
  const firstItem = screen.getByTestId('dashboardDropdownItem');
  expect(firstItem).toHaveFocus();
});

57-252: Add tests for GraphQL error and loading states.

Consider adding test cases to verify the component's behavior when:

  • GraphQL operations fail
  • Data is in a loading state
it('handles GraphQL errors gracefully', async () => {
  const errorLink = new StaticMockLink([
    {
      ...MOCKS_WITH_TIME[0],
      error: new Error('GraphQL Error'),
    },
  ]);
  
  render(
    <MockedProvider link={errorLink}>
      <EventManagement />
    </MockedProvider>
  );
  
  await waitFor(() => {
    expect(screen.getByText('Error loading event data')).toBeInTheDocument();
  });
});

it('shows loading state', async () => {
  renderEventManagement();
  
  expect(screen.getByTestId('loadingSpinner')).toBeInTheDocument();
  
  await waitFor(() => {
    expect(screen.queryByTestId('loadingSpinner')).not.toBeInTheDocument();
  });
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcfb41f and f6f1b86.

📒 Files selected for processing (3)
  • src/screens/EventManagement/EventManagement.spec.tsx (1 hunks)
  • src/screens/EventManagement/EventManagement.test.tsx (0 hunks)
  • src/screens/EventManagement/EventManagement.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • src/screens/EventManagement/EventManagement.test.tsx
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: bitbard3
PR: PalisadoesFoundation/talawa-admin#2588
File: src/components/ChangeLanguageDropdown/ChangeLanguageDropdown.spec.tsx:145-155
Timestamp: 2024-12-02T04:20:11.745Z
Learning: In PRs focused solely on refactoring test cases from Jest to Vitest, avoid suggesting optimizations or changes outside the migration scope.
🔇 Additional comments (2)
src/screens/EventManagement/EventManagement.tsx (2)

203-205: LGTM! Clean simplification of the onClick handler.

The simplified onClick handler maintains the same functionality while improving code readability.


270-272: LGTM! Well-documented removal of unnecessary default case.

The default case removal is justified by the clear comment explaining that 'dashboard' is always the default tab selected in useState.

src/screens/EventManagement/EventManagement.spec.tsx Outdated Show resolved Hide resolved
src/screens/EventManagement/EventManagement.spec.tsx Outdated Show resolved Hide resolved
@palisadoes palisadoes merged commit 0c0b077 into PalisadoesFoundation:develop-postgres Jan 9, 2025
18 checks passed
@rishav-jha-mech rishav-jha-mech self-requested a review January 9, 2025 05:13
Dhiren-Mhatre pushed a commit to Dhiren-Mhatre/talawa-admin that referenced this pull request Jan 9, 2025
…ation#3149)

* code coverage

* jest global coverage decreased

* global jest coverage

* rename file problem solved

* changes requested resolved
@prathmesh703 prathmesh703 deleted the code-coverage branch January 9, 2025 07:57
rishav-jha-mech pushed a commit that referenced this pull request Jan 9, 2025
* prevented unnecessary page reload with complementary test

* Update jest.config.js

* Fixes #2986 - Multiple UI Updates (#3165)

* UI fixes on organisation pages

* Added TSDoc for Truncated Text

* Added Debouncer

* Update src/components/OrgListCard/OrgListCard.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* Added code rabbit suggestions

* Fixed test error

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* refactore src/screens/OrgList from jest to vitest (#3200)

* Improved Code Coverage in src/components/Venues/VenueModal.tsx (#3203)

* Improved Code Coverage in src/components/Venues/VenueModal.tsx

* removed the ignore statements from VenueModal.tsx

* Removed istanbul ignore lines. Code coverage remians 100% (#3207)

* refactored src/screens/FundCampaignPledge from jest to vitest (#3208)

* prettier formatting and disabled ts-specific rules for js in eslint (#3186)

* Improve Code Coverage in src/screens/UserPortal/Settings/Settings.tsx (#3189)

* Preventing Overflow of images in Advertisement and Venue Post modals (#3204)

* improve code coverage of src/screens/EventManagement (#3149)

* code coverage

* jest global coverage decreased

* global jest coverage

* rename file problem solved

* changes requested resolved

* fix: update Chat section title to 'Chats' (#3216)

* removed stale comment line

* Revert "removed stale comment line"

This reverts commit e0fa894.

* removed stale comment line

---------

Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com>
Co-authored-by: Mehul Aggarwal <88583647+AceHunterr@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Syed Ali Ul Hasan <syedaliulhasan19@gmail.com>
Co-authored-by: harshk-89 <133699216+harshk-89@users.noreply.github.com>
Co-authored-by: Amaan ali <amaan.ali.ug22@nsut.ac.in>
Co-authored-by: Yugal Sadhwani <yashsadhwani544@gmail.com>
Co-authored-by: Pranav Nathe <93403830+pranavnathe@users.noreply.github.com>
Co-authored-by: prathmesh703 <146568950+prathmesh703@users.noreply.github.com>
Co-authored-by: Nivedita <141390434+Nivedita-Chhokar@users.noreply.github.com>
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.

3 participants