-
-
Notifications
You must be signed in to change notification settings - Fork 632
Limit releases to only show most recent ones #4570
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
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7613c1c
feat: toggle button to showAll/showLess releases
devnchill 21fc8ce
refactor: rename showAll to showAllReleases
devnchill 64c0e57
fix: set showAllRelease to false whenever shanpshots change
devnchill 2d36380
fix: incorrect tailwind class replaced uppercase k with lowercase k i…
devnchill 697c955
refactor: move MAX_RELEASES_TO_SHOW to util/constant.ts
devnchill 2361dd6
refactor: extract ReleaseSection as a component from snapshot page
devnchill 102607c
feat: add unit test for SnapshotReleaseComponent
devnchill d4a485e
Update ShowMore button to use existing component
kasya 4f73c62
Merge branch 'main' into feat/limit-release
kasya fb8e628
Address Sonar issue
kasya 18aaa44
Merge branch 'feat/limit-release' of github.com:devnchill/Nest into p…
kasya fb57074
Update code
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
42 changes: 42 additions & 0 deletions
42
frontend/__tests__/unit/components/SnapshotReleaseSection.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,42 @@ | ||
| import '@testing-library/jest-dom' | ||
| import { fireEvent, render, screen } from '@testing-library/react' | ||
|
|
||
| import { MAX_RELEASES_TO_SHOW } from 'utils/constants' | ||
| import { ReleasesSection } from 'components/SnapshotReleaseSection' | ||
|
|
||
| describe('ReleasesSection', () => { | ||
| const mockReleases = Array.from({ length: MAX_RELEASES_TO_SHOW + 1 }, (_, i) => ({ | ||
| id: `release-${i}`, | ||
| name: `Release v${i}`, | ||
| publishedAt: new Date().toISOString(), | ||
| tagName: `v${i}`, | ||
| })) | ||
|
|
||
| it('renders only MAX_RELEASES_TO_SHOW items when showAll is false', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={jest.fn()} />) | ||
|
|
||
| const items = screen.getAllByText(/Release v/) | ||
| expect(items.length).toBe(MAX_RELEASES_TO_SHOW) | ||
| }) | ||
|
|
||
| it('renders all releases when showAll is true', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={true} onToggle={jest.fn()} />) | ||
|
|
||
| const items = screen.getAllByText(/Release v/) | ||
| expect(items.length).toBe(MAX_RELEASES_TO_SHOW + 1) | ||
| }) | ||
|
|
||
| it('renders the show more button for releases > MAX_RELEASES_TO_SHOW', () => { | ||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={jest.fn()} />) | ||
| expect(screen.getByRole('button', { name: 'Show more' })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('calls onToggle when the show more button is clicked', () => { | ||
| const onToggle = jest.fn() | ||
|
|
||
| render(<ReleasesSection releases={mockReleases} showAll={false} onToggle={onToggle} />) | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: 'Show more' })) | ||
| expect(onToggle).toHaveBeenCalledTimes(1) | ||
| }) | ||
| }) | ||
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,33 @@ | ||
| import type { Release as ReleaseType } from 'types/release' | ||
| import { MAX_RELEASES_TO_SHOW } from 'utils/constants' | ||
| import Release from 'components/Release' | ||
| import ShowMoreButton from 'components/ShowMoreButton' | ||
|
|
||
| type ReleasesSectionProps = { | ||
| releases: ReleaseType[] | ||
| showAll: boolean | ||
| onToggle: () => void | ||
| } | ||
|
|
||
| export const ReleasesSection = ({ releases, showAll, onToggle }: ReleasesSectionProps) => { | ||
| const visibleReleases = showAll ? releases : releases.slice(0, MAX_RELEASES_TO_SHOW) | ||
| return ( | ||
| <> | ||
| <div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3"> | ||
| {visibleReleases.map((release, index) => { | ||
| return ( | ||
| <Release | ||
| key={ | ||
| release.id || `${release.tagName}-${release.repositoryName ?? 'unknown'}-${index}` | ||
| } | ||
| release={release} | ||
| showAvatar={true} | ||
| index={index} | ||
| /> | ||
| ) | ||
| })} | ||
| </div> | ||
| {releases.length > MAX_RELEASES_TO_SHOW && <ShowMoreButton onToggle={onToggle} />} | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| </> | ||
| ) | ||
| } | ||
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.