Skip to content

Commit 0b01d9e

Browse files
authored
Render captions on posts
1 parent d01b645 commit 0b01d9e

File tree

3 files changed

+107
-27
lines changed

3 files changed

+107
-27
lines changed

frontend/src/features/posts/PostComponent/PostComponent.styles.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ export default createStyles((theme) => ({
1414
height: '100%',
1515
},
1616
likeCommentContainer: {
17-
padding: '14px',
17+
position: 'relative',
18+
left: -5,
19+
},
20+
captionText: {
21+
lineHeight: 1.2,
22+
},
23+
captionCreatorLink: {
24+
lineHeight: 0,
25+
},
26+
postBottomSection: {
27+
padding: 14,
28+
display: 'flex',
29+
flexDirection: 'column',
30+
gap: 5,
1831
},
1932
activeOpacityLight: {
2033
'&:active': {
@@ -25,9 +38,6 @@ export default createStyles((theme) => ({
2538
color: '#737373',
2639
fontWeight: 400,
2740
},
28-
createdContainer: {
29-
padding: '0 14px',
30-
},
3141
modal: {
3242
borderRadius: 10,
3343
width: '83%',

frontend/src/features/posts/PostComponent/PostComponent.tsx

+46-23
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function PostComponent({ post, setAlertText }: PostProps) {
3232
const isCurrentUserPostCreator = currentUsername === postCreator;
3333
const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);
3434
const [isDeleteConfirmModalOpen, setDeleteConfirmModalOpen] = useState(false);
35-
const { classes } = useStyles();
35+
const { classes, cx } = useStyles();
3636
const goBack = useGoBack();
3737
const [deletePost] = useDeletePostByIdMutation();
3838

@@ -168,28 +168,51 @@ function PostComponent({ post, setAlertText }: PostProps) {
168168
src={post.image.url}
169169
data-cy="post-image"
170170
/>
171-
<Group
172-
position="left"
173-
className={classes.likeCommentContainer}
174-
spacing="sm"
175-
>
176-
<IconHeart
177-
size={28}
178-
strokeWidth={1.5}
179-
color="black"
180-
className={classes.activeOpacityLight}
181-
/>
182-
<IconMessageCircle
183-
size={28}
184-
strokeWidth={1.5}
185-
color="black"
186-
className={classes.activeOpacityLight}
187-
/>
188-
</Group>
189-
<div className={classes.createdContainer}>
190-
<Text size="xs" className={classes.createdAt}>
191-
{getTimeSinceDate(new Date(post.createdAt))}
192-
</Text>
171+
<div className={classes.postBottomSection}>
172+
<Group
173+
position="left"
174+
className={classes.likeCommentContainer}
175+
spacing="sm"
176+
>
177+
<IconHeart
178+
size={28}
179+
strokeWidth={1.5}
180+
color="black"
181+
className={classes.activeOpacityLight}
182+
/>
183+
<IconMessageCircle
184+
size={28}
185+
strokeWidth={1.5}
186+
color="black"
187+
className={classes.activeOpacityLight}
188+
/>
189+
</Group>
190+
{
191+
post.caption && (
192+
<div>
193+
<Text
194+
weight={700}
195+
size="sm"
196+
className={cx(classes.activeOpacityLight, classes.captionCreatorLink)}
197+
component={Link}
198+
to={`/${postCreator}`}
199+
>
200+
{postCreator}
201+
</Text>
202+
<Text
203+
size="sm"
204+
className={classes.captionText}
205+
>
206+
{post.caption}
207+
</Text>
208+
</div>
209+
)
210+
}
211+
<div>
212+
<Text size="xs" className={classes.createdAt}>
213+
{getTimeSinceDate(new Date(post.createdAt))}
214+
</Text>
215+
</div>
193216
</div>
194217
</>
195218
);

frontend/src/test/int/viewingposts.test.tsx

+47
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,50 @@ test.only('post is viewable in the post view page', async () => {
161161
expect(postedImage).toBeVisible();
162162
});
163163
});
164+
165+
test.only('when a post has a caption, it is viewable in the post view page', async () => {
166+
await store.dispatch(apiSlice.endpoints.getUsers.initiate());
167+
const history = createBrowserHistory();
168+
history.push('/create/details', { croppedImage: testImage });
169+
170+
render(
171+
<HistoryRouter history={history}>
172+
<Providers>
173+
<App />
174+
</Providers>
175+
</HistoryRouter>,
176+
);
177+
178+
const user = userEvent.setup();
179+
const shareBtns = await screen.findAllByText(/share/i);
180+
const shareBtn = shareBtns[0];
181+
const textarea = screen.getByRole('textbox');
182+
183+
await user.type(textarea, 'This is a caption');
184+
await user.click(shareBtn);
185+
186+
await waitFor(() => {
187+
expect(history.location.pathname).toBe('/');
188+
});
189+
190+
// Navigate to user profile
191+
act(() => {
192+
history.push(`/${fakeUser.username}`);
193+
});
194+
195+
// simulating a page refresh
196+
await store.dispatch(apiSlice.endpoints.getUsers.initiate(undefined, { forceRefetch: true }));
197+
198+
await waitFor(async () => {
199+
const images = screen.getAllByRole('img');
200+
const postedImage = images.find((img) => img.getAttribute('src') === testImage);
201+
expect(postedImage).toBeDefined();
202+
203+
// going to the post view page
204+
await user.click(postedImage!);
205+
});
206+
207+
await waitFor(() => {
208+
expect(screen.getByText(/this is a caption/i)).toBeVisible();
209+
});
210+
});

0 commit comments

Comments
 (0)