Skip to content

Commit

Permalink
Merge pull request #16 from ImJustAMan/master
Browse files Browse the repository at this point in the history
improve list component
  • Loading branch information
ImJustAMan authored May 24, 2021
2 parents 5f7fab4 + 1884672 commit 00de6bb
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/List/ListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const ListItem: React.FC<IListItemPropsType> = props => {
ListItem.defaultProps = {
subtitle: '',
extra: '',
showAll: false,
arrow: 'none',
};

Expand Down
10 changes: 0 additions & 10 deletions src/List/PropsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ type listItemArrowType = 'up' | 'down' | 'horizontal' | 'none';
* List properties
*/
export interface IListPropsType {
/**
* @description 是否设置列表圆角
* @default false
*/
radius?: boolean;
/**
* @description 列表头部内容
* @default ""
Expand Down Expand Up @@ -44,11 +39,6 @@ export interface IListItemPropsType {
* @type string | React.ReactElement
*/
extra?: renderType;
/**
* @description 列表额外内容是否换行显示全部内容
* @default false
*/
showAll?: boolean;
/**
* @description 列表尾端箭头方向 设置none时不显示
* @default "none"
Expand Down
20 changes: 20 additions & 0 deletions src/List/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`List List render correctly 1`] = `
<div
className="h-list"
>
<div
className="h-list-wrap"
>
<ListItem
arrow="horizontal"
extra="extra content"
subtitle="subtitle"
thumb="logo.png"
>
title
</ListItem>
</div>
</div>
`;
86 changes: 86 additions & 0 deletions src/List/__tests__/index.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { shallow } from 'enzyme';
import List from '@/List';
import toJson from 'enzyme-to-json';

const { Item } = List;

describe('List', () => {
it('List render correctly', () => {
const wrapper = shallow(
<List>
<Item
subtitle="subtitle"
thumb={require('../../../public/images/logo.png')}
extra="extra content"
arrow="horizontal"
>
title
</Item>
</List>,
);

expect(toJson(wrapper)).toMatchSnapshot();
});
describe('renderHeader', () => {
it('renderHeader is string', () => {
const wrapper = shallow(<List renderHeader="renderHeader" />);

expect(wrapper.find('.h-list-header').text()).toBe('renderHeader');
});

it('renderHeader is function', () => {
const wrapper = shallow(<List renderHeader={() => 'renderHeader'} />);

expect(wrapper.find('.h-list-header').text()).toBe('renderHeader');
});
});
describe('renderFooter', () => {
it('renderFooter is string', () => {
const wrapper = shallow(<List renderFooter="renderFooter" />);

expect(wrapper.find('.h-list-footer').text()).toBe('renderFooter');
});

it('renderFooter is function', () => {
const wrapper = shallow(<List renderFooter={() => 'renderFooter'} />);

expect(wrapper.find('.h-list-footer').text()).toBe('renderFooter');
});
});
describe('ListItem', () => {
it('subtitle', () => {
const wrapper = shallow(<Item subtitle="subtitle" />);

expect(wrapper.find('.h-list-item-subtitle').text()).toBe('subtitle');
});

it('extra', () => {
const wrapper = shallow(<Item extra="extra" />);

expect(wrapper.find('.h-list-item-extra').text()).toBe('extra');
});

it('arrow', () => {
const wrapper = shallow(<Item arrow="horizontal" />);

expect(wrapper.find('.icon-arrow-right')).toBeTruthy();
});

it('thumb', () => {
const wrapper = shallow(
<Item thumb={require('../../../public/images/logo.png')} />,
);

expect(wrapper.find('.h-list-item-thumb').find('img')).toBeTruthy();
});

it('onPress', () => {
const onPress = jest.fn();
const wrapper = shallow(<Item onPress={onPress} />);
wrapper.simulate('press');

expect(onPress).toBeCalled();
});
});
});
1 change: 0 additions & 1 deletion src/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const List: React.FC<IListPropsType> & { Item: typeof ListItem } = props => {

List.Item = ListItem;
List.defaultProps = {
radius: false,
renderHeader: '',
renderFooter: '',
};
Expand Down

0 comments on commit 00de6bb

Please sign in to comment.