We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Code Review Feedback
Code Review Feedback
Sort by
recency
|
51 Discussions
|
Please Login in order to post a comment
i have done tis and for manual testing its working perfectly fine idk whats the issue none of the test cases are passing
The only way I could get all tests to pass was as follows:
Create a component which will represent a specific test called Card, for example. Into this you pass props for the name of the test, Readability, Performance etc. and a prop for an index.
In the Card component create two states, one to handle up votes and another down votes. These hold the number of votes, a single digit.
Also in the Card create onClick functions for each up and down vote button. These functions simply update the state for the up and down votes by adding one on each click.
In the main component, Feedback, import the Card component. Then create an array for the test titles. Map over this array, putting in a title into the Card component as a prop along with the index of the title from the array. Thus you create a Card component for each of the test titles.
You also need to ensure the test ids in the Card component are dynamic by using the index as a unique reference.
Overall, this approach is simpler and more elegant. It also avoids complex coding in the map function.
Why is my implementation not seen as correct in any way?
The functonality works as expected, it even for some reason says I'm not passing a key to the mapped child but I am?
data-testid should be dynamic it should not always 0, they should be 0,1,2,3,4,5 based on index in map
It seems it was the way I was updating the state, I was basically adding a new value to the data array everytime I upvote or downvote.
So chaning it to this seems to have worked and it now passes all the tests.
setData(data.map(childItem => childItem.id === item.id ? { ...childItem, upVotes: childItem.upVotes + 1 } : childItem));
Also to pass the tests, data-testid should be dynamic like {
upvote-btn-${index}
}.The simplest solution is to pull the card into another component.
This makes each card hold the simplest possible state.
Be advised, this is not ready for easy state upload or anything.
Since this is a training excercise, we optimize for code simplicity.
I can't solve the problem User Action 3 User clicks "Vote" for Security and Documentation multiple times. 4. The number of votes for Security is Sprunki Retake shown as 2 and Documentation is shown as 3. please help me!
assuming that you've set up this state with:
const [upvotes, setUpvotes] = useState(0);
your function handling the click should call:
setUpvotes(upvotes+1)
while your upvotes display should just display
{upvotes}
This should trigger state setting and rerender immediatelly upon click.