mattermost-mobile/app/components/post_body/system_message_helpers.test.js
Allen Lai 3e2fc1bc67
[MM-20804] Add "Unarchive Channel" option to the channel info screen (#3663)
* undelete

* fix build

* change let to const

* ran make i18n

* small refactor

* using canUndelete var

* added render message

* fix bug

* sync

* remove duplicate

* fix test

* add unit test for unarchive channel button render

* fix unit test for unarchive channel

* delete space

* change logic in undelete

* add server minimum for feature

* fix renderunarchive test with adding props variables

* snpashot wasnt matching. fixed by adding to base prop

* return early if false

* change position and color for unarchive button

* refactor handle delete undelete leave

* move serverversion call up

* undelete to unarchive

* remove unnecessary seperator

* hash

* Update app/screens/channel_info/index.js

Co-Authored-By: Elias Nahum <nahumhbl@gmail.com>

* delete canuseunarchive feature

* add test to render sys message

* remote 'w' in package.json

* add trailing comma

* update redux hash

* whitespace in test

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-02-26 21:02:28 -03:00

103 lines
3.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import * as SystemMessageHelpers from './system_message_helpers';
import {Posts} from 'mattermost-redux/constants';
const basePostBodyProps = {
postProps: {
username: 'username',
},
onPress: jest.fn(),
};
const mockStyles = {
messageStyle: {},
textStyles: {},
};
const mockIntl = {
formatMessage: ({defaultMessage}) => defaultMessage,
};
describe('renderSystemMessage', () => {
test('uses renderer for Channel Header update', () => {
const postBodyProps = {
...basePostBodyProps,
postProps: {
...basePostBodyProps.postProps,
old_header: 'old header',
new_header: 'new header',
},
postType: Posts.POST_TYPES.HEADER_CHANGE,
};
const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl);
expect(renderedMessage).toMatchSnapshot();
});
test('uses renderer for Channel Display Name update', () => {
const postBodyProps = {
...basePostBodyProps,
postProps: {
...basePostBodyProps.postProps,
old_displayname: 'old displayname',
new_displayname: 'new displayname',
},
postType: Posts.POST_TYPES.DISPLAYNAME_CHANGE,
};
const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl);
expect(renderedMessage).toMatchSnapshot();
});
test('uses renderer for Channel Purpose update', () => {
const postBodyProps = {
...basePostBodyProps,
postProps: {
...basePostBodyProps.postProps,
old_purpose: 'old purpose',
new_purpose: 'new purpose',
},
postType: Posts.POST_TYPES.PURPOSE_CHANGE,
};
const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl);
expect(renderedMessage).toMatchSnapshot();
});
test('uses renderer for archived channel', () => {
const postBodyProps = {
...basePostBodyProps,
postProps: {
...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,
postProps: {
...basePostBodyProps.postProps,
},
postType: Posts.POST_TYPES.CHANNEL_UNARCHIVED,
};
const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl);
expect(renderedMessage).toMatchSnapshot();
});
test('is null for non-qualifying system messages', () => {
const postBodyProps = {
...basePostBodyProps,
postType: 'not_relevant',
};
const renderedMessage = SystemMessageHelpers.renderSystemMessage(postBodyProps, mockStyles, mockIntl);
expect(renderedMessage).toBeNull();
});
});