From c12dc13b8b880eabc7b433891941b1cf74bfb18d Mon Sep 17 00:00:00 2001 From: Chris Bongers Date: Thu, 23 Jul 2026 16:21:31 +0200 Subject: [PATCH] fix(sentiment): hide sources with no comments --- .../CommunitySentimentBreakdown.spec.tsx | 52 +++++++++++++++++-- .../focus/CommunitySentimentBreakdown.tsx | 30 +++++------ 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/packages/shared/src/components/post/focus/CommunitySentimentBreakdown.spec.tsx b/packages/shared/src/components/post/focus/CommunitySentimentBreakdown.spec.tsx index 179c1b14c4..d404e4cddd 100644 --- a/packages/shared/src/components/post/focus/CommunitySentimentBreakdown.spec.tsx +++ b/packages/shared/src/components/post/focus/CommunitySentimentBreakdown.spec.tsx @@ -33,12 +33,12 @@ const createData = ( }); describe('CommunitySentimentBreakdown', () => { - it('hides the source lean and shows concise empty copy when a source has no comments', () => { + it('does not render a source row when that source has no comments', () => { render(); - expect(screen.getByText('Hacker News')).toBeInTheDocument(); + expect(screen.queryByText('Hacker News')).not.toBeInTheDocument(); expect(screen.queryByText('Mixed')).not.toBeInTheDocument(); - expect(screen.getByText('No comments yet')).toBeInTheDocument(); + expect(screen.queryByText('No comments yet')).not.toBeInTheDocument(); expect( screen.queryByText( 'No comments were present, so no community signal is available.', @@ -46,6 +46,52 @@ describe('CommunitySentimentBreakdown', () => { ).not.toBeInTheDocument(); }); + it('keeps the rest of the breakdown when one source has no comments', () => { + render( + , + ); + + expect( + screen.getByText('Developers like the practical examples.'), + ).toBeInTheDocument(); + expect(screen.queryByText('Hacker News')).not.toBeInTheDocument(); + expect(screen.getByText('Lobsters')).toBeInTheDocument(); + expect(screen.getByText('Skeptical')).toBeInTheDocument(); + expect( + screen.getByText('Developers want stronger benchmarks.'), + ).toBeInTheDocument(); + }); + it('keeps the source lean when comments are available', () => { render( @@ -176,16 +174,14 @@ const SourceRow = ({ > {label} - {!hasNoComments && ( - - {chip.label} - - )} + + {chip.label} + {discussion && ( - {displayNote} + {note} {/* Always reserve the link slot so rows without a link stay aligned. */} @@ -257,6 +253,10 @@ export const CommunitySentimentBreakdown = ({ discussion, ]), ); + const sourcesWithComments = bySource.filter((item) => { + const discussion = discussionByProvider.get(normalizeProvider(item.source)); + return discussion?.commentsCount !== 0; + }); return (
@@ -271,11 +271,11 @@ export const CommunitySentimentBreakdown = ({
)} - {bySource.length > 0 && ( + {sourcesWithComments.length > 0 && (
By community
- {bySource.map((item) => ( + {sourcesWithComments.map((item) => (