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:
parent
8052112260
commit
fbee2fb6b6
2 changed files with 52 additions and 2 deletions
|
|
@ -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});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue