diff --git a/app/components/channel_drawer/channels_list/channel_item/__snapshots__/channel_item.test.js.snap b/app/components/channel_drawer/channels_list/channel_item/__snapshots__/channel_item.test.js.snap
new file mode 100644
index 000000000..b48b1eeb9
--- /dev/null
+++ b/app/components/channel_drawer/channels_list/channel_item/__snapshots__/channel_item.test.js.snap
@@ -0,0 +1,809 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`ChannelItem should match snapshot 1`] = `
+ShallowWrapper {
+ "length": 1,
+ Symbol(enzyme.__root__): [Circular],
+ Symbol(enzyme.__unrendered__): ,
+ Symbol(enzyme.__renderer__): Object {
+ "batchedUpdates": [Function],
+ "getNode": [Function],
+ "render": [Function],
+ "simulateEvent": [Function],
+ "unmount": [Function],
+ },
+ Symbol(enzyme.__node__): Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children":
+
+
+
+
+
+
+ ,
+ },
+ "ref": [Function],
+ "rendered": Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "activeOpacity": 0.85,
+ "children":
+
+
+
+
+ ,
+ "delayPressOut": 100,
+ "onLongPress": [Function],
+ "onPress": [Function],
+ "underlayColor": "rgba(170,170,170,0.5)",
+ },
+ "ref": null,
+ "rendered": Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+ undefined,
+
+
+
+ ,
+ ],
+ "style": Array [
+ Object {
+ "flex": 1,
+ "flexDirection": "row",
+ "height": 44,
+ },
+ undefined,
+ ],
+ },
+ "ref": null,
+ "rendered": Array [
+ undefined,
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+ ,
+ ,
+ undefined,
+ ],
+ "style": Array [
+ Object {
+ "alignItems": "center",
+ "flex": 1,
+ "flexDirection": "row",
+ "paddingLeft": 16,
+ },
+ undefined,
+ ],
+ },
+ "ref": null,
+ "rendered": Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "channelId": "channel_id",
+ "isActive": false,
+ "isInfo": false,
+ "isUnread": true,
+ "membersCount": 1,
+ "size": 16,
+ "status": "online",
+ "teammateDeletedAt": 0,
+ "theme": Object {
+ "sidebarText": "#aaa",
+ "sidebarTextActiveBorder": "#aaa",
+ "sidebarTextActiveColor": "#aaa",
+ "sidebarTextHoverBg": "#aaa",
+ },
+ "type": "O",
+ },
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "accessible": true,
+ "allowFontScaling": true,
+ "children": undefined,
+ "ellipsizeMode": "tail",
+ "numberOfLines": 1,
+ "style": Array [
+ Object {
+ "color": "rgba(170,170,170,0.4)",
+ "flex": 1,
+ "fontSize": 14,
+ "fontWeight": "600",
+ "height": "100%",
+ "lineHeight": 44,
+ "paddingRight": 40,
+ "textAlignVertical": "center",
+ },
+ Object {
+ "color": undefined,
+ },
+ ],
+ },
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ undefined,
+ ],
+ "type": [Function],
+ },
+ ],
+ "type": [Function],
+ },
+ "type": [Function],
+ },
+ "type": [Function],
+ },
+ Symbol(enzyme.__nodes__): Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children":
+
+
+
+
+
+
+ ,
+ },
+ "ref": [Function],
+ "rendered": Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "activeOpacity": 0.85,
+ "children":
+
+
+
+
+ ,
+ "delayPressOut": 100,
+ "onLongPress": [Function],
+ "onPress": [Function],
+ "underlayColor": "rgba(170,170,170,0.5)",
+ },
+ "ref": null,
+ "rendered": Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+ undefined,
+
+
+
+ ,
+ ],
+ "style": Array [
+ Object {
+ "flex": 1,
+ "flexDirection": "row",
+ "height": 44,
+ },
+ undefined,
+ ],
+ },
+ "ref": null,
+ "rendered": Array [
+ undefined,
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+ ,
+ ,
+ undefined,
+ ],
+ "style": Array [
+ Object {
+ "alignItems": "center",
+ "flex": 1,
+ "flexDirection": "row",
+ "paddingLeft": 16,
+ },
+ undefined,
+ ],
+ },
+ "ref": null,
+ "rendered": Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "channelId": "channel_id",
+ "isActive": false,
+ "isInfo": false,
+ "isUnread": true,
+ "membersCount": 1,
+ "size": 16,
+ "status": "online",
+ "teammateDeletedAt": 0,
+ "theme": Object {
+ "sidebarText": "#aaa",
+ "sidebarTextActiveBorder": "#aaa",
+ "sidebarTextActiveColor": "#aaa",
+ "sidebarTextHoverBg": "#aaa",
+ },
+ "type": "O",
+ },
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "accessible": true,
+ "allowFontScaling": true,
+ "children": undefined,
+ "ellipsizeMode": "tail",
+ "numberOfLines": 1,
+ "style": Array [
+ Object {
+ "color": "rgba(170,170,170,0.4)",
+ "flex": 1,
+ "fontSize": 14,
+ "fontWeight": "600",
+ "height": "100%",
+ "lineHeight": 44,
+ "paddingRight": 40,
+ "textAlignVertical": "center",
+ },
+ Object {
+ "color": undefined,
+ },
+ ],
+ },
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ undefined,
+ ],
+ "type": [Function],
+ },
+ ],
+ "type": [Function],
+ },
+ "type": [Function],
+ },
+ "type": [Function],
+ },
+ ],
+ Symbol(enzyme.__options__): Object {
+ "adapter": ReactSixteenAdapter {
+ "options": Object {
+ "enableComponentDidUpdateOnSetState": true,
+ },
+ },
+ "context": Object {
+ "intl": Object {
+ "formatMessage": [MockFunction] {
+ "calls": Array [
+ Array [
+ Object {
+ "defaultMessage": "{displayName} (you)",
+ "id": "channel_header.directchannel.you",
+ },
+ Object {
+ "displayname": "display_name",
+ },
+ ],
+ ],
+ },
+ },
+ },
+ },
+}
+`;
diff --git a/app/components/channel_drawer/channels_list/channel_item/channel_item.js b/app/components/channel_drawer/channels_list/channel_item/channel_item.js
index 21b8ba576..0143264de 100644
--- a/app/components/channel_drawer/channels_list/channel_item/channel_item.js
+++ b/app/components/channel_drawer/channels_list/channel_item/channel_item.js
@@ -32,10 +32,16 @@ export default class ChannelItem extends PureComponent {
navigator: PropTypes.object,
onSelectChannel: PropTypes.func.isRequired,
shouldHideChannel: PropTypes.bool,
+ showUnreadForMsgs: PropTypes.bool.isRequired,
status: PropTypes.string,
teammateDeletedAt: PropTypes.number,
type: PropTypes.string.isRequired,
theme: PropTypes.object.isRequired,
+ unreadMsgs: PropTypes.number.isRequired,
+ };
+
+ static defaultProps = {
+ mentions: 0,
};
static contextTypes = {
@@ -73,6 +79,10 @@ export default class ChannelItem extends PureComponent {
this.previewRef = ref;
};
+ showChannelAsUnread = () => {
+ return this.props.mentions > 0 || (this.props.unreadMsgs > 0 && this.props.showUnreadForMsgs);
+ };
+
render() {
const {
channelId,
@@ -89,7 +99,7 @@ export default class ChannelItem extends PureComponent {
type,
} = this.props;
- if (shouldHideChannel) {
+ if (!this.showChannelAsUnread() && shouldHideChannel) {
return null;
}
diff --git a/app/components/channel_drawer/channels_list/channel_item/channel_item.test.js b/app/components/channel_drawer/channels_list/channel_item/channel_item.test.js
new file mode 100644
index 000000000..e3800c561
--- /dev/null
+++ b/app/components/channel_drawer/channels_list/channel_item/channel_item.test.js
@@ -0,0 +1,47 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import React from 'react';
+import {configure, shallow} from 'enzyme';
+import Adapter from 'enzyme-adapter-react-16';
+configure({adapter: new Adapter()});
+
+import ChannelItem from './channel_item.js';
+
+jest.mock('react-intl');
+
+describe('ChannelItem', () => {
+ const baseProps = {
+ channelId: 'channel_id',
+ currentChannelId: 'current_channel_id',
+ displayName: 'display_name',
+ fake: false,
+ isChannelMuted: false,
+ isMyUser: true,
+ isUnread: true,
+ mentions: 0,
+ navigator: {push: () => {}}, // eslint-disable-line no-empty-function
+ onSelectChannel: () => {}, // eslint-disable-line no-empty-function
+ shouldHideChannel: false,
+ showUnreadForMsgs: true,
+ status: 'online',
+ teammateDeletedAt: 0,
+ type: 'O',
+ theme: {
+ sidebarText: '#aaa',
+ sidebarTextActiveBorder: '#aaa',
+ sidebarTextActiveColor: '#aaa',
+ sidebarTextHoverBg: '#aaa',
+ },
+ unreadMsgs: 1,
+ };
+
+ test('should match snapshot', () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ expect(wrapper).toMatchSnapshot();
+ });
+});
diff --git a/app/components/channel_drawer/channels_list/channel_item/index.js b/app/components/channel_drawer/channels_list/channel_item/index.js
index 416ee3c5f..68c0e58a0 100644
--- a/app/components/channel_drawer/channels_list/channel_item/index.js
+++ b/app/components/channel_drawer/channels_list/channel_item/index.js
@@ -4,7 +4,12 @@
import {connect} from 'react-redux';
import {General} from 'mattermost-redux/constants';
-import {getCurrentChannelId, makeGetChannel, getMyChannelMember, isChannelReadOnlyById} from 'mattermost-redux/selectors/entities/channels';
+import {
+ getCurrentChannelId,
+ makeGetChannel,
+ getMyChannelMember,
+ shouldHideDefaultChannel,
+} from 'mattermost-redux/selectors/entities/channels';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import {getCurrentUserId, getUser} from 'mattermost-redux/selectors/entities/users';
import {isChannelMuted} from 'mattermost-redux/utils/channel_utils';
@@ -29,21 +34,44 @@ function makeMapStateToProps() {
}
}
- const isReadOnly = isChannelReadOnlyById(state, channel.id);
- const shouldHideChannel = !ownProps.isSearchResult && !ownProps.isFavorite && isReadOnly;
+ const currentChannelId = getCurrentChannelId(state);
+ const isActive = ownProps.channelId === currentChannelId;
+
+ let shouldHideChannel = false;
+ if (
+ channel.name === General.DEFAULT_CHANNEL &&
+ !isActive &&
+ !ownProps.isFavorite &&
+ !ownProps.isSearchResult &&
+ shouldHideDefaultChannel(state, channel)
+ ) {
+ shouldHideChannel = true;
+ }
+
+ let unreadMsgs = 0;
+ if (member && channel) {
+ unreadMsgs = Math.max(channel.total_msg_count - member.msg_count, 0);
+ }
+
+ let showUnreadForMsgs = true;
+ if (member && member.notify_props) {
+ showUnreadForMsgs = member.notify_props.mark_unread !== General.MENTION;
+ }
return {
- currentChannelId: getCurrentChannelId(state),
+ currentChannelId,
displayName: channel.display_name,
fake: channel.fake,
isChannelMuted: isChannelMuted(member),
isMyUser,
mentions: member ? member.mention_count : 0,
shouldHideChannel,
+ showUnreadForMsgs,
status: channel.status,
teammateDeletedAt,
theme: getTheme(state),
type: channel.type,
+ unreadMsgs,
};
};
}
diff --git a/app/components/channel_drawer/channels_list/filtered_list/filtered_list.js b/app/components/channel_drawer/channels_list/filtered_list/filtered_list.js
index d8bb6607b..52deb30f9 100644
--- a/app/components/channel_drawer/channels_list/filtered_list/filtered_list.js
+++ b/app/components/channel_drawer/channels_list/filtered_list/filtered_list.js
@@ -19,7 +19,7 @@ import {General} from 'mattermost-redux/constants';
import {sortChannelsByDisplayName} from 'mattermost-redux/utils/channel_utils';
import {displayUsername} from 'mattermost-redux/utils/user_utils';
-import ChannelDrawerItem from 'app/components/channel_drawer/channels_list/channel_item';
+import ChannelItem from 'app/components/channel_drawer/channels_list/channel_item';
import {ListTypes} from 'app/constants';
const VIEWABILITY_CONFIG = ListTypes.VISIBILITY_CONFIG_DEFAULTS;
@@ -109,7 +109,7 @@ class FilteredList extends Component {
createChannelElement = (channel) => {
return (
- ,
+ Symbol(enzyme.__renderer__): Object {
+ "batchedUpdates": [Function],
+ "getNode": [Function],
+ "render": [Function],
+ "simulateEvent": [Function],
+ "unmount": [Function],
+ },
+ Symbol(enzyme.__node__): Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+ ,
+
+
+
+
+
+ ,
+ ],
+ "style": Object {
+ "backgroundColor": "#aaa",
+ "flex": 1,
+ },
+ },
+ "ref": null,
+ "rendered": Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {},
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+
+
+ ,
+ ,
+ ],
+ "style": Object {
+ "flex": 1,
+ },
+ },
+ "ref": null,
+ "rendered": Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": ,
+ "style": Object {
+ "marginVertical": 5,
+ },
+ },
+ "ref": null,
+ "rendered": Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "autoCapitalize": "none",
+ "backgroundColor": "transparent",
+ "blurOnSubmit": true,
+ "cancelTitle": undefined,
+ "inputHeight": 33,
+ "inputStyle": Object {
+ "backgroundColor": "rgba(170,170,170,0.2)",
+ "color": "#aaa",
+ "fontSize": 15,
+ },
+ "onBlur": [Function],
+ "onCancelButtonPress": [Function],
+ "onChangeText": [Function],
+ "onFocus": [Function],
+ "onSearchButtonPress": [Function],
+ "onSelectionChange": [Function],
+ "placeholder": undefined,
+ "placeholderTextColor": "rgba(170,170,170,0.5)",
+ "tintColorDelete": "rgba(170,170,170,0.5)",
+ "tintColorSearch": "rgba(170,170,170,0.5)",
+ "titleCancelColor": "#aaa",
+ "value": "",
+ },
+ "ref": "search_bar",
+ "rendered": null,
+ "type": [Function],
+ },
+ "type": [Function],
+ },
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "createSections": [Function],
+ "data": Array [
+ Object {
+ "display_name": "display_name",
+ "id": "id",
+ "name": "name",
+ },
+ ],
+ "listInitialSize": 10,
+ "listPageSize": 10,
+ "listScrollRenderAheadDistance": 50,
+ "loading": false,
+ "loadingText": Object {
+ "defaultMessage": "Loading Channels...",
+ "id": "mobile.loading_channels",
+ },
+ "onListEndReached": [Function],
+ "onListEndReachedThreshold": 50,
+ "onRowPress": [Function],
+ "renderRow": [Function],
+ "searching": false,
+ "selectable": false,
+ "showNoResults": false,
+ "showSections": false,
+ "theme": Object {
+ "centerChannelBg": "#aaa",
+ "centerChannelColor": "#aaa",
+ "sidebarHeaderBg": "#aaa",
+ "sidebarHeaderTextColor": "#aaa",
+ },
+ },
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ ],
+ "type": [Function],
+ },
+ ],
+ "type": [Function],
+ },
+ Symbol(enzyme.__nodes__): Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+ ,
+
+
+
+
+
+ ,
+ ],
+ "style": Object {
+ "backgroundColor": "#aaa",
+ "flex": 1,
+ },
+ },
+ "ref": null,
+ "rendered": Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {},
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": Array [
+
+
+ ,
+ ,
+ ],
+ "style": Object {
+ "flex": 1,
+ },
+ },
+ "ref": null,
+ "rendered": Array [
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "children": ,
+ "style": Object {
+ "marginVertical": 5,
+ },
+ },
+ "ref": null,
+ "rendered": Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "autoCapitalize": "none",
+ "backgroundColor": "transparent",
+ "blurOnSubmit": true,
+ "cancelTitle": undefined,
+ "inputHeight": 33,
+ "inputStyle": Object {
+ "backgroundColor": "rgba(170,170,170,0.2)",
+ "color": "#aaa",
+ "fontSize": 15,
+ },
+ "onBlur": [Function],
+ "onCancelButtonPress": [Function],
+ "onChangeText": [Function],
+ "onFocus": [Function],
+ "onSearchButtonPress": [Function],
+ "onSelectionChange": [Function],
+ "placeholder": undefined,
+ "placeholderTextColor": "rgba(170,170,170,0.5)",
+ "tintColorDelete": "rgba(170,170,170,0.5)",
+ "tintColorSearch": "rgba(170,170,170,0.5)",
+ "titleCancelColor": "#aaa",
+ "value": "",
+ },
+ "ref": "search_bar",
+ "rendered": null,
+ "type": [Function],
+ },
+ "type": [Function],
+ },
+ Object {
+ "instance": null,
+ "key": undefined,
+ "nodeType": "class",
+ "props": Object {
+ "createSections": [Function],
+ "data": Array [
+ Object {
+ "display_name": "display_name",
+ "id": "id",
+ "name": "name",
+ },
+ ],
+ "listInitialSize": 10,
+ "listPageSize": 10,
+ "listScrollRenderAheadDistance": 50,
+ "loading": false,
+ "loadingText": Object {
+ "defaultMessage": "Loading Channels...",
+ "id": "mobile.loading_channels",
+ },
+ "onListEndReached": [Function],
+ "onListEndReachedThreshold": 50,
+ "onRowPress": [Function],
+ "renderRow": [Function],
+ "searching": false,
+ "selectable": false,
+ "showNoResults": false,
+ "showSections": false,
+ "theme": Object {
+ "centerChannelBg": "#aaa",
+ "centerChannelColor": "#aaa",
+ "sidebarHeaderBg": "#aaa",
+ "sidebarHeaderTextColor": "#aaa",
+ },
+ },
+ "ref": null,
+ "rendered": null,
+ "type": [Function],
+ },
+ ],
+ "type": [Function],
+ },
+ ],
+ "type": [Function],
+ },
+ ],
+ Symbol(enzyme.__options__): Object {
+ "adapter": ReactSixteenAdapter {
+ "options": Object {
+ "enableComponentDidUpdateOnSetState": true,
+ },
+ },
+ "context": Object {
+ "intl": Object {
+ "formatMessage": [MockFunction] {
+ "calls": Array [
+ Array [
+ Object {
+ "defaultMessage": "Create",
+ "id": "mobile.create_channel",
+ },
+ ],
+ Array [
+ Object {
+ "defaultMessage": "Search",
+ "id": "search_bar.search",
+ },
+ ],
+ Array [
+ Object {
+ "defaultMessage": "Cancel",
+ "id": "mobile.post.cancel",
+ },
+ ],
+ ],
+ },
+ },
+ },
+ },
+}
+`;
diff --git a/app/screens/more_channels/more_channels.test.js b/app/screens/more_channels/more_channels.test.js
new file mode 100644
index 000000000..623a96834
--- /dev/null
+++ b/app/screens/more_channels/more_channels.test.js
@@ -0,0 +1,141 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import React from 'react';
+import {configure, shallow} from 'enzyme';
+import Adapter from 'enzyme-adapter-react-16';
+configure({adapter: new Adapter()});
+
+import MoreChannels from './more_channels.js';
+
+jest.mock('react-intl');
+
+describe('MoreChannels', () => {
+ const navigator = {
+ setOnNavigatorEvent: () => {}, // eslint-disable-line no-empty-function
+ setButtons: () => {}, // eslint-disable-line no-empty-function
+ dismissModal: () => {}, // eslint-disable-line no-empty-function
+ push: () => {}, // eslint-disable-line no-empty-function
+ };
+
+ const actions = {
+ handleSelectChannel: () => {}, // eslint-disable-line no-empty-function
+ joinChannel: () => {}, // eslint-disable-line no-empty-function
+ getChannels: () => {}, // eslint-disable-line no-empty-function
+ removeHiddenDefaultChannel: () => {}, // eslint-disable-line no-empty-function
+ searchChannels: () => {}, // eslint-disable-line no-empty-function
+ setChannelDisplayName: () => {}, // eslint-disable-line no-empty-function
+ };
+
+ const baseProps = {
+ currentUserId: 'current_user_id',
+ currentTeamId: 'current_team_id',
+ navigator,
+ theme: {
+ centerChannelBg: '#aaa',
+ centerChannelColor: '#aaa',
+ sidebarHeaderBg: '#aaa',
+ sidebarHeaderTextColor: '#aaa',
+ },
+ canCreateChannels: true,
+ channels: [{id: 'id', name: 'name', display_name: 'display_name'}],
+ closeButton: {},
+ requestStatus: {},
+ actions,
+ };
+
+ test('should match snapshot', () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ expect(wrapper).toMatchSnapshot();
+ });
+
+ test('should call props.navigator.dismissModal on close', () => {
+ const props = {...baseProps, navigator: {...navigator, dismissModal: jest.fn()}};
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ wrapper.instance().close();
+ expect(props.navigator.dismissModal).toHaveBeenCalledTimes(1);
+ expect(props.navigator.dismissModal).toHaveBeenCalledWith({animationType: 'slide-down'});
+ });
+
+ test('should call headerButtons on emitCanCreateChannel', () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ const instance = wrapper.instance();
+ instance.headerButtons = jest.fn();
+
+ wrapper.instance().emitCanCreateChannel(true);
+ expect(instance.headerButtons).toHaveBeenCalledTimes(1);
+ expect(instance.headerButtons).toHaveBeenCalledWith(baseProps.canCreateChannels, true);
+
+ wrapper.instance().emitCanCreateChannel(false);
+ expect(instance.headerButtons).toHaveBeenCalledTimes(2);
+ expect(instance.headerButtons).toHaveBeenCalledWith(baseProps.canCreateChannels, false);
+ });
+
+ test('should match state on handleCreateScreenVisible', () => {
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ wrapper.setState({createScreenVisible: false});
+
+ wrapper.instance().handleCreateScreenVisible(true);
+ expect(wrapper.state('createScreenVisible')).toEqual(true);
+
+ wrapper.instance().handleCreateScreenVisible(false);
+ expect(wrapper.state('createScreenVisible')).toEqual(false);
+ });
+
+ test('should call props.navigator.setButtons on headerButtons', () => {
+ const props = {...baseProps, navigator: {...navigator, setButtons: jest.fn()}};
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ expect(props.navigator.setButtons).toHaveBeenCalledTimes(1);
+ wrapper.instance().headerButtons();
+ expect(props.navigator.setButtons).toHaveBeenCalledTimes(2);
+ });
+
+ test('should match return value of filterChannels', () => {
+ const wrapper = shallow(
+ ,
+ {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 props = {...baseProps, actions: {...actions, getChannels: jest.fn()}};
+ const wrapper = shallow(
+ ,
+ {context: {intl: {formatMessage: jest.fn()}}},
+ );
+
+ wrapper.setState({term: 'term', searching: true, page: 1});
+ wrapper.instance().cancelSearch(true);
+ expect(props.actions.getChannels).toHaveBeenCalledTimes(1);
+ expect(props.actions.getChannels).toHaveBeenCalledWith(props.currentTeamId, 0);
+ expect(wrapper.state('term')).toEqual('');
+ expect(wrapper.state('searching')).toEqual(false);
+ expect(wrapper.state('page')).toEqual(0);
+ });
+});