-
-
Notifications
You must be signed in to change notification settings - Fork 209
Impove chapter/project leaders presentation #1772
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
Draft
rudransh-shrivastava
wants to merge
8
commits into
OWASP:main
Choose a base branch
from
rudransh-shrivastava:feature/improve-leaders-presentation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−50
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b40862a
Add leaders presentation block in chapters and projects
rudransh-shrivastava 1d9e438
fix sonar issues
rudransh-shrivastava e9178fe
Merge branch 'main' into feature/improve-leaders-presentation
rudransh-shrivastava 9146e2c
Add leaders presentation block in chapters
rudransh-shrivastava f4408f0
Add tests for LeadersListBlock
rudransh-shrivastava fe0ce30
Merge branch 'main' into feature/improve-leaders-presentation
kasya a0edae1
increase width
rudransh-shrivastava 734be3f
Merge branch 'main' into feature/improve-leaders-presentation
kasya 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
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
113 changes: 113 additions & 0 deletions
113
frontend/__tests__/unit/components/LeadersListBlock.test.tsx
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,113 @@ | ||
import { MockedProvider } from '@apollo/client/testing' | ||
import { render, screen, fireEvent } from '@testing-library/react' | ||
import { useRouter } from 'next/navigation' | ||
import { GET_LEADER_DATA } from 'server/queries/userQueries' | ||
import LeadersListBlock from 'components/LeadersListBlock' | ||
|
||
jest.mock('next/navigation', () => ({ | ||
useRouter: jest.fn(), | ||
})) | ||
|
||
const mockLeaders = { | ||
leader1: 'Role 1', | ||
leader2: 'Role 2', | ||
} | ||
|
||
const mocks = [ | ||
{ | ||
request: { | ||
query: GET_LEADER_DATA, | ||
variables: { key: 'leader1' }, | ||
}, | ||
result: { | ||
data: { | ||
user: { | ||
login: 'leader1', | ||
avatarUrl: 'https://avatars.githubusercontent.com/u/1', | ||
company: 'Company 1', | ||
location: 'Location 1', | ||
name: 'Leader One', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
request: { | ||
query: GET_LEADER_DATA, | ||
variables: { key: 'leader2' }, | ||
}, | ||
result: { | ||
data: { | ||
user: { | ||
login: 'leader2', | ||
avatarUrl: 'https://avatars.githubusercontent.com/u/2', | ||
company: 'Company 2', | ||
location: 'Location 2', | ||
name: 'Leader Two', | ||
}, | ||
}, | ||
}, | ||
}, | ||
] | ||
|
||
describe('LeadersListBlock', () => { | ||
const push = jest.fn() | ||
beforeEach(() => { | ||
;(useRouter as jest.Mock).mockReturnValue({ push }) | ||
}) | ||
|
||
test('renders loading state initially', () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<LeadersListBlock leaders={mockLeaders} /> | ||
</MockedProvider> | ||
) | ||
|
||
expect(screen.getByText('Loading leader1...')).toBeInTheDocument() | ||
expect(screen.getByText('Loading leader2...')).toBeInTheDocument() | ||
}) | ||
|
||
test('renders user cards on successful data fetch', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<LeadersListBlock leaders={mockLeaders} /> | ||
</MockedProvider> | ||
) | ||
|
||
expect(await screen.findByText('Leader One')).toBeInTheDocument() | ||
expect(await screen.findByText('Leader Two')).toBeInTheDocument() | ||
}) | ||
|
||
test('navigates to the correct user profile on button click', async () => { | ||
render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<LeadersListBlock leaders={mockLeaders} /> | ||
</MockedProvider> | ||
) | ||
|
||
const viewProfileButton = await screen.findAllByText('View Profile') | ||
fireEvent.click(viewProfileButton[0]) | ||
|
||
expect(push).toHaveBeenCalledWith('/members/leader1') | ||
}) | ||
|
||
test('renders an error message if the query fails', async () => { | ||
const errorMocks = [ | ||
{ | ||
request: { | ||
query: GET_LEADER_DATA, | ||
variables: { key: 'leader1' }, | ||
}, | ||
error: new Error('An error occurred'), | ||
}, | ||
] | ||
|
||
render( | ||
<MockedProvider mocks={errorMocks} addTypename={false}> | ||
<LeadersListBlock leaders={{ leader1: 'Role 1' }} /> | ||
</MockedProvider> | ||
) | ||
|
||
expect(await screen.findByText("Error loading leader1's data")).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
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
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,77 @@ | ||
'use client' | ||
import { useQuery } from '@apollo/client' | ||
import { IconProp } from '@fortawesome/fontawesome-svg-core' | ||
import { useRouter } from 'next/navigation' | ||
import FontAwesomeIconWrapper from 'wrappers/FontAwesomeIconWrapper' | ||
import { GET_LEADER_DATA } from 'server/queries/userQueries' | ||
import { LeadersListBlockProps } from 'types/leaders' | ||
import { User } from 'types/user' | ||
import AnchorTitle from 'components/AnchorTitle' | ||
import SecondaryCard from 'components/SecondaryCard' | ||
import UserCard from 'components/UserCard' | ||
|
||
const LeadersListBlock = ({ | ||
leaders, | ||
label = 'Leaders', | ||
icon, | ||
}: { | ||
leaders: LeadersListBlockProps | ||
label?: string | ||
icon?: IconProp | ||
}) => { | ||
return ( | ||
<SecondaryCard icon={icon} title={<AnchorTitle title={label} />}> | ||
<div className="flex w-full flex-col items-center justify-around overflow-hidden md:flex-row"> | ||
{Object.keys(leaders).map((username) => ( | ||
<div key={username}> | ||
<LeaderData username={username} leaders={leaders} /> | ||
</div> | ||
))} | ||
</div> | ||
</SecondaryCard> | ||
) | ||
} | ||
|
||
const LeaderData = ({ | ||
username, | ||
leaders, | ||
}: { | ||
username: string | ||
leaders: LeadersListBlockProps | ||
}) => { | ||
const { data, loading, error } = useQuery(GET_LEADER_DATA, { | ||
variables: { key: username }, | ||
}) | ||
const router = useRouter() | ||
|
||
if (loading) return <p>Loading {username}...</p> | ||
if (error) return <p>Error loading {username}'s data</p> | ||
|
||
const user = data?.user | ||
|
||
if (!user) { | ||
return <p>No data available for {username}</p> | ||
} | ||
|
||
const handleButtonClick = (user: User) => { | ||
router.push(`/members/${user.login}`) | ||
} | ||
|
||
return ( | ||
<UserCard | ||
avatar={user.avatarUrl} | ||
button={{ | ||
icon: <FontAwesomeIconWrapper icon="fa-solid fa-right-to-bracket" />, | ||
label: 'View Profile', | ||
onclick: () => handleButtonClick(user), | ||
}} | ||
className="w-42 h-64 bg-inherit" | ||
company={user.company} | ||
description={leaders[user.login]} | ||
location={user.location} | ||
name={user.name || username} | ||
/> | ||
) | ||
} | ||
|
||
export default LeadersListBlock |
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
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.
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.
@rudransh-shrivastava were you able to see any Leaders data on the frontend? Checking this, and I don't think this resolver returns anything - it's just an empty list all the time. And that's because there's no
self.leaders.all()
Uh oh!
There was an error while loading. Please reload this page.
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.
Also, feel free to use

http://localhost:8000/graphql/
to see data that is returned by graphQL request while working on updating queries - this is super helpful!Uh oh!
There was an error while loading. Please reload this page.
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.
Yes @kasya , you're right that there are no leaders.
There are two fields in the OWASP database model
since
leaders
maps togithub.User
, I was using this field to access leader's logins/usernames.The
leaders_raw
field is a list of strings like ["Rudransh Shrivastava"].leaders
forprojects
orchapters
do not have any data in the database -- but forleaders_raw
there is.If i take a random project for example:

This is the
leaders_raw
field.This is the

leaders
field - which is empty.I'm not sure why
leaders
is empty. Initially I assumed it was an issue locally. I was able to set leaders manually and test out things.