mattermost-mobile/app/screens/post_options/post_options.test.js
Courtney Pattison c3a1e3561e [MM-13381] Added reply to post options (#2665)
* [MM-13381] Added reply to post options

* [MM-13381] Fixes for adding reply to post options

* [MM-13381] Fixed logic for adding reply to post options

* [MM-13381] Fixed canReply logic for post options
2019-03-25 13:29:46 -07:00

102 lines
2.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import {shallow} from 'enzyme';
import Preferences from 'mattermost-redux/constants/preferences';
import PostOptions from './post_options';
jest.mock('react-intl');
describe('PostOptions', () => {
const navigator = {
showModal: jest.fn(),
dismissModal: jest.fn(),
push: jest.fn(),
};
const actions = {
addReaction: jest.fn(),
deletePost: jest.fn(),
flagPost: jest.fn(),
pinPost: jest.fn(),
removePost: jest.fn(),
unflagPost: jest.fn(),
unpinPost: jest.fn(),
selectPost: jest.fn(),
loadThreadIfNecessary: jest.fn(),
};
const post = {
root_id: 'root_id',
id: 'post_id',
message: 'message',
is_pinned: false,
channel_id: 'channel_id',
};
const baseProps = {
actions,
canAddReaction: true,
canReply: true,
canDelete: true,
canPin: true,
canEdit: true,
canEditUntil: -1,
channelIsReadOnly: false,
currentTeamUrl: 'http://localhost:8065/team-name',
deviceHeight: 600,
hasBeenDeleted: false,
isFlagged: false,
isMyPost: true,
isSystemMessage: false,
managedConfig: {},
navigator,
post,
showAddReaction: true,
theme: Preferences.THEMES.default,
};
function getWrapper(props = {}) {
return shallow(
<PostOptions
{...baseProps}
{...props}
/>,
{context: {intl: {formatMessage: ({defaultMessage}) => defaultMessage}}}
);
}
test('should match snapshot, showing all possible options', () => {
const wrapper = getWrapper();
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot, showing Delete option only for system message to user who has permission to delete', () => {
const wrapper = getWrapper({isSystemMessage: true});
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should match snapshot, no option for system message to user who doesn\'t have the permission to delete', () => {
const wrapper = getWrapper({isSystemMessage: true, canDelete: false});
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should load thread', () => {
const wrapper = getWrapper();
wrapper.findWhere((node) => node.key() === 'reply').simulate('press');
expect(actions.loadThreadIfNecessary).toBeCalled();
});
test('should not show reply option', () => {
const wrapper = getWrapper({canReply: false});
expect(wrapper.findWhere((node) => node.key() === 'reply')).toMatchObject({});
});
});