diff --git a/app/components/post_body/__snapshots__/system_message_helpers.test.js.snap b/app/components/post_body/__snapshots__/system_message_helpers.test.js.snap index 1c221a136..237c84090 100644 --- a/app/components/post_body/__snapshots__/system_message_helpers.test.js.snap +++ b/app/components/post_body/__snapshots__/system_message_helpers.test.js.snap @@ -49,3 +49,5 @@ exports[`renderSystemMessage uses renderer for unarchived channel 1`] = ` value="{username} unarchived the channel" /> `; + +exports[`renderSystemMessage uses renderer for unarchived channel 2`] = `null`; diff --git a/app/components/post_body/system_message_helpers.js b/app/components/post_body/system_message_helpers.js index 1ad866339..02ff48d34 100644 --- a/app/components/post_body/system_message_helpers.js +++ b/app/components/post_body/system_message_helpers.js @@ -147,6 +147,9 @@ const renderArchivedMessage = (postBodyProps, styles, intl) => { const renderUnarchivedMessage = (postBodyProps, styles, intl) => { const {postProps} = postBodyProps; + if (!postProps?.username) { + return null; + } const username = renderUsername(postProps.username); const localeHolder = { diff --git a/app/components/post_body/system_message_helpers.test.js b/app/components/post_body/system_message_helpers.test.js index d4f11734c..ba6e6d8f4 100644 --- a/app/components/post_body/system_message_helpers.test.js +++ b/app/components/post_body/system_message_helpers.test.js @@ -87,7 +87,16 @@ describe('renderSystemMessage', () => { postType: Posts.POST_TYPES.CHANNEL_UNARCHIVED, }; - const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl); + let renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl); + expect(renderedMessage).toMatchSnapshot(); + + const noUserInPostBodyProps = { + ...basePostBodyProps, + postProps: {}, + postType: Posts.POST_TYPES.CHANNEL_UNARCHIVED, + }; + + renderedMessage = SystemMessageHelpers.renderSystemMessage(noUserInPostBodyProps, mockStyles, mockIntl); expect(renderedMessage).toMatchSnapshot(); });