Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Check if messsage.replies exist on new message template #26652

Merged
merged 12 commits into from
Sep 13, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ const MessageContent: FC<{
<ThreadMetric
openThread={openThread(message._id)}
counter={message.tcount}
following={Boolean(mineUid && message?.replies.indexOf(mineUid) > -1)}
following={Boolean(mineUid && message?.replies?.indexOf(mineUid) > -1)}
mid={message._id}
rid={message.rid}
lm={message.tlm}
unread={unread}
mention={mention}
all={all}
participants={message?.replies.length}
participants={message?.replies?.length}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { render, screen } from '@testing-library/react';
import { expect } from 'chai';
import proxyquire from 'proxyquire';
import React from 'react';

const date = new Date('2021-10-27T00:00:00.000Z');
const baseMessage = {
ts: date,
u: {
_id: 'userId',
name: 'userName',
username: 'userName',
},
msg: 'message',
rid: 'roomId',
_id: 'messageId',
_updatedAt: date,
urls: [],
};
const MessageContent = proxyquire.noCallThru().load('../../../../../../client/views/room/MessageList/components/MessageContent', {
'../../../../lib/presence': {
UserPresence: () => '',
},
'../../contexts/MessageContext': {
useMessageActions: () => ({
actions: {
openRoom: () => '',
openThread: () => () => '',
replyBroadcast: () => '',
},
}),
useMessageOembedIsEnabled: () => '',
useMessageRunActionLink: () => '',
},

'../../contexts/MessageListContext': {
useTranslateAttachments: () => '',
useMessageListShowReadReceipt: () => '',
},
'../../../../hooks/useUserData': {
useUserData: () => '',
},
'../../../blocks/MessageBlock': () => '',
'./MessageContentBody': () => baseMessage.msg,
}).default;

describe('MessageContent', () => {
it('should render the message when exists', () => {
render(<MessageContent message={baseMessage} sequential={false} id={''} />);

expect(screen.getByText(baseMessage.msg)).to.exist;
});

it('should render the message when replies is undefined', () => {
render(<MessageContent message={{ ...baseMessage, replies: undefined, tcount: 0, tlm: date }} sequential={false} id={''} />);

expect(screen.getByText(baseMessage.msg)).to.exist;
expect(screen.getByTitle('Replies')).to.include.text('0');
});
});