- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 250
Task/badge implementation in frontend #2273
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
          
     Merged
      
      
            arkid15r
  merged 43 commits into
  OWASP:main
from
Piyushrathoree:task/badge-implementation-in-frontend
  
      
      
   
  Oct 13, 2025 
      
    
  
     Merged
                    Changes from 32 commits
      Commits
    
    
            Show all changes
          
          
            43 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6f9482e
              
                created some initial file and add some changes
              
              
                Piyushrathoree 2289fdd
              
                Add Badge functionality to UserNode and integrate Badges component
              
              
                Piyushrathoree 5b947da
              
                updated the backend file for sorting badges
              
              
                Piyushrathoree f22d2e0
              
                Refactor tests and mock data for badges functionality
              
              
                Piyushrathoree e78e42a
              
                Update frontend/__tests__/unit/components/Badges.test.tsx
              
              
                Piyushrathoree dcb90b7
              
                Update frontend/src/components/Badges.tsx
              
              
                Piyushrathoree 7f270cf
              
                Update frontend/__tests__/unit/pages/UserDetails.test.tsx
              
              
                Piyushrathoree 4fdca0f
              
                Add Font Awesome icons to custom dictionary
              
              
                Piyushrathoree e402712
              
                Make Badge properties readonly
              
              
                Piyushrathoree 21d6803
              
                Sort badges by weight before rendering
              
              
                Piyushrathoree 3e85e89
              
                Use nullish coalescing for user badges
              
              
                Piyushrathoree a38e89d
              
                Add aria-label to FontAwesomeIcon for accessibility
              
              
                Piyushrathoree 984da0d
              
                Update user.py
              
              
                Piyushrathoree f3f2290
              
                Merge branch 'main' into task/badge-implementation-in-frontend
              
              
                Piyushrathoree 39a7a8c
              
                Refactor badge count resolver for improved readability and performanc…
              
              
                Piyushrathoree 8e76f8f
              
                Update backend/apps/github/api/internal/nodes/user.py
              
              
                Piyushrathoree 81b21d9
              
                Update frontend/src/components/Badges.tsx
              
              
                Piyushrathoree 8e846f3
              
                Update frontend/src/components/Badges.tsx
              
              
                Piyushrathoree 3cb9785
              
                Add badgeCount field to UserNode and update related queries; refactor…
              
              
                Piyushrathoree 1121d26
              
                frontend: fix Badges non-prefixed and invalid cssClass handling; adju…
              
              
                Piyushrathoree d32c6bf
              
                Merge branch 'main' into task/badge-implementation-in-frontend
              
              
                Piyushrathoree 1b445b0
              
                fix: correct badge relationship reference in UserNode and update tests
              
              
                 263d53f
              
                refactor: streamline badge display in UserDetailsPage component
              
              
                Piyushrathoree f429bbf
              
                fix: update useParams to use memberKey in UserDetailsPage and adjust …
              
              
                Piyushrathoree 5c69863
              
                fix: adjust class names for better layout consistency in UserDetailsPage
              
              
                Piyushrathoree cc30ab4
              
                Merge branch 'main' into task/badge-implementation-in-frontend
              
              
                kasya f9e044d
              
                Revert "fix: adjust class names for better layout consistency in User…
              
              
                 0e9dede
              
                Merge branch 'task/badge-implementation-in-frontend' of https://githu…
              
              
                Piyushrathoree f429071
              
                Refactor UserNode badge logic and improve Badge component rendering
              
              
                Piyushrathoree ac27f26
              
                done with changes suggested by kate .
              
              
                Piyushrathoree 7535bc9
              
                Update frontend/src/components/Badges.tsx
              
              
                Piyushrathoree fb1e403
              
                CodeRabbit: For Font Awesome icons, the CSS classes are backend-drive…
              
              
                Piyushrathoree 05a694c
              
                Merge branch 'main' into task/badge-implementation-in-frontend
              
              
                Piyushrathoree f39dec0
              
                migration
              
              
                Piyushrathoree 878059d
              
                Update migration timestamp, enhance badge component, and import icon …
              
              
                Piyushrathoree 6e1bbe7
              
                Refactor badge class key from 'bug_slash' to 'bugSlash' for consistency
              
              
                Piyushrathoree 848ae72
              
                Fix issues with badges
              
              
                kasya 995f67a
              
                Merge branch 'main' of github.com:OWASP/Nest into pr/Piyushrathoree/2273
              
              
                kasya 142786e
              
                Fix make check
              
              
                kasya 2078a70
              
                Guard against null/undefined cssClass in normalizeCssClass
              
              
                kasya 84498fc
              
                Add test to verify badge rendering order per backend contract
              
              
                kasya bf7e112
              
                Fix backend test for getting users
              
              
                kasya 6c2a612
              
                Update code
              
              
                arkid15r File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { render, screen } from '@testing-library/react' | ||
