-
-
Notifications
You must be signed in to change notification settings - Fork 650
Feature/communit snapshots page #1130
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 13 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
e3120d8
trying out stuff
nipunh 51f1a78
basic implementation completed
nipunh e9060fd
snapshots page completed
nipunh 97d266a
test cases added
nipunh 1179ff6
Merge branch 'main' into feature/communit-snapshots-page
nipunh 391e523
improved code quality
nipunh 03c09b5
corrections
nipunh 6c57eb8
mobile navigation implemented
nipunh c073c2a
code smell removed
nipunh d0eb718
code smell removed
nipunh f59dffd
formatting issue
nipunh 9c69cec
removed trailing spaces
nipunh 33657ea
code formatting improved
nipunh 658de49
code formatting improved
nipunh 4fd3010
test cases updated
nipunh e0e7f46
Merge branch 'main' into feature/communit-snapshots-page
arkid15r 1aab7ad
updated branch
nipunh 64cfe7c
Merge branch 'main' into feature/communit-snapshots-page
nipunh 81f3fbc
Merge branch 'main' into feature/communit-snapshots-page
arkid15r 89af8c7
Merge branch 'main' into feature/communit-snapshots-page
nipunh 3c79828
Merge branch 'main' into feature/communit-snapshots-page
arkid15r 65f4c4f
test cases updated
nipunh 975d70d
code structure updated
nipunh 4eac7b5
updated few cases
nipunh d2aed1a
test coverage completed
nipunh c596951
code cleanup
nipunh 0ec9351
nitpicks resolved
nipunh e164b45
formating
nipunh 342df6d
updated test case
nipunh af3a9e5
Merge branch 'main' into pr/nipunh/1130
arkid15r 5bdf0bc
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import { useQuery } from '@apollo/client' | ||
| import { render, screen, waitFor, fireEvent } from '@testing-library/react' | ||
| import { mockSnapshotDetailsData } from '@unit/data/mockSnapshotData' | ||
| import { useNavigate } from 'react-router-dom' | ||
| import { toaster } from 'components/ui/toaster' | ||
| import Snapshots from 'pages/Snapshots' | ||
|
|
||
| jest.mock('@apollo/client', () => ({ | ||
| ...jest.requireActual('@apollo/client'), | ||
| useQuery: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('react-router-dom', () => ({ | ||
| ...jest.requireActual('react-router-dom'), | ||
| useNavigate: jest.fn(), | ||
| })) | ||
|
|
||
| jest.mock('components/ui/toaster', () => ({ | ||
| toaster: { | ||
| create: jest.fn(), | ||
| __esModule: true, | ||
| default: jest.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| describe('Snapshots Component', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| test('renders loading spinner initially', async () => { | ||
| // Mocking the return value of useQuery | ||
| ;(useQuery as jest.Mock).mockReturnValue({ data: null, loading: true, error: null }) | ||
| render(<Snapshots />) | ||
|
|
||
| expect(screen.getByRole('status')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('renders snapshots after data is loaded', async () => { | ||
| // Mocking the return value with snapshot data | ||
| ;(useQuery as jest.Mock).mockReturnValue({ | ||
| data: { snapshots: mockSnapshotDetailsData }, | ||
| loading: false, | ||
| error: null, | ||
| }) | ||
| render(<Snapshots />) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Snapshot 1')).toBeInTheDocument() | ||
| expect(screen.getByText('Snapshot 2')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| test('displays error message on GraphQL error', async () => { | ||
| // Mocking the return value with an error | ||
| (useQuery as jest.Mock).mockReturnValue({ data: null, loading: false, error: new Error('GraphQL Error') }); | ||
| render(<Snapshots />); | ||
|
|
||
| await waitFor(() => { | ||
| expect(toaster).toHaveBeenCalledWith( | ||
| expect.objectContaining({ title: 'GraphQL Request Failed' }) | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('navigates to snapshot details on button click', async () => { | ||
| const navigateMock = jest.fn(); | ||
| (useNavigate as jest.Mock)(navigateMock); | ||
| // Mocking the return value with snapshot data | ||
| (useQuery as jest.Mock).mockReturnValue({ data: { snapshots: mockSnapshotDetailsData }, loading: false, error: null }); | ||
| render(<Snapshots />); | ||
|
|
||
| await waitFor(() => { | ||
| const viewButtons = screen.getAllByText('View Details'); | ||
| expect(viewButtons).toHaveLength(2); | ||
| fireEvent.click(viewButtons[0]); | ||
| }); | ||
|
|
||
| expect(navigateMock).toHaveBeenCalledWith('/community/snapshots/1'); | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| test('displays "No Snapshots found" when there are no snapshots', async () => { | ||
| // Mocking the return value with no snapshot data | ||
| ;(useQuery as jest.Mock).mockReturnValue({ | ||
| data: { snapshots: [] }, | ||
| loading: false, | ||
| error: null, | ||
| }) | ||
| render(<Snapshots />) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('No Snapshots found')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| test('displays fallback snapshot title if snapshot title is missing', async () => { | ||
| // Mocking the return value with a snapshot that has no title | ||
| ;(useQuery as jest.Mock).mockReturnValue({ | ||
| data: { snapshots: [{ id: '1', title: '', createdAt: '2021-01-01' }] }, | ||
| loading: false, | ||
| error: null, | ||
| }) | ||
| render(<Snapshots />) | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('Untitled Snapshot')).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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { Button } from '@chakra-ui/react' | ||
| import { faChevronRight, faCalendar } from '@fortawesome/free-solid-svg-icons' | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
| import { SnapshotCardProps } from 'types/card' | ||
| import { formatDate } from 'utils/dateFormatter' | ||
|
|
||
| const SnapshotCard = ({ title, button, startAt, endAt }: SnapshotCardProps) => { | ||
| return ( | ||
| <Button | ||
| onClick={button.onclick} | ||
| className="group flex h-40 w-full flex-col items-center rounded-lg bg-white p-6 text-left shadow-lg transition-transform duration-500 hover:scale-105 hover:shadow-xl dark:bg-gray-800 dark:shadow-gray-900/30" | ||
| > | ||
| <div className="text-center"> | ||
| <h3 className="max-w-[250px] text-balance text-lg font-semibold text-gray-900 group-hover:text-blue-500 dark:text-white sm:text-xl"> | ||
| <p>{title}</p> | ||
| </h3> | ||
| </div> | ||
|
|
||
| <div className="flex flex-wrap items-center gap-2 text-gray-600 dark:text-gray-300"> | ||
| <div className="flex items-center"> | ||
| <FontAwesomeIcon icon={faCalendar} className="mr-1 h-4 w-4" /> | ||
| <span> | ||
| {formatDate(startAt)} - {formatDate(endAt)} | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div className="mt-auto inline-flex items-center text-sm font-medium text-blue-500 dark:text-blue-400"> | ||
| View Snapshot | ||
| <FontAwesomeIcon | ||
| icon={faChevronRight} | ||
| className="ml-2 h-4 w-4 transform transition-transform group-hover:translate-x-1" | ||
| /> | ||
| </div> | ||
| </Button> | ||
| ) | ||
| } | ||
|
|
||
| export default SnapshotCard |
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.