From 7b57a29d3b0275c78d35e3d0ee818d968a5119ee Mon Sep 17 00:00:00 2001 From: ImJustAMan Date: Mon, 24 May 2021 14:39:10 +0800 Subject: [PATCH 1/2] fix(List): delete unuseful props --- src/List/ListItem.tsx | 1 - src/List/PropsType.ts | 10 ---------- src/List/index.tsx | 1 - 3 files changed, 12 deletions(-) diff --git a/src/List/ListItem.tsx b/src/List/ListItem.tsx index ef62fcd..6f2caab 100644 --- a/src/List/ListItem.tsx +++ b/src/List/ListItem.tsx @@ -64,7 +64,6 @@ const ListItem: React.FC = props => { ListItem.defaultProps = { subtitle: '', extra: '', - showAll: false, arrow: 'none', }; diff --git a/src/List/PropsType.ts b/src/List/PropsType.ts index 77bd4ce..7b90069 100644 --- a/src/List/PropsType.ts +++ b/src/List/PropsType.ts @@ -9,11 +9,6 @@ type listItemArrowType = 'up' | 'down' | 'horizontal' | 'none'; * List properties */ export interface IListPropsType { - /** - * @description 是否设置列表圆角 - * @default false - */ - radius?: boolean; /** * @description 列表头部内容 * @default "" @@ -44,11 +39,6 @@ export interface IListItemPropsType { * @type string | React.ReactElement */ extra?: renderType; - /** - * @description 列表额外内容是否换行显示全部内容 - * @default false - */ - showAll?: boolean; /** * @description 列表尾端箭头方向 设置none时不显示 * @default "none" diff --git a/src/List/index.tsx b/src/List/index.tsx index a897fbd..2770b73 100644 --- a/src/List/index.tsx +++ b/src/List/index.tsx @@ -28,7 +28,6 @@ const List: React.FC & { Item: typeof ListItem } = props => { List.Item = ListItem; List.defaultProps = { - radius: false, renderHeader: '', renderFooter: '', }; From 1884672eabefcad0f8f580138c97f14a3a067cb2 Mon Sep 17 00:00:00 2001 From: ImJustAMan Date: Mon, 24 May 2021 14:40:17 +0800 Subject: [PATCH 2/2] test(List): finish List test --- .../__snapshots__/index.spec.tsx.snap | 20 +++++ src/List/__tests__/index.spec.tsx | 86 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/List/__tests__/__snapshots__/index.spec.tsx.snap create mode 100644 src/List/__tests__/index.spec.tsx diff --git a/src/List/__tests__/__snapshots__/index.spec.tsx.snap b/src/List/__tests__/__snapshots__/index.spec.tsx.snap new file mode 100644 index 0000000..4d42ee4 --- /dev/null +++ b/src/List/__tests__/__snapshots__/index.spec.tsx.snap @@ -0,0 +1,20 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`List List render correctly 1`] = ` +
+
+ + title + +
+
+`; diff --git a/src/List/__tests__/index.spec.tsx b/src/List/__tests__/index.spec.tsx new file mode 100644 index 0000000..4c8cc40 --- /dev/null +++ b/src/List/__tests__/index.spec.tsx @@ -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( + + + title + + , + ); + + expect(toJson(wrapper)).toMatchSnapshot(); + }); + describe('renderHeader', () => { + it('renderHeader is string', () => { + const wrapper = shallow(); + + expect(wrapper.find('.h-list-header').text()).toBe('renderHeader'); + }); + + it('renderHeader is function', () => { + const wrapper = shallow( 'renderHeader'} />); + + expect(wrapper.find('.h-list-header').text()).toBe('renderHeader'); + }); + }); + describe('renderFooter', () => { + it('renderFooter is string', () => { + const wrapper = shallow(); + + expect(wrapper.find('.h-list-footer').text()).toBe('renderFooter'); + }); + + it('renderFooter is function', () => { + const wrapper = shallow( 'renderFooter'} />); + + expect(wrapper.find('.h-list-footer').text()).toBe('renderFooter'); + }); + }); + describe('ListItem', () => { + it('subtitle', () => { + const wrapper = shallow(); + + expect(wrapper.find('.h-list-item-subtitle').text()).toBe('subtitle'); + }); + + it('extra', () => { + const wrapper = shallow(); + + expect(wrapper.find('.h-list-item-extra').text()).toBe('extra'); + }); + + it('arrow', () => { + const wrapper = shallow(); + + expect(wrapper.find('.icon-arrow-right')).toBeTruthy(); + }); + + it('thumb', () => { + const wrapper = shallow( + , + ); + + expect(wrapper.find('.h-list-item-thumb').find('img')).toBeTruthy(); + }); + + it('onPress', () => { + const onPress = jest.fn(); + const wrapper = shallow(); + wrapper.simulate('press'); + + expect(onPress).toBeCalled(); + }); + }); +});