Automated cherry pick of #3988 (#3991)

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

* Add unit tests

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
Mattermost Build
2020-03-03 17:40:11 +01:00
committed by GitHub
parent 446ddf91d4
commit c009047003
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);
});
});