Skip to content
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

my solution #1207

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

my solution #1207

wants to merge 6 commits into from

Conversation

minimal005
Copy link

Copy link

@OkMoroz OkMoroz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. Keep it up!

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Thank you for your hard work on this project! There are a few critical issues that need to be addressed before we can approve the pull request. These include several typographical errors, such as setIsLoadind instead of setIsLoading, which could lead to bugs and confusion. Additionally, there are multiple tests that are currently skipped, and it's important to ensure they are intentionally skipped or enabled if relevant. There are also some extraneous code blocks and duplicate attributes that should be cleaned up to improve code clarity and maintainability. Please address these issues to ensure the code meets the core requirements and functions as expected. Keep up the great work, and I'm confident you'll have this polished in no time! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

@@ -225,7 +254,7 @@ describe('', () => {
cy.get('@users').should('have.callCount', 1);
});

it('should not request posts from API', () => {
it.skip('should not request posts from API', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is skipped. Ensure that it is intentionally skipped and consider enabling it if it is relevant to the test suite.

@@ -236,7 +265,7 @@
cy.get('@posts').should('not.be.called');
});

it('should not request comments from API', () => {
it.skip('should not request comments from API', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is skipped. Ensure that it is intentionally skipped and consider enabling it if it is relevant to the test suite.


describe('UserSelector', () => {
const { el, button, users, selectedUser } = userSelector;

describe('', () => {
it('should have all the loaded users', () => {
it.skip('should have all the loaded users', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is skipped. Ensure that it is intentionally skipped and consider enabling it if it is relevant to the test suite.

page.mockUsers();
cy.visit('/');

users().should('have.length', 10);
});

it('should not have users hardcoded', () => {
cy.intercept('**/users', { fixture: 'someUsers' })
it.skip('should not have users hardcoded', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is skipped. Ensure that it is intentionally skipped and consider enabling it if it is relevant to the test suite.

cy.visit('/');

users().should('have.length', 3);
});

it('should not have users before they are loaded', () => {
it.skip('should not have users before they are loaded', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is skipped. Ensure that it is intentionally skipped and consider enabling it if it is relevant to the test suite.

Comment on lines 40 to 44
{
<button type="button" data-cy="PostButton" className="button is-link">
Close
</button>;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code appears to be extraneous and should be removed. It seems to be a leftover or mistakenly included, as it duplicates the button logic already present in the component.

const [comments, setComments] = useState<CommentItem[]>([]);

const [isError, setIsError] = useState<boolean>(false);
const [isLoading, setIsLoadind] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in state variable name: setIsLoadind should be setIsLoading.


export const PostDetails: React.FC = () => {
return (
<div className="content" data-cy="PostDetails">
<div className="content" data-cy="PostDetails">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate data-cy="PostDetails" attribute. This is unnecessary and should be removed to avoid confusion.

Comment on lines +34 to +36
useEffect(() => {
setIsActive(false);
}, [setIsActive]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook here resets the isActive state to false whenever setIsActive changes. This might not be necessary and could lead to unexpected behavior if setIsActive is updated elsewhere. Consider whether this effect is needed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook here resets the isActive state to false whenever setIsActive changes. This might not be necessary and could lead to unexpected behavior if setIsActive is updated elsewhere. Consider whether this effect is needed.

Good point

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook here resets the isActive state to false whenever setIsActive changes. This might not be necessary and could lead to unexpected behavior if setIsActive is updated elsewhere. Consider whether this effect is needed.

Good point

Not fixed

Comment on lines 33 to 34
.catch(() => {
throw new Error();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch block throws a generic error without any message. Consider providing a more descriptive error message to aid in debugging.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Great job on your progress so far! 🎉 While the code is mostly well-structured and follows best practices, there are a few areas that need attention to enhance clarity and functionality:

  1. Typographical Errors:

    • Correct the state variable setIsLoadind to setIsLoading to avoid confusion and potential bugs.
    • Rename validateform to validateForm to adhere to camelCase naming conventions.
    • Fix post2Coments to post2Comments for consistency.
  2. Skipped Tests: Ensure that the tests currently marked with it.skip are intentionally skipped with a clear reason or enable them if they are relevant.

  3. Extraneous Code: Clean up any extraneous commas and code blocks, such as the one at the end of the intercept setup, to improve readability and maintainability.

  4. Error Handling: Improve error handling by providing more informative error messages or handling specific error scenarios in the catch block.

These improvements will not only enhance the functionality and maintainability of your code but also help you grow as a developer. Keep up the great work, and make sure to address these issues in future iterations to avoid similar problems. Your dedication to learning and improving is commendable! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -291,7 +320,7 @@ describe('', () => {
button().should('have.text', 'Choose a user');
});

it('should not show users list by default', () => {
it.skip('should not show users list by default', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is currently skipped. Ensure it is intentionally skipped or enable it if relevant.

users().eq(0).should('have.text', 'Leanne Graham')
users().eq(3).should('have.text', 'Patricia Lebsack')
users().eq(9).should('have.text', 'Clementina DuBuque')
it.skip('should have names in the list', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is currently skipped. Ensure it is intentionally skipped or enable it if relevant.

});

it('should close dropdown after selecting a user', () => {
it.skip('should close dropdown after selecting a user', () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is currently skipped. Ensure it is intentionally skipped or enable it if relevant.

@@ -861,7 +920,9 @@
describe('', () => {
beforeEach(() => {
cy.clock();
page.spyOn('**/comments?postId=2', 'post2Coments', { fixture: 'post2Comments' });
page.spyOn('**/comments?postId=2', 'post2Coments', {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error: post2Coments should be post2Comments.

Comment on lines +885 to +887
cy.intercept('**/comments?postId=1', { body: [] }).as(
'post1CommentsRequest',
);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extraneous comma at the end of the intercept setup. Remove it for cleaner code.

src/App.tsx Outdated

<Loader />
const [isError, setIsError] = useState(false);
const [isLoading, setIsLoadind] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error: setIsLoadind should be setIsLoading.

src/App.tsx Outdated
}

setPostSelected(null);
setIsLoadind(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error: setIsLoadind should be setIsLoading.

src/App.tsx Outdated
setIsError(true);
setPostsByUser([]);
} finally {
setIsLoadind(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error: setIsLoadind should be setIsLoading.

setIsLoading(false);
};

const validateform = () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typographical error: validateform should be validateForm to follow camelCase naming conventions.

Comment on lines 33 to 34
.catch(error => {
throw new Error(error);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing more informative error messages or handling specific error scenarios in the catch block to improve error handling.

Copy link

@BudnikOleksii BudnikOleksii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work 👍
Let's improve your solution slightly

src/App.tsx Outdated
Comment on lines 18 to 19
const [postsByUser, setPostsByUser] = useState<Post[]>([]);
const [postSelected, setPostSelected] = useState<Post | null>(null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userPosts and selectedPost sounds a bit better, the same as selectedUserId

src/App.tsx Outdated

setPostSelected(null);
setIsLoading(true);
const getPostsByUser = async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const getPostsByUser = async () => {
const getPostsByUserId = async (userId: string) => {

src/App.tsx Outdated
getPostsByUser();
}, [userSelectedId]);

const showMessageAboutNotPosts =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Boolean variables should start from is or has

src/App.tsx Outdated
<div className="tile is-child box is-success ">
<PostDetails />
<div
data-cy="Sidebar"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a Sidebar component

src/api/posts.ts Outdated
import { client } from '../utils/fetchClient';
import { Post } from '../types/Post';

const url = `/posts`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const url = `/posts`;
const ENDPOINTS = {
posts: '/posts',
};

What url is it?

data-cy="PostButton"
className={`button is-link ${openClassButton}`}
>
{currentPost?.id === post.id ? 'Close' : 'Open'}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You compare currentPost?.id === post.id twice, create a variable

Comment on lines 40 to 44
try {
setComments(prev => prev.filter(comment => comment.id !== commentId));
commentsService.deleteComment(commentId);
} catch (error) {
setIsError(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If you don't await the response you never catch an error so try/catch here doesn't make much sense
  • Also use one style for API requests try/catch or with then

Comment on lines 11 to 15
const [currentPost, setCurrentPost] = useState<PostUser | null>(null);

useEffect(() => {
setPostSelected(currentPost);
}, [currentPost, setPostSelected]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you store the selected post in two places? You should have one source of truth

Comment on lines +34 to +36
useEffect(() => {
setIsActive(false);
}, [setIsActive]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook here resets the isActive state to false whenever setIsActive changes. This might not be necessary and could lead to unexpected behavior if setIsActive is updated elsewhere. Consider whether this effect is needed.

Good point

Comment on lines 33 to 35
.catch(error => {
throw new Error(error);
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of this catch block? You just throw the same error

Copy link

@BudnikOleksii BudnikOleksii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Comment on lines +34 to +36
useEffect(() => {
setIsActive(false);
}, [setIsActive]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook here resets the isActive state to false whenever setIsActive changes. This might not be necessary and could lead to unexpected behavior if setIsActive is updated elsewhere. Consider whether this effect is needed.

Good point

Not fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants