diff --git a/apps/meteor/client/views/room/MessageList/components/MessageContent.tsx b/apps/meteor/client/views/room/MessageList/components/MessageContent.tsx index 1e4b10ff67b0..94dbe18aa418 100644 --- a/apps/meteor/client/views/room/MessageList/components/MessageContent.tsx +++ b/apps/meteor/client/views/room/MessageList/components/MessageContent.tsx @@ -87,14 +87,14 @@ const MessageContent: FC<{ -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} /> )} diff --git a/apps/meteor/tests/unit/client/views/room/MessageList/MessageContent.spec.tsx b/apps/meteor/tests/unit/client/views/room/MessageList/MessageContent.spec.tsx new file mode 100644 index 000000000000..8715f92d16b5 --- /dev/null +++ b/apps/meteor/tests/unit/client/views/room/MessageList/MessageContent.spec.tsx @@ -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(); + + expect(screen.getByText(baseMessage.msg)).to.exist; + }); + + it('should render the message when replies is undefined', () => { + render(); + + expect(screen.getByText(baseMessage.msg)).to.exist; + expect(screen.getByTitle('Replies')).to.include.text('0'); + }); +});