mattermost-mobile/app/screens/more_channels/more_channels.test.js
Miguel Alatzar b65ce5d283 [MM-16136] Update channel related screens (#2915)
* Update screens

* Update login tests

* Remove done

* Fix failing tests

* Update screens and components

* Check styles fix

* Update tests

* Prevent setState call after component unmounts

* Add empty setButtons func to dummy navigator

* Remove platform check

* Remove Platform import

* Update react-native-navigation version

* Add separate showModalOverCurrentContext function

* check-style fixes

* Remove overriding of AppDelegate's window

* Fix modal over current context animation

* Add showSearchModal navigation action

* Check-style fix

* Address review comments

* Update SettingsSidebar and children

* Update EditProfile screen

* Update SettingsSidebar

* Keep track of latest componentId to appear

* Track componentId in state to use in navigation actions

* Update FlaggedPosts and children

* Update RecentMentions

* Update Settings

* Store componentIds in ephemeral store

* Update AttachmentButton

* Remove unnecessary dismissModal

* Fix typo

* Upate NotificationSettings

* Update NotificationSettingsAutoResponder

* Update NotificationSettingsMentions

* Update NotificationSettingsMobile

* Update CreateChannel and children

* Update MoreChannels

* Update ChannelPeek and children

* Update ChannelNavBar and children

* Update ChannelPostList and children

* Update ChannelInfo and children

* Update ChannelAddMembers

* Update ChannelMembers

* Update EditChannel

* Fix setting of top bar buttons

* Update Channel screen and children

* Fix typo

* Use goToScreen for Android too

* Remove navigationComponentId
2019-06-26 16:46:05 -04:00

90 lines
3.1 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 MoreChannels from './more_channels.js';
jest.mock('react-intl');
describe('MoreChannels', () => {
const actions = {
handleSelectChannel: jest.fn(),
joinChannel: jest.fn(),
getChannels: jest.fn().mockResolvedValue({data: [{id: 'id2', name: 'name2', display_name: 'display_name2'}]}),
searchChannels: jest.fn(),
setChannelDisplayName: jest.fn(),
setButtons: jest.fn(),
dismissModal: jest.fn(),
goToScreen: jest.fn(),
};
const baseProps = {
actions,
canCreateChannels: true,
channels: [{id: 'id', name: 'name', display_name: 'display_name'}],
closeButton: {},
currentUserId: 'current_user_id',
currentTeamId: 'current_team_id',
theme: Preferences.THEMES.default,
componentId: 'component-id',
};
test('should match snapshot', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper.getElement()).toMatchSnapshot();
});
test('should call props.actions.dismissModal on close', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
wrapper.instance().close();
expect(baseProps.actions.dismissModal).toHaveBeenCalledTimes(1);
});
test('should call props.actions.setButtons on headerButtons', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(baseProps.actions.setButtons).toHaveBeenCalledTimes(1);
wrapper.instance().headerButtons(true);
expect(baseProps.actions.setButtons).toHaveBeenCalledTimes(2);
});
test('should match return value of filterChannels', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const channels = [{id: 'id', name: 'name', display_name: 'display_name'}];
expect(wrapper.instance().filterChannels(channels, 'name')).toEqual([channels[0]]);
expect(wrapper.instance().filterChannels(channels, 'display_name')).toEqual([channels[0]]);
expect(wrapper.instance().filterChannels(channels, 'none')).toEqual([]);
expect(wrapper.instance().filterChannels(channels, 'display_none')).toEqual([]);
});
test('should match state on cancelSearch', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
wrapper.setState({term: 'term'});
wrapper.instance().cancelSearch(true);
expect(wrapper.state('term')).toEqual('');
expect(wrapper.state('channels')).toEqual(baseProps.channels);
});
});