// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react'; import {View} from 'react-native'; import {shallow} from 'enzyme'; import Preferences from 'mattermost-redux/constants/preferences'; import CustomList, {FLATLIST, SECTIONLIST} from './index'; describe('CustomList', () => { const baseProps = { data: [{username: 'username_1'}, {username: 'username_2'}], listType: FLATLIST, loading: false, loadingComponent: (), onLoadMore: jest.fn(), onRowPress: jest.fn(), onRowSelect: null, renderItem: jest.fn(), listInitialSize: 0, listScrollRenderAheadDistance: 0, showSections: true, selectable: true, theme: Preferences.THEMES.default, }; test('should match snapshot with FlatList', () => { const wrapper = shallow( ); expect(wrapper.getElement()).toMatchSnapshot(); expect(wrapper.find('FlatList')).toHaveLength(1); }); test('should match snapshot with SectionList', () => { const props = { ...baseProps, listType: SECTIONLIST, }; const wrapper = shallow( ); expect(wrapper.getElement()).toMatchSnapshot(); expect(wrapper.find('SectionList')).toHaveLength(1); }); test('should match snapshot, renderSectionHeader', () => { const wrapper = shallow( ); const section = { id: 'section_id', }; expect(wrapper.instance().renderSectionHeader({section})).toMatchSnapshot(); }); test('should call props.renderItem on renderItem', () => { const props = {...baseProps}; const wrapper = shallow( ); wrapper.instance().renderItem({item: {id: 'item_id', selected: true}, index: 0, section: null}); expect(props.renderItem).toHaveBeenCalledTimes(1); }); test('should match snapshot, renderSeparator', () => { const wrapper = shallow( ); expect(wrapper.instance().renderSeparator()).toMatchSnapshot(); }); test('should match snapshot, renderFooter', () => { const props = {...baseProps}; const wrapper = shallow( ); // should return null expect(wrapper.instance().renderFooter()).toMatchSnapshot(); // should return element wrapper.setProps({loading: true}); expect(wrapper.instance().renderFooter()).toMatchSnapshot(); }); });