Files
mattermost-mobile/app/components/global_threads/thread_item/thread_item.test.tsx
Anurag Shivarathri 856d8bd05f MM-34842 global threads options (#5630)
* fixes MM-37294 MM-37296 MM-37297

* Added conditions to check for post & thread existence

* Update app/mm-redux/selectors/entities/threads.ts

Co-authored-by: Kyriakos Z. <3829551+koox00@users.noreply.github.com>

* type fix

* Never disabling Mark All as unread

* Added follow/unfollow message for not yet thread posts

* Test case fix for mark all as unread enabled all the time

* Removed hardcoded condition

* Fixed MM-37509

* Updated snapshot for sidebar

* Global thread actions init

* Added options

* Update post_options.js

* Test cases fix

* Added border bottom for each thread option

* Update test case

* Reverting snapshot

* Updated snapshot

* Moved options to screens & removed redundants translations

* Reusing post_option for thread_option

* Component name changed to PostOption from ThreadOption

* Snapshot updated

* Removed factory

* Update app/screens/thread_options/index.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

* Update app/screens/thread_options/index.ts

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>

Co-authored-by: Kyriakos Z. <3829551+koox00@users.noreply.github.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
2021-10-11 13:24:38 +05:30

113 lines
3.5 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shallow} from 'enzyme';
import React from 'react';
import {Text} from 'react-native';
import {Preferences} from '@mm-redux/constants';
import {Channel} from '@mm-redux/types/channels';
import {Post} from '@mm-redux/types/posts';
import {UserThread} from '@mm-redux/types/threads';
import {UserProfile} from '@mm-redux/types/users';
import EventEmitter from '@mm-redux/utils/event_emitter';
import {intl} from '@test/intl-test-helper';
import {ThreadItem} from './thread_item';
describe('Global Thread Item', () => {
const testID = 'thread_item';
const baseProps = {
actions: {
getPost: jest.fn(),
getPostThread: jest.fn(),
selectPost: jest.fn(),
},
channel: {
display_name: 'CHANNEL 1',
} as Channel,
intl,
post: {
id: 'post1',
} as Post,
threadId: 'post1',
testID,
theme: Preferences.THEMES.denim,
thread: {
id: 'post1',
unread_replies: 5,
} as UserThread,
threadStarter: {
id: 'user1',
} as UserProfile,
};
const testIDPrefix = `${testID}.post1`;
test('Should render thread item with unread messages dot', () => {
const wrapper = shallow(
<ThreadItem
{...baseProps}
/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find({testID: `${testIDPrefix}.unread_dot`}).exists()).toBeTruthy();
expect(wrapper.find({testID: `${testIDPrefix}.unread_mentions`}).exists()).toBeFalsy();
expect(wrapper.find({testID: `${testIDPrefix}.footer`}).exists()).toBeTruthy();
});
test('Should show unread mentions count', () => {
const props = {
...baseProps,
thread: {
...baseProps.thread,
unread_mentions: 5,
},
};
const wrapper = shallow(
<ThreadItem
{...props}
/>,
);
expect(wrapper.getElement()).toMatchSnapshot();
expect(wrapper.find({testID: `${testIDPrefix}.unread_dot`}).exists()).toBeFalsy();
const mentionBadge = wrapper.find({testID: `${testIDPrefix}.unread_mentions`}).at(0);
expect(mentionBadge.exists()).toBeTruthy();
expect(mentionBadge.find(Text).children().text().trim()).toBe('5');
});
test('Should show unread mentions as 99+ when over 99', () => {
const props = {
...baseProps,
thread: {
...baseProps.thread,
unread_mentions: 511,
},
};
const wrapper = shallow(
<ThreadItem
{...props}
/>,
);
const mentionBadge = wrapper.find({testID: `${testIDPrefix}.unread_mentions`}).at(0);
expect(mentionBadge.find(Text).children().text().trim()).toBe('99+');
});
test('Should goto threads when pressed on thread item', () => {
EventEmitter.emit = jest.fn();
const wrapper = shallow(
<ThreadItem
{...baseProps}
/>,
);
const threadItem = wrapper.find({testID: `${testIDPrefix}.item`});
expect(threadItem.exists()).toBeTruthy();
threadItem.simulate('press');
expect(EventEmitter.emit).toHaveBeenCalledWith('goToThread', expect.anything());
});
});