MM-22043 Render Channel purpose message without markdown (#4131)

This commit is contained in:
Elias Nahum 2020-04-09 06:08:15 -04:00 committed by GitHub
parent c64581ef16
commit 9d0209fce6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 13 deletions

View file

@ -21,13 +21,11 @@ exports[`renderSystemMessage uses renderer for Channel Header update 1`] = `
`;
exports[`renderSystemMessage uses renderer for Channel Purpose update 1`] = `
<Connect(Markdown)
baseTextStyle={Object {}}
disableAtChannelMentionHighlight={true}
onPostPress={[MockFunction]}
textStyles={Object {}}
value="{username} updated the channel purpose from: {oldPurpose} to: {newPurpose}"
/>
<Text
style={Object {}}
>
{username} updated the channel purpose from: {oldPurpose} to: {newPurpose}
</Text>
`;
exports[`renderSystemMessage uses renderer for archived channel 1`] = `

View file

@ -2,6 +2,7 @@
// See LICENSE.txt for license information.
import React from 'react';
import {Text} from 'react-native';
import {Posts} from '@mm-redux/constants';
import Markdown from 'app/components/markdown';
import {t} from 'app/utils/i18n';
@ -10,10 +11,18 @@ const renderUsername = (value) => {
return (value[0] === '@') ? value : `@${value}`;
};
const renderMessage = (postBodyProps, styles, intl, localeHolder, values) => {
const renderMessage = (postBodyProps, styles, intl, localeHolder, values, skipMarkdown = false) => {
const {onPress} = postBodyProps;
const {messageStyle, textStyles} = styles;
if (skipMarkdown) {
return (
<Text style={messageStyle}>
{intl.formatMessage(localeHolder, values)}
</Text>
);
}
return (
<Markdown
baseTextStyle={messageStyle}
@ -90,7 +99,7 @@ const renderPurposeChangeMessage = (postBodyProps, styles, intl) => {
};
values = {username, oldPurpose, newPurpose};
return renderMessage(postBodyProps, styles, intl, localeHolder, values);
return renderMessage(postBodyProps, styles, intl, localeHolder, values, true);
}
localeHolder = {
@ -99,7 +108,7 @@ const renderPurposeChangeMessage = (postBodyProps, styles, intl) => {
};
values = {username, oldPurpose, newPurpose};
return renderMessage(postBodyProps, styles, intl, localeHolder, values);
return renderMessage(postBodyProps, styles, intl, localeHolder, values, true);
} else if (postProps.old_purpose) {
localeHolder = {
id: t('mobile.system_message.update_channel_purpose_message.removed'),
@ -107,7 +116,7 @@ const renderPurposeChangeMessage = (postBodyProps, styles, intl) => {
};
values = {username, oldPurpose, newPurpose};
return renderMessage(postBodyProps, styles, intl, localeHolder, values);
return renderMessage(postBodyProps, styles, intl, localeHolder, values, true);
}
return null;

View file

@ -1,9 +1,11 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as SystemMessageHelpers from './system_message_helpers';
import renderer from 'react-test-renderer';
import {Posts} from '@mm-redux/constants';
import * as SystemMessageHelpers from './system_message_helpers';
const basePostBodyProps = {
postProps: {
username: 'username',
@ -62,7 +64,9 @@ describe('renderSystemMessage', () => {
};
const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl);
expect(renderedMessage).toMatchSnapshot();
const tree = renderer.create(renderedMessage).toJSON();
expect(tree).toMatchSnapshot();
expect(tree.type).toEqual('Text');
});
test('uses renderer for archived channel', () => {