Skip to content

Conversation

@Klath123
Copy link
Contributor

@Klath123 Klath123 commented Aug 3, 2025

Proposed change

Resolves #1916

Add unit tests for ToggleableList component
This PR adds comprehensive unit tests for the ToggleableList component, covering:

  • Rendering with different props (items, label, icon, limit)
  • Show/hide functionality with ShowMoreButton
  • Navigation behavior on item clicks
  • Edge cases (empty arrays, single items, zero limits).

Checklist

  • I've read and followed the contributing guidelines.
  • I've run make check-test locally; all checks and tests passed.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 3, 2025

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for the ToggleableList component, covering rendering, interactive behavior, conditional display of items and buttons, navigation, icon rendering, and edge cases.

Walkthrough

A new unit test suite for the ToggleableList React component has been added. The tests cover rendering, conditional logic, prop-based behaviors, user interactions, default values, edge cases, and navigation. Mocks are used for dependencies, and React Testing Library is used for assertions and event simulation.

Changes

Cohort / File(s) Change Summary
ToggleableList Component Unit Tests
frontend/__tests__/unit/components/ToggleableList.test.tsx
Added comprehensive unit tests for the ToggleableList component, covering rendering, props, event handling, edge cases, and navigation logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Assessment against linked issues

Objective (Issue #1916) Addressed Explanation
Renders successfully with minimal required props; Conditional rendering logic; Prop-based behavior; Event handling; State changes / internal logic; Default values and fallbacks; Text and content rendering; Handles edge cases and invalid inputs
Accessibility roles and labels; DOM structure / classNames / styles Tests for accessibility roles/labels and DOM/classNames/styles are not explicitly described; may need further review.

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • arkid15r
  • kasya

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 54c68ff and f39df4c.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/ToggleableList.test.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/tests/unit/components/ToggleableList.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Run frontend e2e tests
  • GitHub Check: Run frontend unit tests
  • GitHub Check: Run backend tests
  • GitHub Check: CodeQL (python)
  • GitHub Check: CodeQL (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

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: 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 d1a87d6 and 5a43782.

📒 Files selected for processing (1)
  • frontend/__tests__/unit/components/ToggleableList.test.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.
📚 Learning: when testing react page components that use mocked form components, validation logic should be teste...
Learnt from: Rajgupta36
PR: OWASP/Nest#1717
File: frontend/__tests__/unit/pages/createProgram.test.tsx:70-86
Timestamp: 2025-07-12T17:36:57.255Z
Learning: When testing React page components that use mocked form components, validation logic should be tested at the form component level, not the page level. Page-level tests should focus on authentication, role checking, submission handling, and navigation logic.

Applied to files:

  • frontend/__tests__/unit/components/ToggleableList.test.tsx
🔇 Additional comments (6)
frontend/__tests__/unit/components/ToggleableList.test.tsx (6)

1-13: LGTM! Modern Next.js router mocking.

The imports and router mock setup correctly use next/navigation which is appropriate for Next.js 13+ app router. The mock implementation properly provides the push function needed for navigation testing.


15-33: Well-implemented mocks for isolated testing.

The mock implementations effectively isolate the ToggleableList component by:

  • Preserving essential ShowMoreButton functionality (onToggle callback)
  • Maintaining FontAwesome icon properties (className, iconName) for verification
  • Using proper ES module structure with __esModule: true

This allows focused testing of the component's core logic without external dependencies.


42-84: Comprehensive coverage of basic rendering scenarios.

The tests effectively verify:

  • Default limit behavior (10 items displayed initially)
  • Icon rendering with correct CSS classes (mr-2, h-5, w-5)
  • Custom limit prop functionality
  • Conditional ShowMoreButton rendering based on item count vs limit

This aligns well with the PR objectives for testing rendering logic and prop-based behaviors.


86-112: Excellent coverage of interactive behavior.

The expand/collapse tests thoroughly verify the ShowMoreButton toggle functionality, confirming that:

  • Items are properly hidden/shown on state changes
  • The component correctly transitions between expanded and collapsed states
  • Specific items are tested to ensure the limit boundaries work correctly

114-119: Navigation test correctly verifies router integration.

The test properly simulates user interaction and verifies that clicking an item triggers navigation with the expected URL format (/projects?q=React).


121-141: Good coverage of edge cases.

The tests handle important edge scenarios:

  • Empty arrays (no ShowMoreButton expected)
  • Single items (no ShowMoreButton expected)
  • Items exactly equal to limit (boundary condition)

These tests ensure robustness against various input conditions.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 5, 2025

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

@Klath123 Thanks for your PR!
I updated it with some updates that were missing.
Please run make check locally before creating a PR to make sure everything passes. It is required per OWASP Nest Contributing Guidelines.

@kasya kasya added this pull request to the merge queue Aug 5, 2025
Merged via the queue into OWASP:main with commit 2f1f4fe Aug 5, 2025
24 checks passed
trucodd pushed a commit to trucodd/Nest that referenced this pull request Aug 5, 2025
* add unit test for ToggleableList component

* fix suggested change

* made suggested change

* Fix make check and font awesome mock issues

---------

Co-authored-by: Kate Golovanova <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for <ToggleableList> component

2 participants