MM-22790 Fix Load more joinable/archived channels in more channels screeen (#3988)

* MM-22790 Fix Load more joinable/archived channels in more channels screen

* Add unit tests
This commit is contained in:
Elias Nahum 2020-03-03 13:35:46 -03:00 committed by GitHub
parent 8052112260
commit fbee2fb6b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 2 deletions

View file

@ -229,10 +229,10 @@ export default class MoreChannels extends PureComponent {
if (isPublic) {
this.publicPage += 1;
this.nextPublic = (data && !data.length);
this.nextPublic = data?.length > 0;
} else {
this.archivedPage += 1;
this.nextArchived = (data && !data.length);
this.nextArchived = data?.length > 0;
}
this.setState({loading: false});

View file

@ -110,4 +110,54 @@ describe('MoreChannels', () => {
instance.searchChannels('archived channel');
expect(wrapper.state('archivedChannels')).toEqual(baseProps.archivedChannels);
});
test('Allow load more public channels', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const instance = wrapper.instance();
wrapper.setState({typeOfChannels: 'public'});
instance.loadedChannels({data: ['channel-1', 'channel-2']});
expect(instance.nextPublic).toBe(true);
});
test('Prevent load more public channels', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const instance = wrapper.instance();
wrapper.setState({typeOfChannels: 'public'});
instance.loadedChannels({data: null});
expect(instance.nextPublic).toBe(false);
instance.loadedChannels({data: []});
expect(instance.nextPublic).toBe(false);
});
test('Allow load more archived channels', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const instance = wrapper.instance();
wrapper.setState({typeOfChannels: 'archived'});
instance.loadedChannels({data: ['archived-1', 'archived-2']});
expect(instance.nextArchived).toBe(true);
});
test('Prevent load more archived channels', () => {
const wrapper = shallow(
<MoreChannels {...baseProps}/>,
{context: {intl: {formatMessage: jest.fn()}}},
);
const instance = wrapper.instance();
wrapper.setState({typeOfChannels: 'archived'});
instance.loadedChannels({data: null});
expect(instance.nextArchived).toBe(false);
instance.loadedChannels({data: []});
expect(instance.nextArchived).toBe(false);
});
});