-
-
Notifications
You must be signed in to change notification settings - Fork 264
add unit test for ToggleableList component #1960
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
Conversation
Summary by CodeRabbit
WalkthroughA new unit test suite for the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Possibly related PRs
Suggested reviewers
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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
📒 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/navigationwhich is appropriate for Next.js 13+ app router. The mock implementation properly provides thepushfunction 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: trueThis 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.
|
There was a problem hiding this 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.
* 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]>



Proposed change
Resolves #1916
Add unit tests for ToggleableList component
This PR adds comprehensive unit tests for the ToggleableList component, covering:
Checklist
make check-testlocally; all checks and tests passed.