-
-
Notifications
You must be signed in to change notification settings - Fork 848
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
Fixed error message in PostCard.tsx #3152
Merged
palisadoes
merged 7 commits into
PalisadoesFoundation:develop-postgres
from
Nivedita-Chhokar:issue-3142
Jan 18, 2025
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3591d4e
Fixed error message on PostCard.tsx
Nivedita-Chhokar 496ac80
Added translation of text and added a test case for my code
Nivedita-Chhokar 246d643
handle empty comment validation
Nivedita-Chhokar 5ea8c1c
updated error handling
Nivedita-Chhokar 0e0b8e7
improved error handling
Nivedita-Chhokar c2c73f5
Improve error handling and add test coverage for edge cases
Nivedita-Chhokar 180c971
Added missing providers
Nivedita-Chhokar 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React, { act } from 'react'; | ||
import { MockedProvider } from '@apollo/react-testing'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { I18nextProvider } from 'react-i18next'; | ||
import { Provider } from 'react-redux'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
@@ -661,6 +661,119 @@ describe('Testing PostCard Component [User Portal]', () => { | |
await wait(); | ||
}); | ||
|
||
test('Comment validation displays an error toast when an empty comment is submitted', async () => { | ||
console.log('Starting empty comment validation test'); | ||
|
||
const cardProps = { | ||
id: '1', | ||
userImage: 'image.png', | ||
creator: { | ||
firstName: 'test', | ||
lastName: 'user', | ||
email: '[email protected]', | ||
id: '1', | ||
}, | ||
postedAt: '', | ||
image: 'testImage', | ||
video: '', | ||
text: 'This is post test text', | ||
title: 'This is post test title', | ||
likeCount: 1, | ||
commentCount: 0, | ||
comments: [], | ||
likedBy: [ | ||
{ | ||
firstName: 'test', | ||
lastName: 'user', | ||
id: '1', | ||
}, | ||
], | ||
fetchPosts: vi.fn(), | ||
}; | ||
|
||
expect(toast.error).toBeDefined(); | ||
|
||
render( | ||
<MockedProvider addTypename={false} link={link}> | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<I18nextProvider i18n={i18nForTest}> | ||
<PostCard {...cardProps} /> | ||
</I18nextProvider> | ||
</Provider> | ||
</BrowserRouter> | ||
</MockedProvider>, | ||
); | ||
|
||
userEvent.click(screen.getByTestId('viewPostBtn')); // Open the post view | ||
userEvent.type(screen.getByTestId('commentInput'), ''); // Type an empty comment | ||
userEvent.click(screen.getByTestId('createCommentBtn')); | ||
|
||
await waitFor(() => { | ||
expect(toast.error).toHaveBeenCalledWith( | ||
i18nForTest.t('postCard.emptyCommentError'), | ||
rishav-jha-mech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
}); | ||
}); | ||
|
||
test('Comment submission displays error toast when network error occurs', async () => { | ||
const cardProps = { | ||
id: '1', | ||
userImage: 'image.png', | ||
creator: { | ||
firstName: 'test', | ||
lastName: 'user', | ||
email: '[email protected]', | ||
id: '1', | ||
}, | ||
postedAt: '', | ||
image: 'testImage', | ||
video: '', | ||
text: 'This is post test text', | ||
title: 'This is post test title', | ||
likeCount: 1, | ||
commentCount: 0, | ||
comments: [], | ||
likedBy: [ | ||
{ | ||
firstName: 'test', | ||
lastName: 'user', | ||
id: '1', | ||
}, | ||
], | ||
fetchPosts: vi.fn(), | ||
}; | ||
|
||
const errorLink = new StaticMockLink([ | ||
{ | ||
request: { | ||
query: CREATE_COMMENT_POST, | ||
variables: { | ||
postId: '1', | ||
comment: 'test comment', | ||
}, | ||
}, | ||
error: new Error('Network error'), | ||
}, | ||
]); | ||
|
||
render( | ||
<MockedProvider link={errorLink}> | ||
<PostCard {...cardProps} /> | ||
</MockedProvider>, | ||
); | ||
rishav-jha-mech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
userEvent.click(screen.getByTestId('viewPostBtn')); | ||
userEvent.type(screen.getByTestId('commentInput'), 'test comment'); | ||
userEvent.click(screen.getByTestId('createCommentBtn')); | ||
|
||
await waitFor(() => { | ||
expect(toast.error).toHaveBeenCalledWith( | ||
i18nForTest.t('postCard.unexpectedError'), | ||
); | ||
}); | ||
}); | ||
|
||
test(`Comment should be liked when like button is clicked`, async () => { | ||
const cardProps = { | ||
id: '1', | ||
|
This file contains 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.
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.
@Nivedita-Chhokar code rabbit is asking you to remove this line
console.log should not be here
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.
@rishav-jha-mech Thank you for your review. I'll remove that line, but could you share your thoughts on the other suggestions made by Code Rabbit? Also, if you have any additional recommendations, I'd appreciate them.