[MM-10394] Make hidden town-square (on read-only) be available to view by joining in more channels (#1666)

* make hidden town-square (on read-only) be available to view by joining in more channels

* updated

Signed-off-by: Saturnino Abril <saturnino.abril@gmail.com>
This commit is contained in:
Saturnino Abril 2018-05-25 04:38:39 +08:00 committed by GitHub
parent 1e4ee0716f
commit 38daeb95cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1744 additions and 7 deletions

View file

@ -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__): <ChannelItem
channelId="channel_id"
currentChannelId="current_channel_id"
displayName="display_name"
fake={false}
isChannelMuted={false}
isMyUser={true}
isUnread={true}
mentions={0}
navigator={
Object {
"push": [Function],
}
}
onSelectChannel={[Function]}
shouldHideChannel={false}
showUnreadForMsgs={true}
status="online"
teammateDeletedAt={0}
theme={
Object {
"sidebarText": "#aaa",
"sidebarTextActiveBorder": "#aaa",
"sidebarTextActiveColor": "#aaa",
"sidebarTextHoverBg": "#aaa",
}
}
type="O"
unreadMsgs={1}
/>,
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": <TouchableHighlight
activeOpacity={0.85}
delayPressOut={100}
onLongPress={[Function]}
onPress={[Function]}
underlayColor="rgba(170,170,170,0.5)"
>
<Component
style={
Array [
Object {
"flex": 1,
"flexDirection": "row",
"height": 44,
},
undefined,
]
}
>
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
undefined,
]
}
>
<ChannelIcon
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"
/>
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>
</Component>
</Component>
</TouchableHighlight>,
},
"ref": [Function],
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"activeOpacity": 0.85,
"children": <Component
style={
Array [
Object {
"flex": 1,
"flexDirection": "row",
"height": 44,
},
undefined,
]
}
>
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
undefined,
]
}
>
<ChannelIcon
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"
/>
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>
</Component>
</Component>,
"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,
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
undefined,
]
}
>
<ChannelIcon
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"
/>
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>
</Component>,
],
"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 [
<ChannelIcon
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"
/>,
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>,
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": <TouchableHighlight
activeOpacity={0.85}
delayPressOut={100}
onLongPress={[Function]}
onPress={[Function]}
underlayColor="rgba(170,170,170,0.5)"
>
<Component
style={
Array [
Object {
"flex": 1,
"flexDirection": "row",
"height": 44,
},
undefined,
]
}
>
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
undefined,
]
}
>
<ChannelIcon
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"
/>
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>
</Component>
</Component>
</TouchableHighlight>,
},
"ref": [Function],
"rendered": Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"activeOpacity": 0.85,
"children": <Component
style={
Array [
Object {
"flex": 1,
"flexDirection": "row",
"height": 44,
},
undefined,
]
}
>
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
undefined,
]
}
>
<ChannelIcon
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"
/>
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>
</Component>
</Component>,
"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,
<Component
style={
Array [
Object {
"alignItems": "center",
"flex": 1,
"flexDirection": "row",
"paddingLeft": 16,
},
undefined,
]
}
>
<ChannelIcon
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"
/>
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>
</Component>,
],
"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 [
<ChannelIcon
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"
/>,
<Text
accessible={true}
allowFontScaling={true}
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,
},
]
}
/>,
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",
},
],
],
},
},
},
},
}
`;

View file

@ -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;
}

View file

@ -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(
<ChannelItem {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
expect(wrapper).toMatchSnapshot();
});
});

View file

@ -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,
};
};
}

View file

@ -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 (
<ChannelDrawerItem
<ChannelItem
ref={channel.id}
channelId={channel.id}
channel={channel}

View file

@ -0,0 +1,702 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`MoreChannels should match snapshot 1`] = `
ShallowWrapper {
"length": 1,
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <MoreChannels
actions={
Object {
"getChannels": [Function],
"handleSelectChannel": [Function],
"joinChannel": [Function],
"removeHiddenDefaultChannel": [Function],
"searchChannels": [Function],
"setChannelDisplayName": [Function],
}
}
canCreateChannels={true}
channels={
Array [
Object {
"display_name": "display_name",
"id": "id",
"name": "name",
},
]
}
closeButton={Object {}}
currentTeamId="current_team_id"
currentUserId="current_user_id"
navigator={
Object {
"dismissModal": [Function],
"push": [Function],
"setButtons": [Function],
"setOnNavigatorEvent": [Function],
}
}
requestStatus={Object {}}
theme={
Object {
"centerChannelBg": "#aaa",
"centerChannelColor": "#aaa",
"sidebarHeaderBg": "#aaa",
"sidebarHeaderTextColor": "#aaa",
}
}
/>,
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 [
<Connect(StatusBar) />,
<Component
style={
Object {
"flex": 1,
}
}
>
<Component
style={
Object {
"marginVertical": 5,
}
}
>
<SearchBarIos
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=""
/>
</Component>
<CustomList
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",
}
}
/>
</Component>,
],
"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 [
<Component
style={
Object {
"marginVertical": 5,
}
}
>
<SearchBarIos
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=""
/>
</Component>,
<CustomList
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",
}
}
/>,
],
"style": Object {
"flex": 1,
},
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <SearchBarIos
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=""
/>,
"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 [
<Connect(StatusBar) />,
<Component
style={
Object {
"flex": 1,
}
}
>
<Component
style={
Object {
"marginVertical": 5,
}
}
>
<SearchBarIos
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=""
/>
</Component>
<CustomList
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",
}
}
/>
</Component>,
],
"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 [
<Component
style={
Object {
"marginVertical": 5,
}
}
>
<SearchBarIos
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=""
/>
</Component>,
<CustomList
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",
}
}
/>,
],
"style": Object {
"flex": 1,
},
},
"ref": null,
"rendered": Array [
Object {
"instance": null,
"key": undefined,
"nodeType": "class",
"props": Object {
"children": <SearchBarIos
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=""
/>,
"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",
},
],
],
},
},
},
},
}
`;

View file

@ -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(
<MoreChannels {...baseProps}/>,
{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(
<MoreChannels {...props}/>,
{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(
<MoreChannels {...baseProps}/>,
{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(
<MoreChannels {...baseProps}/>,
{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(
<MoreChannels {...props}/>,
{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(
<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 props = {...baseProps, actions: {...actions, getChannels: jest.fn()}};
const wrapper = shallow(
<MoreChannels {...props}/>,
{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);
});
});