-
-
Notifications
You must be signed in to change notification settings - Fork 629
Refactored CardDetailsPage into smaller components #4519
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
Open
anurag2787
wants to merge
16
commits into
OWASP:main
Choose a base branch
from
anurag2787:refractor/carddetailspage
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.
Open
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b0644dc
Refactored CardDetailsPage into smaller components
anurag2787 6548e9c
fixed review
anurag2787 b200004
Merge branch 'main' of github.com:anurag2787/Nest into refractor/card…
anurag2787 5df2ff5
reslove conflict
anurag2787 fc0a006
updated refractored
anurag2787 2da3fd2
fix review
anurag2787 3579d0c
fixed review'
anurag2787 52d0bbb
Merge branch 'main' into refractor/carddetailspage
anurag2787 656a2e8
fixed failed test
anurag2787 dac3185
fixed test
anurag2787 f3c1ecf
fix: use keyboard navigation for map unlock button to avoid pointer i…
anurag2787 d7db76f
update code
anurag2787 26562bd
fix
anurag2787 d1f0cbd
Merge branch 'main' into refractor/carddetailspage
anurag2787 b9f4fdf
Merge branch 'main' of github.com:anurag2787/Nest into refractor/card…
anurag2787 322cd05
Merge branch 'main' into refractor/carddetailspage
anurag2787 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
2,327 changes: 117 additions & 2,210 deletions
2,327
frontend/__tests__/unit/components/CardDetailsPage.test.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
frontend/__tests__/unit/components/CardDetailsPage/CardDetailsContributions.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,150 @@ | ||
| import { render, screen } from '@testing-library/react' | ||
| import React from 'react' | ||
| import '@testing-library/jest-dom' | ||
| import CardDetailsContributions from 'components/CardDetailsPage/CardDetailsContributions' | ||
|
|
||
| jest.mock('components/ContributionHeatmap', () => ({ | ||
| __esModule: true, | ||
| default: ({ stats }: { stats: object }) => ( | ||
| <div data-testid="contribution-heatmap">Heatmap: {JSON.stringify(stats)}</div> | ||
| ), | ||
| })) | ||
|
|
||
| jest.mock('components/ContributionStats', () => ({ | ||
| __esModule: true, | ||
| default: ({ stats }: { stats: object }) => ( | ||
| <div data-testid="contribution-stats">Stats: {JSON.stringify(stats)}</div> | ||
| ), | ||
| })) | ||
|
|
||
| jest.mock('utils/contributionDataUtils', () => ({ | ||
| shouldShowContributions: jest.fn((type: string) => ['project', 'chapter'].includes(type)), | ||
| })) | ||
|
|
||
| jest.mock('next/link', () => { | ||
| return ({ children, href }: { children: React.ReactNode; href: string }) => ( | ||
| <a href={href}>{children}</a> | ||
| ) | ||
| }) | ||
|
|
||
| describe('CardDetailsContributions', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| it('renders nothing when no contribution stats provided', () => { | ||
| const { container } = render( | ||
| <CardDetailsContributions type="project" hasContributions={false} /> | ||
| ) | ||
| expect(container.firstChild).toBeNull() | ||
| }) | ||
|
|
||
| it('renders nothing when shouldShowContributions returns false', () => { | ||
| const { container } = render( | ||
| <CardDetailsContributions | ||
| type="repository" | ||
| hasContributions={true} | ||
| contributionStats={{ | ||
| totalContributions: 100, | ||
| heatmapData: [], | ||
| }} | ||
| /> | ||
| ) | ||
| expect(container.firstChild).toBeNull() | ||
| }) | ||
|
|
||
| it('renders contribution stats when stats provided for project type', () => { | ||
| const stats = { | ||
| totalContributions: 150, | ||
| heatmapData: [1, 2, 3, 4, 5], | ||
| } | ||
|
|
||
| render( | ||
| <CardDetailsContributions type="project" hasContributions={true} contributionStats={stats} /> | ||
| ) | ||
|
|
||
| expect(screen.getByTestId('contribution-stats')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders contribution heatmap with required props', () => { | ||
| render( | ||
| <CardDetailsContributions | ||
| type="project" | ||
| hasContributions={true} | ||
| contributionData={{ '2024-01-01': 5 }} | ||
| startDate="2024-01-01" | ||
| endDate="2024-01-31" | ||
| /> | ||
| ) | ||
|
|
||
| expect(screen.getByTestId('contribution-heatmap')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders both stats and heatmap components together', () => { | ||
| const stats = { | ||
| totalContributions: 100, | ||
| averageContribution: 50, | ||
| heatmapData: [], | ||
| } | ||
|
|
||
| render( | ||
| <CardDetailsContributions | ||
| type="project" | ||
| hasContributions={true} | ||
| contributionStats={stats} | ||
| contributionData={{ '2024-01-01': 5 }} | ||
| startDate="2024-01-01" | ||
| endDate="2024-01-31" | ||
| /> | ||
| ) | ||
|
|
||
| expect(screen.getByTestId('contribution-stats')).toBeInTheDocument() | ||
| expect(screen.getByTestId('contribution-heatmap')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('does not render when hasContributions is false', () => { | ||
| const { container } = render( | ||
| <CardDetailsContributions | ||
| type="project" | ||
| hasContributions={false} | ||
| contributionStats={{ totalContributions: 100 }} | ||
| /> | ||
| ) | ||
| expect(container.firstChild).toBeNull() | ||
| }) | ||
|
|
||
| it('does not render for repository type even with contributions', () => { | ||
| const { container } = render( | ||
| <CardDetailsContributions | ||
| type="repository" | ||
| hasContributions={true} | ||
| contributionStats={{ totalContributions: 100 }} | ||
| /> | ||
| ) | ||
| expect(container.firstChild).toBeNull() | ||
| }) | ||
|
|
||
| it('does not render for program type even with contributions', () => { | ||
| const { container } = render( | ||
| <CardDetailsContributions | ||
| type="program" | ||
| hasContributions={true} | ||
| contributionStats={{ totalContributions: 100 }} | ||
| /> | ||
| ) | ||
| expect(container.firstChild).toBeNull() | ||
| }) | ||
|
|
||
| it('renders for chapter type with contributions', () => { | ||
| const stats = { | ||
| totalContributions: 50, | ||
| heatmapData: [], | ||
| } | ||
|
|
||
| render( | ||
| <CardDetailsContributions type="chapter" hasContributions={true} contributionStats={stats} /> | ||
| ) | ||
|
|
||
| expect(screen.getByTestId('contribution-stats')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
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.