diff --git a/app/screens/channel/channel_post_list/__snapshots__/channel_post_list.test.js.snap b/app/screens/channel/channel_post_list/__snapshots__/channel_post_list.test.js.snap new file mode 100644 index 000000000..11f682834 --- /dev/null +++ b/app/screens/channel/channel_post_list/__snapshots__/channel_post_list.test.js.snap @@ -0,0 +1,124 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ChannelPostList should match snapshot 1`] = ` + + + + + +`; + +exports[`ChannelPostList should match snapshot 2`] = ` + + + + + +`; + +exports[`ChannelPostList should match snapshot 3`] = ` + + + + + +`; diff --git a/app/screens/channel/channel_post_list/channel_post_list.js b/app/screens/channel/channel_post_list/channel_post_list.js index 1630cf61f..00affc27d 100644 --- a/app/screens/channel/channel_post_list/channel_post_list.js +++ b/app/screens/channel/channel_post_list/channel_post_list.js @@ -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 = ( { + 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( + , + ); + expect(wrapper.getElement()).toMatchSnapshot(); + + wrapper.setProps({postIds: null}); + expect(wrapper.getElement()).toMatchSnapshot(); + + wrapper.setProps({postIds: undefined}); + expect(wrapper.getElement()).toMatchSnapshot(); + }); +});