Skip to content

Commit e4a3b7c

Browse files
fix: empty thread preview (RocketChat#36527)
1 parent 8942187 commit e4a3b7c

5 files changed

Lines changed: 137 additions & 1 deletion

File tree

.changeset/pretty-geckos-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes an issue that caused some types of messages to generate an empty thread preview
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { mockAppRoot } from '@rocket.chat/mock-providers';
2+
import { composeStories } from '@storybook/react';
3+
import { render, screen } from '@testing-library/react';
4+
import { axe } from 'jest-axe';
5+
6+
import * as stories from './ThreadMessagePreviewBody.stories';
7+
8+
const { Default } = composeStories(stories);
9+
10+
const testCases = Object.values(composeStories(stories)).map((Story) => [Story.storyName || 'Story', Story]);
11+
12+
jest.mock('../../../../lib/utils/fireGlobalEvent', () => ({
13+
fireGlobalEvent: jest.fn(),
14+
}));
15+
16+
jest.mock('../../../../views/room/hooks/useGoToRoom', () => ({
17+
useGoToRoom: jest.fn(),
18+
}));
19+
20+
test.each(testCases)(`renders ThreadMessagePreviewBody without crashing`, async (_storyname, Story) => {
21+
const view = render(<Story />, { wrapper: mockAppRoot().build() });
22+
23+
expect(view.baseElement).toMatchSnapshot();
24+
});
25+
26+
test.each(testCases)('ThreadMessagePreviewBody should have no a11y violations', async (_storyname, Story) => {
27+
const { container } = render(<Story />, { wrapper: mockAppRoot().build() });
28+
29+
const results = await axe(container);
30+
31+
expect(results).toHaveNoViolations();
32+
});
33+
34+
it('should not show an empty thread preview', async () => {
35+
const { container } = render(
36+
<Default
37+
message={{
38+
_id: 'message-id',
39+
ts: new Date(),
40+
msg: 'http://localhost:3000/group/ds?msg=ZoX9pDowqNb4BiWxf',
41+
md: [
42+
{
43+
type: 'PARAGRAPH',
44+
value: [
45+
{
46+
type: 'PLAIN_TEXT',
47+
value: 'message attachment text quote',
48+
},
49+
],
50+
},
51+
],
52+
attachments: [
53+
{
54+
text: 'message attachment text quote',
55+
md: [
56+
{
57+
type: 'PARAGRAPH',
58+
value: [
59+
{
60+
type: 'PLAIN_TEXT',
61+
value: 'message attachment text quote',
62+
},
63+
],
64+
},
65+
],
66+
message_link: 'http://localhost:3000/group/ds?msg=ZoX9pDowqNb4BiWxf',
67+
author_name: 'b',
68+
author_icon: '/avatar/b',
69+
attachments: [],
70+
ts: new Date('2025-07-24T18:05:45.339Z'),
71+
},
72+
],
73+
u: {
74+
_id: 'user-id',
75+
username: 'username',
76+
},
77+
rid: 'room-id',
78+
_updatedAt: new Date(),
79+
}}
80+
/>,
81+
{ wrapper: mockAppRoot().build() },
82+
);
83+
expect(container).toMatchSnapshot();
84+
const text = screen.getByText('http://localhost:3000/group/ds?msg=ZoX9pDowqNb4BiWxf');
85+
86+
expect(text).toBeInTheDocument;
87+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { mockAppRoot } from '@rocket.chat/mock-providers';
2+
import type { Meta, StoryFn } from '@storybook/react';
3+
import type { ComponentProps } from 'react';
4+
5+
import ThreadMessagePreviewBody from './ThreadMessagePreviewBody';
6+
7+
export default {
8+
title: 'Components/ThreadMessagePreviewBody',
9+
component: ThreadMessagePreviewBody,
10+
parameters: {
11+
layout: 'fullscreen',
12+
},
13+
decorators: [mockAppRoot().withSetting('UI_Use_Real_Name', true).withJohnDoe().buildStoryDecorator()],
14+
args: {
15+
message: {
16+
_id: 'message-id',
17+
ts: new Date(),
18+
msg: 'This is a message',
19+
u: {
20+
_id: 'user-id',
21+
username: 'username',
22+
},
23+
rid: 'room-id',
24+
_updatedAt: new Date(),
25+
},
26+
},
27+
} satisfies Meta<typeof ThreadMessagePreviewBody>;
28+
29+
export const Default: StoryFn<ComponentProps<typeof ThreadMessagePreviewBody>> = (args) => <ThreadMessagePreviewBody {...args} />;

apps/meteor/client/components/message/variants/threadPreview/ThreadMessagePreviewBody.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const ThreadMessagePreviewBody = ({ message }: ThreadMessagePreviewBodyProps): R
3030
return <>{t('Message_with_attachment')}</>;
3131
}
3232
if (!isEncryptedMessage || message.e2e === 'done') {
33-
return mdTokens ? (
33+
return mdTokens?.length ? (
3434
<GazzodownText>
3535
<PreviewMarkup tokens={mdTokens} />
3636
</GazzodownText>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`renders ThreadMessagePreviewBody without crashing 1`] = `
4+
<body>
5+
<div>
6+
This is a message
7+
</div>
8+
</body>
9+
`;
10+
11+
exports[`should not show an empty thread preview 1`] = `
12+
<div>
13+
http://localhost:3000/group/ds?msg=ZoX9pDowqNb4BiWxf
14+
</div>
15+
`;

0 commit comments

Comments
 (0)