Handle postIds null or undefined in channel_post_list (#2760)
* Handle postIds null or undefined in channel_post_list * Update unit tests
This commit is contained in:
parent
5c654364c1
commit
f49c2b430c
3 changed files with 177 additions and 3 deletions
|
|
@ -0,0 +1,124 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`ChannelPostList should match snapshot 1`] = `
|
||||
<View
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Connect(PostList)
|
||||
channelId="current_channel_id"
|
||||
currentUserId="current_user_id"
|
||||
extraData={false}
|
||||
indicateNewMessages={true}
|
||||
lastViewedAt={12345}
|
||||
navigator={
|
||||
Object {
|
||||
"pop": [MockFunction],
|
||||
"setButtons": [MockFunction],
|
||||
"setOnNavigatorEvent": [MockFunction],
|
||||
}
|
||||
}
|
||||
onLoadMoreUp={[Function]}
|
||||
onPostPress={[Function]}
|
||||
postIds={Array []}
|
||||
refreshing={false}
|
||||
renderFooter={[Function]}
|
||||
renderReplies={true}
|
||||
/>
|
||||
<Connect(AnnouncementBanner)
|
||||
navigator={
|
||||
Object {
|
||||
"pop": [MockFunction],
|
||||
"setButtons": [MockFunction],
|
||||
"setOnNavigatorEvent": [MockFunction],
|
||||
}
|
||||
}
|
||||
/>
|
||||
<Connect(RetryBarIndicator) />
|
||||
</View>
|
||||
`;
|
||||
|
||||
exports[`ChannelPostList should match snapshot 2`] = `
|
||||
<View
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Connect(PostList)
|
||||
channelId="current_channel_id"
|
||||
currentUserId="current_user_id"
|
||||
extraData={false}
|
||||
indicateNewMessages={true}
|
||||
lastViewedAt={12345}
|
||||
navigator={
|
||||
Object {
|
||||
"pop": [MockFunction],
|
||||
"setButtons": [MockFunction],
|
||||
"setOnNavigatorEvent": [MockFunction],
|
||||
}
|
||||
}
|
||||
onLoadMoreUp={[Function]}
|
||||
onPostPress={[Function]}
|
||||
postIds={Array []}
|
||||
refreshing={false}
|
||||
renderFooter={[Function]}
|
||||
renderReplies={true}
|
||||
/>
|
||||
<Connect(AnnouncementBanner)
|
||||
navigator={
|
||||
Object {
|
||||
"pop": [MockFunction],
|
||||
"setButtons": [MockFunction],
|
||||
"setOnNavigatorEvent": [MockFunction],
|
||||
}
|
||||
}
|
||||
/>
|
||||
<Connect(RetryBarIndicator) />
|
||||
</View>
|
||||
`;
|
||||
|
||||
exports[`ChannelPostList should match snapshot 3`] = `
|
||||
<View
|
||||
style={
|
||||
Object {
|
||||
"flex": 1,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Connect(PostList)
|
||||
channelId="current_channel_id"
|
||||
currentUserId="current_user_id"
|
||||
extraData={false}
|
||||
indicateNewMessages={true}
|
||||
lastViewedAt={12345}
|
||||
navigator={
|
||||
Object {
|
||||
"pop": [MockFunction],
|
||||
"setButtons": [MockFunction],
|
||||
"setOnNavigatorEvent": [MockFunction],
|
||||
}
|
||||
}
|
||||
onLoadMoreUp={[Function]}
|
||||
onPostPress={[Function]}
|
||||
postIds={Array []}
|
||||
refreshing={false}
|
||||
renderFooter={[Function]}
|
||||
renderReplies={true}
|
||||
/>
|
||||
<Connect(AnnouncementBanner)
|
||||
navigator={
|
||||
Object {
|
||||
"pop": [MockFunction],
|
||||
"setButtons": [MockFunction],
|
||||
"setOnNavigatorEvent": [MockFunction],
|
||||
}
|
||||
}
|
||||
/>
|
||||
<Connect(RetryBarIndicator) />
|
||||
</View>
|
||||
`;
|
||||
|
|
@ -35,7 +35,7 @@ export default class ChannelPostList extends PureComponent {
|
|||
lastViewedAt: PropTypes.number,
|
||||
loadMorePostsVisible: PropTypes.bool.isRequired,
|
||||
navigator: PropTypes.object,
|
||||
postIds: PropTypes.array.isRequired,
|
||||
postIds: PropTypes.array,
|
||||
postVisibility: PropTypes.number,
|
||||
refreshing: PropTypes.bool.isRequired,
|
||||
theme: PropTypes.object.isRequired,
|
||||
|
|
@ -43,6 +43,7 @@ export default class ChannelPostList extends PureComponent {
|
|||
|
||||
static defaultProps = {
|
||||
postVisibility: ViewTypes.POST_VISIBILITY_CHUNK_SIZE,
|
||||
postIds: [],
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
|
|
@ -77,7 +78,7 @@ export default class ChannelPostList extends PureComponent {
|
|||
}
|
||||
|
||||
getVisiblePostIds = (props) => {
|
||||
return props.postIds.slice(0, props.postVisibility);
|
||||
return props.postIds?.slice(0, props.postVisibility) || [];
|
||||
};
|
||||
|
||||
goToThread = (post) => {
|
||||
|
|
@ -173,7 +174,7 @@ export default class ChannelPostList extends PureComponent {
|
|||
const {visiblePostIds} = this.state;
|
||||
let component;
|
||||
|
||||
if (!postIds.length && channelRefreshingFailed) {
|
||||
if (!postIds?.length && channelRefreshingFailed) {
|
||||
component = (
|
||||
<PostListRetry
|
||||
retry={this.loadPostsRetry}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
// 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';
|
||||
|
||||
import ChannelPostList from './channel_post_list';
|
||||
|
||||
describe('ChannelPostList', () => {
|
||||
const baseProps = {
|
||||
actions: {
|
||||
loadPostsIfNecessaryWithRetry: jest.fn(),
|
||||
loadThreadIfNecessary: jest.fn(),
|
||||
increasePostVisibility: jest.fn(),
|
||||
selectPost: jest.fn(),
|
||||
recordLoadTime: jest.fn(),
|
||||
refreshChannelWithRetry: jest.fn(),
|
||||
},
|
||||
channelId: 'current_channel_id',
|
||||
channelRefreshingFailed: false,
|
||||
currentUserId: 'current_user_id',
|
||||
lastViewedAt: 12345,
|
||||
loadMorePostsVisible: false,
|
||||
postIds: [],
|
||||
postVisibility: 15,
|
||||
refreshing: false,
|
||||
navigator: {
|
||||
pop: jest.fn(),
|
||||
setButtons: jest.fn(),
|
||||
setOnNavigatorEvent: jest.fn(),
|
||||
},
|
||||
theme: Preferences.THEMES.default,
|
||||
};
|
||||
|
||||
test('should match snapshot', async () => {
|
||||
const wrapper = shallow(
|
||||
<ChannelPostList {...baseProps}/>,
|
||||
);
|
||||
expect(wrapper.getElement()).toMatchSnapshot();
|
||||
|
||||
wrapper.setProps({postIds: null});
|
||||
expect(wrapper.getElement()).toMatchSnapshot();
|
||||
|
||||
wrapper.setProps({postIds: undefined});
|
||||
expect(wrapper.getElement()).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue