restore low_score comment state
This commit is contained in:
@@ -104,16 +104,4 @@ describe('<CommentVote />', () => {
|
||||
expect(screen.getByTitle('Vote up')).toBeVisible();
|
||||
expect(screen.getByTitle('Vote up')).not.toBeDisabled();
|
||||
});
|
||||
|
||||
it('should disable downvote ability when `low_score` is reached', async () => {
|
||||
StaticStore.config.low_score = -4;
|
||||
jest.spyOn(api, 'putCommentVote').mockImplementation(jest.fn(async () => ({ id: '1', score: -4 })));
|
||||
render(<CommentVotes id="1" vote={0} votes={-3} controversy={0} />);
|
||||
expect(screen.getByTitle('Vote down')).not.toBeDisabled();
|
||||
fireEvent(screen.getByTitle('Vote down'), new Event('click'));
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTitle('Vote down')).toBeDisabled();
|
||||
expect(screen.getByTitle('Vote up')).toBeDisabled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,11 +44,10 @@ export function CommentVotes({ id, votes, vote, disabled, controversy = 0 }: Pro
|
||||
}
|
||||
}
|
||||
|
||||
const lowScore = StaticStore.config.low_score === votes;
|
||||
const positiveScore = StaticStore.config.positive_score;
|
||||
const isUpvoted = vote === 1;
|
||||
const isDownvoted = vote === -1;
|
||||
const value = loadingState?.votes ?? votes;
|
||||
const isPositiveScore = StaticStore.config.positive_score && value > -1;
|
||||
|
||||
return (
|
||||
<span className={clsx(styles.root, disabled && styles.rootDisabled)}>
|
||||
@@ -58,7 +57,7 @@ export function CommentVotes({ id, votes, vote, disabled, controversy = 0 }: Pro
|
||||
onClick={handleClick}
|
||||
data-value={-1}
|
||||
title={intl.formatMessage(messages.downvote)}
|
||||
disabled={lowScore || loadingState !== null || isDownvoted || (positiveScore && value > -1)}
|
||||
disabled={loadingState !== null || isDownvoted || isPositiveScore}
|
||||
>
|
||||
<ArrowIcon className={styles.downVoteIcon} />
|
||||
</button>
|
||||
|
||||
@@ -326,6 +326,14 @@ export class Comment extends Component<CommentProps, State> {
|
||||
const defaultMods = {
|
||||
disabled: props.disabled,
|
||||
pinned: props.data.pin,
|
||||
// TODO: we also have critical_score, so we need to collapse comments with it in future
|
||||
useless:
|
||||
!!props.isUserBanned ||
|
||||
!!props.data.delete ||
|
||||
(props.view !== 'preview' &&
|
||||
props.data.score < StaticStore.config.low_score &&
|
||||
!props.data.pin &&
|
||||
!props.disabled),
|
||||
// TODO: add default view mod or don't?
|
||||
guest: isGuest,
|
||||
view: props.view === 'main' || props.view === 'pinned' ? props.data.user.admin && 'admin' : props.view,
|
||||
|
||||
Reference in New Issue
Block a user