Skip to content

Commit d3d6a00

Browse files
fix: reactions not being rendered correctly (#6330)
* fix: reactions not being rendered correctly * fix: revert plain unused adjustment * fix: lint * feat: created reactions unit test * fix: test e2e failing
1 parent 0411e11 commit d3d6a00

File tree

4 files changed

+93
-6
lines changed

4 files changed

+93
-6
lines changed

app/containers/markdown/components/Plain.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@ import { Text } from 'react-native';
33
import { Plain as PlainProps } from '@rocket.chat/message-parser';
44

55
import { useTheme } from '../../../theme';
6-
import usePreviewFormatText from '../../../lib/hooks/usePreviewFormatText';
76
import styles from '../styles';
87

98
interface IPlainProps {
109
value: PlainProps['value'];
1110
}
1211

1312
const Plain = ({ value }: IPlainProps): React.ReactElement => {
14-
const formattedText = usePreviewFormatText(value);
1513
const { colors } = useTheme();
1614
return (
1715
<Text accessibilityLabel={value} style={[styles.plainText, { color: colors.fontDefault }]}>
18-
{formattedText}
16+
{value}
1917
</Text>
2018
);
2119
};

app/containers/message/Emoji.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Emoji = React.memo(
1313
if (emoji) {
1414
return <CustomEmoji key={content} style={customEmojiStyle} emoji={emoji} />;
1515
}
16-
return <Text style={standardEmojiStyle}>{formatShortnameToUnicode(parsedContent)}</Text>;
16+
return <Text style={standardEmojiStyle}>{formatShortnameToUnicode(content)}</Text>;
1717
},
1818
() => true
1919
);
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import React, { useState } from 'react';
2+
import { Provider } from 'react-redux';
3+
import { render, fireEvent } from '@testing-library/react-native';
4+
5+
import Reactions from './Reactions';
6+
import MessageContext from './Context';
7+
import { setUser } from '../../actions/login';
8+
import { mockedStore } from '../../reducers/mockedStore';
9+
import { IReaction } from '../../definitions';
10+
11+
const initialMockedStoreState = () => {
12+
mockedStore.dispatch(
13+
setUser({
14+
settings: {
15+
preferences: {
16+
convertAsciiEmoji: true
17+
}
18+
}
19+
})
20+
);
21+
};
22+
23+
initialMockedStoreState();
24+
25+
const TestWrapper = ({ initialReactions }: { initialReactions: IReaction[] }) => {
26+
const [reactions, setReactions] = useState<IReaction[]>(initialReactions);
27+
const handleReactionPress = (emoji: string) => {
28+
setReactions(prev => prev.filter(r => r.emoji !== emoji));
29+
};
30+
31+
return (
32+
<Provider store={mockedStore}>
33+
<MessageContext.Provider
34+
value={{
35+
user: { username: 'john' },
36+
reactionInit: jest.fn(),
37+
onReactionPress: handleReactionPress,
38+
onReactionLongPress: jest.fn()
39+
}}>
40+
<Reactions reactions={reactions} getCustomEmoji={getCustomEmoji} />
41+
</MessageContext.Provider>
42+
</Provider>
43+
);
44+
};
45+
46+
const getCustomEmoji = jest.fn();
47+
48+
it('renders all reactions and AddReaction button', () => {
49+
const reactions: IReaction[] = [
50+
{ _id: '1', emoji: '👍', usernames: ['john', 'alice'], names: [] },
51+
{ _id: '2', emoji: '😂', usernames: ['bob'], names: [] }
52+
];
53+
54+
const { getByTestId } = render(<TestWrapper initialReactions={reactions} />);
55+
56+
expect(getByTestId('message-reaction-👍')).toBeTruthy();
57+
expect(getByTestId('message-reaction-😂')).toBeTruthy();
58+
expect(getByTestId('message-add-reaction')).toBeTruthy();
59+
});
60+
61+
it('should render unicode emoji reaction', () => {
62+
const reactions = [{ _id: '1', emoji: ':)', usernames: ['john', 'alice'], names: [] }];
63+
const { getByTestId } = render(<TestWrapper initialReactions={reactions} />);
64+
65+
expect(getByTestId('message-reaction-:)')).toBeTruthy();
66+
expect(getByTestId('message-add-reaction')).toBeTruthy();
67+
});
68+
69+
it('should render custom emoji reaction', () => {
70+
const reactions = [{ _id: '1', emoji: ':aaaaa:', usernames: ['john', 'alice'], names: [] }];
71+
const { getByTestId } = render(<TestWrapper initialReactions={reactions} />);
72+
73+
expect(getByTestId('message-reaction-:aaaaa:')).toBeTruthy();
74+
expect(getByTestId('message-add-reaction')).toBeTruthy();
75+
});
76+
77+
it('should remove reaction', () => {
78+
const reactions = [
79+
{ _id: '1', emoji: ':thumbsup:', usernames: ['john'], names: [] },
80+
{ _id: '1', emoji: ':heart_eyes:', usernames: ['john', 'alice'], names: [] }
81+
];
82+
const { getByTestId, queryByTestId } = render(<TestWrapper initialReactions={reactions} />);
83+
84+
expect(getByTestId('message-reaction-:thumbsup:')).toBeTruthy();
85+
expect(getByTestId('message-reaction-:heart_eyes:')).toBeTruthy();
86+
fireEvent.press(getByTestId('message-reaction-:thumbsup:'));
87+
expect(queryByTestId('message-reaction-:thumbsup:')).toBeNull();
88+
expect(getByTestId('message-add-reaction')).toBeTruthy();
89+
});

e2e/tests/assorted/17-userpreferences.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('User Preferences screen', () => {
6868
.withTimeout(2000);
6969
await expect(element(by.id('sidebar-chats'))).toBeVisible();
7070
await element(by.id('sidebar-chats')).tap();
71-
await waitFor(element(by.text(`${otherUser.username}::(`)))
71+
await waitFor(element(by.text(`${otherUser.username}: :(`)))
7272
.toBeVisible()
7373
.withTimeout(2000);
7474
await navigateToRoom(room);
@@ -93,7 +93,7 @@ describe('User Preferences screen', () => {
9393
.withTimeout(2000);
9494
await expect(element(by.id('sidebar-chats'))).toBeVisible();
9595
await element(by.id('sidebar-chats')).tap();
96-
await waitFor(element(by.text(`${otherUser.name}:😞`)))
96+
await waitFor(element(by.text(`${otherUser.name}: 😞`)))
9797
.toBeVisible()
9898
.withTimeout(2000);
9999
await navigateToRoom(room);

0 commit comments

Comments
 (0)