From 49c9ee40b4ab90f8ede150b963ac3878052317b9 Mon Sep 17 00:00:00 2001 From: ahauzq <30280271+ahauzq@users.noreply.github.com> Date: Thu, 26 Sep 2019 22:07:34 +0800 Subject: [PATCH 1/7] =?UTF-8?q?Input.tsx=E7=9A=84otherProps=E4=B8=BA?= =?UTF-8?q?=E4=BB=80=E4=B9=88=E4=B8=8D=E5=8E=BB=E6=8E=89size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 我觉得你们的otherProps推导竟然是any,所以不写size没报错 --- components/input/Input.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/components/input/Input.tsx b/components/input/Input.tsx index f92060c01b..7823ca97fb 100644 --- a/components/input/Input.tsx +++ b/components/input/Input.tsx @@ -290,6 +290,7 @@ class Input extends React.Component { // Input elements must be either controlled or uncontrolled, // specify either the value prop, or the defaultValue prop, but not both. 'defaultValue', + 'size', ]); return this.renderLabeledIcon( From 7ae663da6df38aa9dcc3d9440945f843145dd954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 27 Sep 2019 01:17:42 -0500 Subject: [PATCH 2/7] fix: ssr should not render string at first (#19029) * fix: ssr should not render string at first * update snapshot --- .../avatar/__tests__/__snapshots__/demo.test.js.snap | 6 ++++++ components/avatar/index.tsx | 12 +++++++++++- .../__tests__/__snapshots__/components.test.js.snap | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/components/avatar/__tests__/__snapshots__/demo.test.js.snap b/components/avatar/__tests__/__snapshots__/demo.test.js.snap index 1b650ba917..bcbedba0e2 100644 --- a/components/avatar/__tests__/__snapshots__/demo.test.js.snap +++ b/components/avatar/__tests__/__snapshots__/demo.test.js.snap @@ -433,6 +433,7 @@ exports[`renders ./components/avatar/demo/dynamic.md correctly 1`] = ` > U @@ -486,6 +487,7 @@ exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = ` > Avatar @@ -507,6 +509,7 @@ exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = ` > Avatar @@ -554,6 +557,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = ` > U @@ -563,6 +567,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = ` > USER @@ -580,6 +585,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = ` > U diff --git a/components/avatar/index.tsx b/components/avatar/index.tsx index f3d0536cbe..36829690e9 100644 --- a/components/avatar/index.tsx +++ b/components/avatar/index.tsx @@ -29,6 +29,7 @@ export interface AvatarProps { export interface AvatarState { scale: number; + mounted: boolean; isImgExist: boolean; } @@ -40,6 +41,7 @@ export default class Avatar extends React.Component { state = { scale: 1, + mounted: false, isImgExist: true, }; @@ -53,6 +55,7 @@ export default class Avatar extends React.Component { componentDidMount() { this.setScale(); + this.setState({ mounted: true }); } componentDidUpdate(prevProps: AvatarProps) { @@ -105,7 +108,7 @@ export default class Avatar extends React.Component { ...others } = this.props; - const { isImgExist, scale } = this.state; + const { isImgExist, scale, mounted } = this.state; const prefixCls = getPrefixCls('avatar', customizePrefixCls); @@ -144,6 +147,7 @@ export default class Avatar extends React.Component { WebkitTransform: transformString, transform: transformString, }; + const sizeChildrenStyle: React.CSSProperties = typeof size === 'number' ? { @@ -160,9 +164,15 @@ export default class Avatar extends React.Component { ); } else { + const childrenStyle: React.CSSProperties = {}; + if (!mounted) { + childrenStyle.opacity = 0; + } + children = ( (this.avatarChildren = node)} > {children} diff --git a/components/config-provider/__tests__/__snapshots__/components.test.js.snap b/components/config-provider/__tests__/__snapshots__/components.test.js.snap index b159a27c42..0799794609 100644 --- a/components/config-provider/__tests__/__snapshots__/components.test.js.snap +++ b/components/config-provider/__tests__/__snapshots__/components.test.js.snap @@ -360,6 +360,7 @@ exports[`ConfigProvider components Avatar configProvider 1`] = ` > `; @@ -370,6 +371,7 @@ exports[`ConfigProvider components Avatar normal 1`] = ` > `; @@ -380,6 +382,7 @@ exports[`ConfigProvider components Avatar prefixCls 1`] = ` > `; From 49ecf9b738a1562e114439f369ab0c1882a66211 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 27 Sep 2019 14:41:55 +0800 Subject: [PATCH 3/7] :white_check_mark: add more test cases for DatePicker --- components/date-picker/WeekPicker.tsx | 2 +- .../date-picker/__tests__/WeekPicker.test.js | 13 +++++ .../date-picker/__tests__/invalid.test.js | 52 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 components/date-picker/__tests__/invalid.test.js diff --git a/components/date-picker/WeekPicker.tsx b/components/date-picker/WeekPicker.tsx index 035e22fa4b..92c20dd2d8 100644 --- a/components/date-picker/WeekPicker.tsx +++ b/components/date-picker/WeekPicker.tsx @@ -47,7 +47,7 @@ class WeekPicker extends React.Component { const value = props.value || props.defaultValue; if (value && !interopDefault(moment).isMoment(value)) { throw new Error( - 'The value/defaultValue of DatePicker or MonthPicker must be ' + + 'The value/defaultValue of WeekPicker must be ' + 'a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value', ); } diff --git a/components/date-picker/__tests__/WeekPicker.test.js b/components/date-picker/__tests__/WeekPicker.test.js index 951e5bfe2f..7d08d99425 100644 --- a/components/date-picker/__tests__/WeekPicker.test.js +++ b/components/date-picker/__tests__/WeekPicker.test.js @@ -1,5 +1,6 @@ import React from 'react'; import { mount, render } from 'enzyme'; +import moment from 'moment'; import { setMockDate, resetMockDate } from '../../../tests/utils'; import DatePicker from '..'; import focusTest from '../../../tests/shared/focusTest'; @@ -71,4 +72,16 @@ describe('WeekPicker', () => { ), ).toMatchSnapshot(); }); + + it('should support allowClear', () => { + const onChange = jest.fn(); + const wrapper = mount( + , + ); + wrapper + .find('.ant-calendar-picker-clear') + .hostNodes() + .simulate('click'); + expect(onChange).toHaveBeenCalledWith(null, ''); + }); }); diff --git a/components/date-picker/__tests__/invalid.test.js b/components/date-picker/__tests__/invalid.test.js new file mode 100644 index 0000000000..ff8ff6d6c5 --- /dev/null +++ b/components/date-picker/__tests__/invalid.test.js @@ -0,0 +1,52 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import DatePicker from '..'; + +const { MonthPicker, WeekPicker, RangePicker } = DatePicker; + +describe('invalid value or defaultValue', () => { + beforeAll(() => { + jest.spyOn(console, 'error').mockImplementation(() => undefined); + }); + + afterAll(() => { + // eslint-disable-next-line no-console + console.error.mockRestore(); + }); + + it('DatePicker should throw error when value or defaultValue is not moment object', () => { + expect(() => { + mount(); + }).toThrow('The value/defaultValue of DatePicker or MonthPicker must be a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value'); + expect(() => { + mount(); + }).toThrow('The value/defaultValue of DatePicker or MonthPicker must be a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value') + }); + + it('WeekPicker should throw error when value or defaultValue is not moment object', () => { + expect(() => { + mount(); + }).toThrow('The value/defaultValue of WeekPicker must be a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value'); + expect(() => { + mount(); + }).toThrow('The value/defaultValue of WeekPicker must be a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value'); + }); + + it('RangePicker should throw error when value or defaultValue is not moment object', () => { + expect(() => { + mount(); + }).toThrow('The value/defaultValue of RangePicker must be a moment object array after `antd@2.0`, see: https://u.ant.design/date-picker-value'); + expect(() => { + mount(); + }).toThrow('The value/defaultValue of RangePicker must be a moment object array after `antd@2.0`, see: https://u.ant.design/date-picker-value') + }); + + it('MonthPicker should throw error when value or defaultValue is not moment object', () => { + expect(() => { + mount(); + }).toThrow('The value/defaultValue of DatePicker or MonthPicker must be a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value'); + expect(() => { + mount(); + }).toThrow('The value/defaultValue of DatePicker or MonthPicker must be a moment object after `antd@2.0`, see: https://u.ant.design/date-picker-value') + }); +}); From b536643f761ce3856fe54e8481fdefd26e41e3e7 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 27 Sep 2019 23:24:02 +0800 Subject: [PATCH 4/7] :white_check_mark: add test case for Collapse --- components/collapse/__tests__/index.test.js | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/components/collapse/__tests__/index.test.js b/components/collapse/__tests__/index.test.js index 41ab35b98f..35a065e9f8 100644 --- a/components/collapse/__tests__/index.test.js +++ b/components/collapse/__tests__/index.test.js @@ -1,9 +1,21 @@ import React from 'react'; import { mount } from 'enzyme'; -import Collapse from '..'; import mountTest from '../../../tests/shared/mountTest'; describe('Collapse', () => { + // Fix css-animation deps on these + // https://github.com/yiminghe/css-animation/blob/a5986d73fd7dfce75665337f39b91483d63a4c8c/src/Event.js#L44 + window.AnimationEvent = window.AnimationEvent || (() => {}); + window.TransitionEvent = window.TransitionEvent || (() => {}); + + afterAll(() => { + // restore it + delete window.AnimationEvent; + delete window.TransitionEvent; + }); + + // eslint-disable-next-line global-require + const Collapse = require('..').default; mountTest(Collapse); it('should support remove expandIcon', () => { @@ -24,4 +36,24 @@ describe('Collapse', () => { ); expect(wrapper.render()).toMatchSnapshot(); }); + + it('could be expand and collapse', () => { + jest.useFakeTimers(); + const wrapper = mount( + + + content + + , + ); + expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(false); + wrapper + .find('.ant-collapse-header') + .at(0) + .simulate('click'); + expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(true); + jest.runAllTimers(); + expect(wrapper.find('.ant-collapse-item').hasClass('ant-collapse-item-active')).toBe(true); + jest.useRealTimers(); + }); }); From 049799ed0f443eef2dec48aea085740f486b35bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=AF=E4=B8=80?= Date: Sat, 28 Sep 2019 10:20:47 +0800 Subject: [PATCH 5/7] fix: detect antd button by children.type.[staticProperty] instead of same class for HOC case (#19042) --- components/input/Search.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 1802248687..9ec2d2b1b3 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -92,7 +92,10 @@ export default class Search extends React.Component { let button: React.ReactNode; const enterButtonAsElement = enterButton as React.ReactElement; - if (enterButtonAsElement.type === Button || enterButtonAsElement.type === 'button') { + const isAntdButton = + enterButtonAsElement.type && + (enterButtonAsElement.type as typeof Button).__ANT_BUTTON === true; + if (isAntdButton || enterButtonAsElement.type === 'button') { button = React.cloneElement(enterButtonAsElement, { onClick: this.onSearch, key: 'enterButton', From 5728763dcc17dfbb23e512128f40fe1e89651655 Mon Sep 17 00:00:00 2001 From: shaodahong Date: Sat, 28 Sep 2019 11:58:09 +0800 Subject: [PATCH 6/7] fix: IE11 syntax error --- site/bisheng.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/site/bisheng.config.js b/site/bisheng.config.js index ae06141ab0..22d00bcf93 100644 --- a/site/bisheng.config.js +++ b/site/bisheng.config.js @@ -100,6 +100,7 @@ module.exports = { antd: path.join(process.cwd(), 'index'), site: path.join(process.cwd(), 'site'), 'react-router': 'react-router/umd/ReactRouter', + 'react-intl': 'react-intl/dist', }; // eslint-disable-next-line From 8219438ecde3c123d5ef58cbcd6a27983dabb458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=AF=E4=B8=80?= Date: Sat, 28 Sep 2019 13:52:59 +0800 Subject: [PATCH 7/7] Fix/detect antd button by static (#19045) * fix: detect antd button by children.type.[staticProperty] instead of same class for HOC case * fix: chore --- components/input/Search.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/input/Search.tsx b/components/input/Search.tsx index 9ec2d2b1b3..5e41606b87 100644 --- a/components/input/Search.tsx +++ b/components/input/Search.tsx @@ -99,7 +99,7 @@ export default class Search extends React.Component { button = React.cloneElement(enterButtonAsElement, { onClick: this.onSearch, key: 'enterButton', - ...(enterButtonAsElement.type === Button + ...(isAntdButton ? { className: btnClassName, size,