mattermost-mobile/app/components/post_header/post_pre_header.test.js
Miguel Alatzar ee4b85edcf
[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-03-31 11:09:26 -07:00

153 lines
5 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 '@mm-redux/constants/preferences';
import PostPreHeader from './post_pre_header';
describe('PostPreHeader', () => {
const baseProps = {
isConsecutive: false,
isFlagged: false,
isPinned: false,
rightColumnStyle: [],
skipFlaggedHeader: false,
skipPinnedHeader: false,
theme: Preferences.THEMES.default,
};
test('should match snapshot when not flagged or pinned post', () => {
const wrapper = shallow(
<PostPreHeader {...baseProps}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.type()).toBeNull();
});
test('should match snapshot when flagged post is set but skipFlaggedHeader is true', () => {
const props = {
...baseProps,
isFlagged: true,
skipFlaggedHeader: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.type()).toBeNull();
});
test('should match snapshot when pinned post is set but skipPinnedHeader is true', () => {
const props = {
...baseProps,
isPinned: true,
skipPinnedHeader: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.type()).toBeNull();
});
test('should match snapshot when flagged and not pinned', () => {
const props = {
...baseProps,
isFlagged: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find('#flagIcon').exists()).toEqual(true);
expect(wrapper.find('#pinIcon').exists()).toEqual(false);
expect(wrapper.find('FormattedText').first().props().id).toEqual('mobile.post_pre_header.flagged');
});
test('should match snapshot when pinned and not flagged', () => {
const props = {
...baseProps,
isPinned: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find('#flagIcon').exists()).toEqual(false);
expect(wrapper.find('#pinIcon').exists()).toEqual(true);
expect(wrapper.find('FormattedText').first().props().id).toEqual('mobile.post_pre_header.pinned');
});
test('should match snapshot when pinned and flagged', () => {
const props = {
...baseProps,
isFlagged: true,
isPinned: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find('#flagIcon').exists()).toEqual(true);
expect(wrapper.find('#pinIcon').exists()).toEqual(true);
expect(wrapper.find('FormattedText').first().props().id).toEqual('mobile.post_pre_header.pinned_flagged');
});
test('should match snapshot when pinned and flagged but skipping pinned', () => {
const props = {
...baseProps,
isFlagged: true,
isPinned: true,
skipPinnedHeader: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find('#flagIcon').exists()).toEqual(true);
expect(wrapper.find('#pinIcon').exists()).toEqual(false);
expect(wrapper.find('FormattedText').first().props().id).toEqual('mobile.post_pre_header.flagged');
});
test('should match snapshot when pinned and flagged but skipping flagged', () => {
const props = {
...baseProps,
isFlagged: true,
isPinned: true,
skipFlaggedHeader: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find('#flagIcon').exists()).toEqual(false);
expect(wrapper.find('#pinIcon').exists()).toEqual(true);
expect(wrapper.find('FormattedText').first().props().id).toEqual('mobile.post_pre_header.pinned');
});
test('should match snapshot when pinned and flagged but skipping both', () => {
const props = {
...baseProps,
isFlagged: true,
isPinned: true,
skipFlaggedHeader: true,
skipPinnedHeader: true,
};
const wrapper = shallow(
<PostPreHeader {...props}/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.type()).toBeNull();
});
});