From 81ca2036b7643e8b2f1221901484d2043fa013d9 Mon Sep 17 00:00:00 2001 From: idoshamun Date: Sun, 24 May 2026 11:41:47 +0000 Subject: [PATCH 1/2] fix: fall back to shared post title in ShareBar (ENG-1532) For shared posts with no title, the post sidebar share buttons were passing an undefined description to Twitter/social share links. Fall back to the referenced post's title so the share text is populated. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../shared/src/components/ShareBar.spec.tsx | 25 ++++++++++++++++--- packages/shared/src/components/ShareBar.tsx | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/shared/src/components/ShareBar.spec.tsx b/packages/shared/src/components/ShareBar.spec.tsx index 010c6b341cd..a2bc74f376c 100644 --- a/packages/shared/src/components/ShareBar.spec.tsx +++ b/packages/shared/src/components/ShareBar.spec.tsx @@ -5,11 +5,11 @@ import React from 'react'; import nock from 'nock'; import { useRouter } from 'next/router'; import ShareBar from './ShareBar'; -import Post from '../../__tests__/fixture/post'; +import Post, { sharePost } from '../../__tests__/fixture/post'; import { AuthContextProvider } from '../contexts/AuthContext'; import loggedUser from '../../__tests__/fixture/loggedUser'; import { generateTestSquad } from '../../__tests__/fixture/squads'; -import { getFacebookShareLink } from '../lib/share'; +import { getFacebookShareLink, getTwitterShareLink } from '../lib/share'; import { LazyModalElement } from './modals/LazyModalElement'; import { NotificationsContextProvider } from '../contexts/NotificationsContext'; @@ -50,6 +50,7 @@ const manySquads = Array.from({ length: 5 }, (_, index) => const renderComponent = ( loggedIn = true, customSquads: typeof squads = squads, + post = defaultPost, ): RenderResult => { const client = new QueryClient(); @@ -66,7 +67,7 @@ const renderComponent = ( > - + , @@ -137,6 +138,24 @@ describe('ShareBar Test Suite:', () => { }); }); + it('should fall back to shared post title on Twitter share when shared post has no title', async () => { + const sharedPostWithoutTitle = { ...sharePost, title: undefined }; + renderComponent(true, squads, sharedPostWithoutTitle); + const btn = await screen.findByTestId('social-share-X'); + + fireEvent.click(btn); + + await waitFor(() => { + expect(mockWindowOpen).toHaveBeenCalledWith( + getTwitterShareLink( + sharedPostWithoutTitle.commentsPermalink, + sharePost.sharedPost!.title, + ), + '_blank', + ); + }); + }); + it('should render the copy link button and copy link to clipboard', async () => { renderComponent(); const btn = await screen.findByTestId('social-share-Copy link'); diff --git a/packages/shared/src/components/ShareBar.tsx b/packages/shared/src/components/ShareBar.tsx index ae4d342ae6c..6b9461f11cf 100644 --- a/packages/shared/src/components/ShareBar.tsx +++ b/packages/shared/src/components/ShareBar.tsx @@ -65,7 +65,7 @@ export default function ShareBar({ post }: ShareBarProps): ReactElement { const shareLink = getShareLink({ provider, link: shortLink, - text: post?.title, + text: post?.title || post?.sharedPost?.title, }); window.open(shareLink, '_blank'); }; From ae8a7e1ed505ac8517a52e99b174be6b54fbd3e4 Mon Sep 17 00:00:00 2001 From: idoshamun Date: Sun, 24 May 2026 11:46:26 +0000 Subject: [PATCH 2/2] chore: simplify ShareBar Twitter fallback test Reference the test-local post in both setup and assertion so the test reads top-to-bottom without jumping back to the fixture. Co-Authored-By: Claude Opus 4.7 (1M context) --- packages/shared/src/components/ShareBar.spec.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/shared/src/components/ShareBar.spec.tsx b/packages/shared/src/components/ShareBar.spec.tsx index a2bc74f376c..275c4e34b4c 100644 --- a/packages/shared/src/components/ShareBar.spec.tsx +++ b/packages/shared/src/components/ShareBar.spec.tsx @@ -139,18 +139,14 @@ describe('ShareBar Test Suite:', () => { }); it('should fall back to shared post title on Twitter share when shared post has no title', async () => { - const sharedPostWithoutTitle = { ...sharePost, title: undefined }; - renderComponent(true, squads, sharedPostWithoutTitle); - const btn = await screen.findByTestId('social-share-X'); + const post = { ...sharePost, title: undefined }; + renderComponent(true, squads, post); - fireEvent.click(btn); + fireEvent.click(await screen.findByTestId('social-share-X')); await waitFor(() => { expect(mockWindowOpen).toHaveBeenCalledWith( - getTwitterShareLink( - sharedPostWithoutTitle.commentsPermalink, - sharePost.sharedPost!.title, - ), + getTwitterShareLink(post.commentsPermalink, post.sharedPost!.title), '_blank', ); });