Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/shared/src/components/ShareBar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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();

Expand All @@ -66,7 +67,7 @@ const renderComponent = (
>
<NotificationsContextProvider>
<LazyModalElement />
<ShareBar post={defaultPost} />
<ShareBar post={post} />
</NotificationsContextProvider>
</AuthContextProvider>
</QueryClientProvider>,
Expand Down Expand Up @@ -137,6 +138,20 @@ describe('ShareBar Test Suite:', () => {
});
});

it('should fall back to shared post title on Twitter share when shared post has no title', async () => {
const post = { ...sharePost, title: undefined };
renderComponent(true, squads, post);

fireEvent.click(await screen.findByTestId('social-share-X'));

await waitFor(() => {
expect(mockWindowOpen).toHaveBeenCalledWith(
getTwitterShareLink(post.commentsPermalink, post.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');
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/components/ShareBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down
Loading