Merge remote-tracking branch 'origin/master' into 4.0-prepare

This commit is contained in:
zombiej 2019-09-29 11:15:13 +08:00
commit 4d81cea17a
10 changed files with 126 additions and 5 deletions

View File

@ -443,6 +443,7 @@ exports[`renders ./components/avatar/demo/dynamic.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
U
</span>
@ -496,6 +497,7 @@ exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
Avatar
</span>
@ -517,6 +519,7 @@ exports[`renders ./components/avatar/demo/toggle-debug.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
Avatar
</span>
@ -565,6 +568,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
U
</span>
@ -574,6 +578,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
USER
</span>
@ -591,6 +596,7 @@ exports[`renders ./components/avatar/demo/type.md correctly 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
>
U
</span>

View File

@ -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<AvatarProps, AvatarState> {
state = {
scale: 1,
mounted: false,
isImgExist: true,
};
@ -53,6 +55,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
componentDidMount() {
this.setScale();
this.setState({ mounted: true });
}
componentDidUpdate(prevProps: AvatarProps) {
@ -105,7 +108,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
...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<AvatarProps, AvatarState> {
WebkitTransform: transformString,
transform: transformString,
};
const sizeChildrenStyle: React.CSSProperties =
typeof size === 'number'
? {
@ -160,9 +164,15 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
</span>
);
} else {
const childrenStyle: React.CSSProperties = {};
if (!mounted) {
childrenStyle.opacity = 0;
}
children = (
<span
className={`${prefixCls}-string`}
style={{ opacity: 0 }}
ref={(node: HTMLElement) => (this.avatarChildren = node)}
>
{children}

View File

@ -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(
<Collapse>
<Collapse.Panel header="This is panel header 1" key="1">
content
</Collapse.Panel>
</Collapse>,
);
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();
});
});

View File

@ -249,6 +249,7 @@ exports[`ConfigProvider components Avatar configProvider 1`] = `
>
<span
class="config-avatar-string"
style="opacity:0"
/>
</span>
`;
@ -259,6 +260,7 @@ exports[`ConfigProvider components Avatar normal 1`] = `
>
<span
class="ant-avatar-string"
style="opacity:0"
/>
</span>
`;
@ -269,6 +271,7 @@ exports[`ConfigProvider components Avatar prefixCls 1`] = `
>
<span
class="prefix-Avatar-string"
style="opacity:0"
/>
</span>
`;

View File

@ -48,7 +48,7 @@ class WeekPicker extends React.Component<any, WeekPickerState> {
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',
);
}

View File

@ -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(
<WeekPicker defaultValue={moment()} onChange={onChange} />,
);
wrapper
.find('.ant-calendar-picker-clear')
.hostNodes()
.simulate('click');
expect(onChange).toHaveBeenCalledWith(null, '');
});
});

View File

@ -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(<DatePicker value={{}} />);
}).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(<DatePicker defaultValue={{}} />);
}).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(<WeekPicker value={{}} />);
}).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(<WeekPicker defaultValue={{}} />);
}).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(<RangePicker value={[{}, {}]} />);
}).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(<RangePicker defaultValue={[{}, {}]} />);
}).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(<MonthPicker value={{}} />);
}).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(<MonthPicker defaultValue={{}} />);
}).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')
});
});

View File

@ -290,6 +290,7 @@ class Input extends React.Component<InputProps, any> {
// 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(

View File

@ -88,11 +88,14 @@ export default class Search extends React.Component<SearchProps, any> {
let button: React.ReactNode;
const enterButtonAsElement = enterButton as React.ReactElement<any>;
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',
...(enterButtonAsElement.type === Button
...(isAntdButton
? {
className: btnClassName,
size,

View File

@ -101,6 +101,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