| import React from 'react' | ||
| import Badges from 'components/Badges' | ||
|  | ||
| // Mock FontAwesome | ||
| jest.mock('@fortawesome/fontawesome-svg-core', () => ({ | ||
| findIconDefinition: jest.fn(({ iconName }: { iconName: string }) => { | ||
|         
                  kasya marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| // Return truthy value for valid icons, null for invalid | ||
| return iconName === 'medal' ? { iconName } : null | ||
| }), | ||
| })) | ||
|  | ||
| jest.mock('wrappers/FontAwesomeIconWrapper', () => { | ||
| return function MockFontAwesomeIconWrapper({ icon }: { icon: string }) { | ||
| const iconName = icon.split(' ').pop()?.replace('fa-', '') || icon.replace('fa-', '') | ||
| return <span data-testid={`icon-${iconName}`} /> | ||
|         
                  kasya marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
| }) | ||
|  | ||
| jest.mock('@heroui/tooltip', () => ({ | ||
| Tooltip: ({ | ||
| children, | ||
| content, | ||
| isDisabled, | ||
| }: { | ||
| children: React.ReactNode | ||
| content: string | ||
| isDisabled?: boolean | ||
| }) => { | ||
| if (isDisabled) { | ||
| return <>{children}</> | ||
| } | ||
| return ( | ||
| <div data-testid="tooltip" data-content={content}> | ||
| {children} | ||
| </div> | ||
| ) | ||
| }, | ||
| })) | ||
|  | ||
| describe('Badges Component', () => { | ||
| const defaultProps = { | ||
| name: 'Test Badge', | ||
| cssClass: 'fa-solid fa-medal', | ||
| } | ||
|  | ||
| it('renders valid icon with tooltip', () => { | ||
| render(<Badges {...defaultProps} />) | ||
|  | ||
| expect(screen.getByTestId('icon-medal')).toBeInTheDocument() | ||
|         
                  kasya marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| expect(screen.getByTestId('tooltip')).toHaveAttribute('data-content', 'Test Badge') | ||
| }) | ||
|  | ||
| it('renders fallback fa-medal for invalid cssClass', () => { | ||
| render(<Badges {...defaultProps} cssClass="" />) | ||
|  | ||
| expect(screen.getByTestId('icon-medal')).toBeInTheDocument() | ||
| }) | ||
|  | ||
| it('renders fa-question fallback for unrecognized icon', () => { | ||
| render(<Badges {...defaultProps} cssClass="fa-solid fa-unknown" />) | ||
|  | ||
| expect(screen.getByTestId('icon-question')).toBeInTheDocument() | ||
| }) | ||
|  | ||
| it('hides tooltip when showTooltip is false', () => { | ||
| render(<Badges {...defaultProps} showTooltip={false} />) | ||
|  | ||
| expect(screen.getByTestId('icon-medal')).toBeInTheDocument() | ||
| expect(screen.queryByTestId('tooltip')).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import type { Badge } from 'types/badge' | ||
|  | ||
| export const mockBadgeData: Badge[] = [ | ||
| { | ||
| id: '1', | ||
| name: 'Contributor', | ||
| cssClass: 'fa-medal', | ||
| description: 'Active contributor to OWASP projects', | ||
| weight: 1, | ||
| }, | ||
| { | ||
| id: '2', | ||
| name: 'Security Expert', | ||
| cssClass: 'fa-shield-alt', | ||
| description: 'Security expertise demonstrated', | ||
| weight: 2, | ||
| }, | ||
| { | ||
| id: '3', | ||
| name: 'Code Reviewer', | ||
| cssClass: 'fa-code', | ||
| description: 'Regular code reviewer', | ||
| weight: 1, | ||
| }, | ||
| { | ||
| id: '4', | ||
| name: 'Mentor', | ||
| cssClass: 'fa-user-graduate', | ||
| description: 'Mentors other contributors', | ||
| weight: 3, | ||
| }, | ||
| { | ||
| id: '5', | ||
| name: 'Project Lead', | ||
| cssClass: 'fa-crown', | ||
| description: 'Leads OWASP projects', | ||
| weight: 4, | ||
| }, | ||
| ] | ||
|  | ||
| export const mockUserBadgeQueryResponse = { | ||
| user: { | ||
| id: '1', | ||
| login: 'testuser', | ||
| name: 'Test User', | ||
| badges: mockBadgeData, | ||
| badgeCount: 5, | ||
| }, | ||
| } | ||
|  | ||
| export const mockUserWithoutBadgeQueryResponse = { | ||
| user: { | ||
| id: '2', | ||
| login: 'testuser2', | ||
| name: 'Test User 2', | ||
| badges: [], | ||
| badgeCount: 0, | ||
| }, | ||
| } | ||
|  | ||
| export const mockBadgeQueryResponse = { | ||
| badges: mockBadgeData, | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.