Skip to content

Commit

Permalink
MM-14810 Fix for channel header loading in center channel (mattermost…
Browse files Browse the repository at this point in the history
…#2596)

* MM-14810 Fix for channel header loading in center channel

* Fix lint errors
  • Loading branch information
sudheerDev committed Apr 3, 2019
1 parent 87e17bd commit 6bc18af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion components/post_view/post_list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default class PostList extends React.PureComponent {
} else {
this.loadingMorePosts = false;
if (this.mounted && this.props.posts) {
const atEnd = !moreToLoad && this.props.posts.length < this.props.postVisibility;
const atEnd = !moreToLoad;
const newState = {
atEnd,
autoRetryEnable: true,
Expand Down
52 changes: 39 additions & 13 deletions components/post_view/post_list.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,31 @@
import React from 'react';
import {shallow} from 'enzyme';

import {mountWithIntl} from 'tests/helpers/intl-test-helper.jsx';

import PostList from 'components/post_view/post_list.jsx';
import {PostListRowListIds} from 'utils/constants.jsx';

const returnDummyPostsAndIds = () => {
const postsArray = [];
const Ids = [];
const createAtValue = 12346;
for (var i = 1; i <= 30; i++) {
const postCreatedAt = createAtValue + i;
postsArray.push({
id: `${postCreatedAt}`,
message: 'test',
create_at: postCreatedAt,
});
Ids.push(`${postCreatedAt}`);
}

return {
postsArray,
Ids,
};
};

describe('components/post_view/post_list', () => {
const posts = [{
id: 'postId',
Expand Down Expand Up @@ -40,19 +62,7 @@ describe('components/post_view/post_list', () => {
};

test('should return index of loader when all are unread messages in the view and call increasePostVisibility action', () => {
const postsArray = [];
const Ids = [];
const createAtValue = 12346;
for (var i = 1; i <= 30; i++) {
const postCreatedAt = createAtValue + i;
postsArray.push({
id: `${postCreatedAt}`,
message: 'test',
create_at: postCreatedAt,
});
Ids.push(`${postCreatedAt}`);
}

const {Ids, postsArray} = returnDummyPostsAndIds();
const postListIds = [...Ids, PostListRowListIds.START_OF_NEW_MESSAGES];
const props = {
...baseProps,
Expand All @@ -65,4 +75,20 @@ describe('components/post_view/post_list', () => {
expect(initScrollToIndex).toEqual({index: 31, position: 'start'}); //Loader will be at pos 31
expect(actions.increasePostVisibility).toHaveBeenCalledTimes(1);
});

test('should set the state of atEnd to true when increasePostVisibility returns moreToLoad false', async () => {
const increasePostVisibilityMock = jest.fn().mockResolvedValue({moreToLoad: false});
const props = {
...baseProps,
actions: {
...baseProps.actions,
increasePostVisibility: increasePostVisibilityMock,
},
};
const wrapper = mountWithIntl(<PostList {...props}/>);
await wrapper.instance().loadMorePosts();
expect(increasePostVisibilityMock).toHaveBeenCalledTimes(1);
wrapper.update();
expect(wrapper.state('atEnd')).toEqual(true);
});
});

0 comments on commit 6bc18af

Please sign in to comment.