From 93cbccf7bcd7f5f036f74f7dfed0e1597e404343 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Mon, 13 Apr 2020 11:44:22 -0400 Subject: [PATCH] MM-24093 Fix crash when system message does not contain a username in post props (#4143) --- .../system_message_helpers.test.js.snap | 10 ++++++++++ app/components/post_body/index.js | 12 +++++++++--- app/components/post_body/system_message_helpers.js | 8 ++++++-- .../post_body/system_message_helpers.test.js | 11 +++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) 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 237c84090..345c6f9bc 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 @@ -30,6 +30,16 @@ exports[`renderSystemMessage uses renderer for Channel Purpose update 1`] = ` /> `; +exports[`renderSystemMessage uses renderer for OLD archived channel without a username 1`] = ` + +`; + exports[`renderSystemMessage uses renderer for archived channel 1`] = ` { - return (value[0] === '@') ? value : `@${value}`; +const renderUsername = (value = '') => { + if (value) { + return (value[0] === '@') ? value : `@${value}`; + } + + return value; }; const renderMessage = (postBodyProps, styles, intl, localeHolder, values) => { diff --git a/app/components/post_body/system_message_helpers.test.js b/app/components/post_body/system_message_helpers.test.js index ba6e6d8f4..dae0eaa97 100644 --- a/app/components/post_body/system_message_helpers.test.js +++ b/app/components/post_body/system_message_helpers.test.js @@ -78,6 +78,17 @@ describe('renderSystemMessage', () => { expect(renderedMessage).toMatchSnapshot(); }); + test('uses renderer for OLD archived channel without a username', () => { + const postBodyProps = { + ...basePostBodyProps, + postProps: {}, + postType: Posts.POST_TYPES.CHANNEL_DELETED, + }; + + const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl); + expect(renderedMessage).toMatchSnapshot(); + }); + test('uses renderer for unarchived channel', () => { const postBodyProps = { ...basePostBodyProps,