forked from Ivasoft/mattermost-mobile
* 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:
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user