mattermost-mobile/app/components/post_body/post_body.test.js
Miguel Alatzar 2d81b497cf [MM-23520] Port mattermost-redux (#4088)
* Remove mattermost-redux

* Move mm-redux files into app/redux

* Add @redux path to tsconfig.json

* Fix imports

* Install missing dependencies

* Fix tsc errors

* Fix i18n_utils test

* Fix more imports

* Remove redux websocket

* Fix tests

* Rename @redux

* Apply changes from mattermost-redux PR 1103

* Remove mattermost-redux mention in template

* Add missing imports

* Rename app/redux/ to app/mm-redux/

* Remove test file

* Fix fetching Sidebar GM profiles

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2020-04-17 21:12:09 -07:00

132 lines
4.2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {Preferences} from '@mm-redux/constants';
import PostBodyAdditionalContent from 'app/components/post_body_additional_content';
import {shallowWithIntl} from 'test/intl-test-helper';
import PostBody from './post_body.js';
import * as SystemMessageHelpers from './system_message_helpers';
jest.mock('./system_message_helpers');
describe('PostBody', () => {
const baseProps = {
canDelete: true,
channelIsReadOnly: false,
deviceHeight: 1920,
fileIds: [],
hasBeenDeleted: false,
hasBeenEdited: false,
hasReactions: false,
highlight: false,
isFailed: false,
isFlagged: false,
isPending: false,
isPostAddChannelMember: false,
isPostEphemeral: false,
isReplyPost: false,
isSearchResult: false,
isSystemMessage: false,
managedConfig: {},
message: 'Hello, World!',
onFailedPostPress: jest.fn(),
onHashtagPress: jest.fn(),
onPermalinkPress: jest.fn(),
onPress: jest.fn(),
post: {id: 'post'},
postProps: {},
postType: '',
replyBarStyle: [],
showAddReaction: true,
showLongPost: true,
isEmojiOnly: false,
shouldRenderJumboEmoji: false,
theme: Preferences.THEMES.default,
};
test('should mount additional content for non-system messages', () => {
const props = {
...baseProps,
isSystemMessage: false,
};
const wrapper = shallowWithIntl(<PostBody {...props}/>);
expect(wrapper.find(PostBodyAdditionalContent).exists()).toBeTruthy();
});
test('should not mount additional content for system messages', () => {
const props = {
...baseProps,
isSystemMessage: true,
};
const wrapper = shallowWithIntl(<PostBody {...props}/>);
expect(wrapper.find(PostBodyAdditionalContent).exists()).toBeFalsy();
});
test('measurePost should update isLongPost when showLongPost is false', () => {
const event = {
nativeEvent: {
layout: {
height: null,
},
},
};
const props = {...baseProps, showLongPost: false};
const wrapper = shallowWithIntl(<PostBody {...props}/>);
const instance = wrapper.instance();
expect(wrapper.state('isLongPost')).toEqual(false);
event.nativeEvent.layout.height = wrapper.state('maxHeight');
instance.measurePost(event);
expect(wrapper.state('isLongPost')).toEqual(true);
event.nativeEvent.layout.height = wrapper.state('maxHeight') - 1;
instance.measurePost(event);
expect(wrapper.state('isLongPost')).toEqual(false);
event.nativeEvent.layout.height = wrapper.state('maxHeight') + 1;
instance.measurePost(event);
expect(wrapper.state('isLongPost')).toEqual(true);
});
test('measurePost should not update isLongPost when showLongPost is true', () => {
const event = {
nativeEvent: {
layout: {
height: null,
},
},
};
const props = {...baseProps, showLongPost: true};
const wrapper = shallowWithIntl(<PostBody {...props}/>);
const instance = wrapper.instance();
expect(wrapper.state('isLongPost')).toEqual(false);
event.nativeEvent.layout.height = wrapper.state('maxHeight');
instance.measurePost(event);
expect(wrapper.state('isLongPost')).toEqual(false);
event.nativeEvent.layout.height = wrapper.state('maxHeight') - 1;
instance.measurePost(event);
expect(wrapper.state('isLongPost')).toEqual(false);
event.nativeEvent.layout.height = wrapper.state('maxHeight') + 1;
instance.measurePost(event);
expect(wrapper.state('isLongPost')).toEqual(false);
});
test('should return system message as post body', () => {
shallowWithIntl(<PostBody {...baseProps}/>);
expect(SystemMessageHelpers.renderSystemMessage.mock.calls.length).toBe(1);
});
});