From fbee2fb6b6ec006ad52af1b4243d9a6196e0d46d Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 3 Mar 2020 13:35:46 -0300 Subject: [PATCH] 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 --- app/screens/more_channels/more_channels.js | 4 +- .../more_channels/more_channels.test.js | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/screens/more_channels/more_channels.js b/app/screens/more_channels/more_channels.js index 804f3cd5a..e11cff8e1 100644 --- a/app/screens/more_channels/more_channels.js +++ b/app/screens/more_channels/more_channels.js @@ -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}); diff --git a/app/screens/more_channels/more_channels.test.js b/app/screens/more_channels/more_channels.test.js index 9876dcd73..702b7a688 100644 --- a/app/screens/more_channels/more_channels.test.js +++ b/app/screens/more_channels/more_channels.test.js @@ -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( + , + {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( + , + {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( + , + {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( + , + {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); + }); });