-
Notifications
You must be signed in to change notification settings - Fork 398
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
Do not render report flag for reviews by the current user #6620
Conversation
Codecov Report
@@ Coverage Diff @@
## master mozilla/addons-frontend#6620 +/- ##
==========================================
+ Coverage 97.84% 97.84% +<.01%
==========================================
Files 240 241 +1
Lines 6549 6553 +4
Branches 1242 1243 +1
==========================================
+ Hits 6408 6412 +4
Misses 126 126
Partials 15 15
Continue to review full report at Codecov.
|
@@ -562,11 +569,12 @@ describe(__filename, () => { | |||
}); | |||
|
|||
it('lets you flag a developer reply', () => { | |||
const { reply } = _setReviewReply(); | |||
const root = renderReply({ reply }); | |||
const review = createReviewAndSignInAsUnrelatedUser(); |
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.
This test was checking a developer's reply to an existing review. I think I changed the logic behind it - would appreciate feedback.
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.
This test was checking a developer's reply to an existing review. I think I changed the logic behind it - would appreciate feedback.
Why did you need to change the test? I put it back to how it was and it passed for me. Maybe it was related to not being signed in?
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.
This is a good start, thanks @seanprashad, but I think we only want to remove the "Flag" option on the User Profile screen, and not on every screen. I had a discussion with @kumar303 about this awhile ago, but I cannot find the issue where we discussed it.
He felt that we should keep the "Flag" menu, even for reviews by the same user, on the Review Listing screen, but it was fine to remove it from the User Profile screen.
@kumar303 Can you confirm that is what we should be doing for this issue?
I think the direction of this patch is good -- hiding the flag menu for all screens. I'd rather implement this feature consistently rather than just for the user profile page. I personally don't like hidden UI controls because it can be confusing to know what state you're in but everyone else argued against that so I concede 😁 |
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.
Thanks @seanprashad ! This mostly looks good. I have one change request.
@@ -481,7 +481,8 @@ export class AddonReviewCardBase extends React.Component<InternalProps> { | |||
</a> | |||
) : null} | |||
|
|||
{flaggable && review ? ( | |||
{/* Do not render the "flag" button for replies made by the current user */} | |||
{flaggable && review && siteUser && siteUser.id !== review.userId ? ( |
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.
If the user is signed out, the Flag link should always be visible. Otherwise, if someone wants to flag a review, they might not know that they have to sign in first.
This is what it looks like (there is actually a style regression that I will fix right now! https://github.com/mozilla/addons-frontend/issues/6656)
This test is responsible for making sure that the "flag" button is hidden for replies made by the current user.
These tests are affected by the previous commit, which hides the "flag" button for reviews made by the current user.
@kumar303 I've updated the logic to always render the flag button if the user isn't logged in: |
We should always render the "flag" button if a user is not authenticated because users should know that they have to sign in first before flagging a review.
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.
Thanks for the fix-ups. I have a few more change requests.
@@ -481,7 +486,7 @@ export class AddonReviewCardBase extends React.Component<InternalProps> { | |||
</a> | |||
) : null} | |||
|
|||
{flaggable && review ? ( | |||
{flaggable && review && showFlagButton ? ( |
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.
I liked how simple this was in your first patch. It was a lot easier to read. What about this?
{flaggable && review && showFlagButton ? ( | |
{flaggable && review && (!siteUser || siteUser.id !== review.userId) ? ( |
@@ -481,7 +486,7 @@ export class AddonReviewCardBase extends React.Component<InternalProps> { | |||
</a> | |||
) : null} | |||
|
|||
{flaggable && review ? ( | |||
{flaggable && review && showFlagButton ? ( |
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.
You also need to add a test that makes sure the flag button is not hidden when the user is signed out. After writing the test, you can comment out the part that allowed non-signed in users to see the flag link; the test should fail. This helps you know that the test is working.
@@ -562,11 +569,12 @@ describe(__filename, () => { | |||
}); | |||
|
|||
it('lets you flag a developer reply', () => { | |||
const { reply } = _setReviewReply(); | |||
const root = renderReply({ reply }); | |||
const review = createReviewAndSignInAsUnrelatedUser(); |
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.
This test was checking a developer's reply to an existing review. I think I changed the logic behind it - would appreciate feedback.
Why did you need to change the test? I put it back to how it was and it passed for me. Maybe it was related to not being signed in?
@@ -547,7 +554,7 @@ describe(__filename, () => { | |||
}); | |||
|
|||
it('lets you flag a review', () => { | |||
const review = _setReview(fakeReview); |
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.
I think you can put this back now, too. The test passes for me.
@@ -423,6 +423,11 @@ export class AddonReviewCardBase extends React.Component<InternalProps> { | |||
(review.userId === siteUser.id || | |||
(this.isReply() && this.siteUserCanManageReplies())); | |||
|
|||
/* Do not render the "flag" button for reviews made by the current user */ |
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.
Prefix comments with //
(double slashes) when they don't need to span multiple lines.
These were initially changed as the new implementation hid the flag button for users who weren't logged in. We can now revert these as we display the flag button for all replies that do not belong to the current user, regardless if they are signed in or not.
Thanks for the great feedback @kumar303! ✌🏽I've reverted the other tests back and added a new test to check for the flag button when the user wasn't authenticated. I think this should be good to 🚢 Edit: Not sure if it's just me, but I can't reply to the third comment you made for your review - there's no textbox. I don't think I've seen this behaviour before: |
It's not just you. Github is buggy. I copied/pasted the quote of what I was replying to because I had actually pressed the reply button on your last comment and I knew Github is buggy around this behavior (for some reason). I guess they broke it further. |
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.
Thanks for the quick fixes. Here is some more feedback.
expect(renderControls(root).find(FlagReviewMenu)).toHaveLength(1); | ||
}); | ||
|
||
it('hides the flag button if you wrote the review', () => { |
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.
When I undo your patch, this test should fail but it does not. Try to make it fail.
Here's how I undid your patch:
diff --git a/src/amo/components/AddonReviewCard/index.js b/src/amo/components/AddonReviewCard/index.js
index 13013647a..ff535434a 100644
--- a/src/amo/components/AddonReviewCard/index.js
+++ b/src/amo/components/AddonReviewCard/index.js
@@ -482,7 +482,7 @@ export class AddonReviewCardBase extends React.Component<InternalProps> {
) : null}
{/* Do not render the "flag" button for reviews made by the current user */}
- {flaggable && review && (!siteUser || siteUser.id !== review.userId) ? (
+ {flaggable && review ? (
<FlagReviewMenu
isDeveloperReply={this.isReply()}
openerClass="AddonReviewCard-control"
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.
Ok - here's how I think we should proceed:
The current test:
- Signs the user in
- Creates a review
- Checks that the flag button isn't rendered
The ideal test:
- Signs the user in
- Creates a review
- Checks that the flag button isn't rendered
- Signs the user out
- Checks that the flag button is rendered
Edit: This logout
is just what we need!
@@ -576,6 +583,21 @@ describe(__filename, () => { | |||
expect(root.find(FlagReviewMenu)).toHaveLength(0); | |||
}); | |||
|
|||
it('renders the flag button when not signed in', () => { |
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.
Actually, I just realized that you don't need this test because we already have one:
it('lets you flag a review', () => { |
However, I would suggest changing the spec from 'lets you flag a review' to 'shows FlagReviewMenu when signed out'
In addition to signing in the user and ensuring the "flag" button is hidden for their own replies, the test now signs the user out to ensure that all flag buttons are shown. This workflow allows unauthenticated users to see that flagging a review is possible, only after signing in.
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.
The test fails now without your patch (good!) but it needs some tweaks.
|
||
expect(renderControls(root).find(FlagReviewMenu)).toHaveLength(0); | ||
|
||
store.dispatch(logOutUser()); |
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.
You can delete this and the assertion below because it's a duplication of the logic covered by this test. In other words, signing out produces the exact same state as not signing in to begin with.
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.
✅ All done
it('hides the flag button if you wrote the review', () => { | ||
const originalReviewId = 123; | ||
const review = signInAndDispatchSavedReview({ | ||
siteUserId: originalReviewId, |
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.
This variable name is confusing but I see what you are trying to do. You are letting the helper take over to set siteUserId
and reviewUserId
to the same value. Instead of letting the helper do this implicitly, your test should explicitly set these both to the same value so that the intention is clear.
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.
Yeah, I didn't want to introduce another helper that wrapped the signInAndDispatchSavedReview()
helper so I just used it directly. I've updated the variable naming to siteUserId
so it hopefully helps us recognize that this is an authenticated user.
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.
This looks great. Thanks for all the quick turnarounds.
Fixes mozilla/addons#12433: "Flag" should be removed from the profile page
This PR prevents the "flag" button from being rendered for reviews made by the current user. Essentially, if Sean leaves a review, he should not be allowed to flag his own comment.
Before:
After: