mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
This reverts commit 98387ad819
.
This commit is contained in:
parent
1329de5ebd
commit
fa14765695
@ -3,20 +3,11 @@ import { mount } from 'enzyme';
|
||||
import moment from 'moment';
|
||||
import MockDate from 'mockdate';
|
||||
import DatePicker from '..';
|
||||
import { selectDate } from './utils';
|
||||
import focusTest from '../../../tests/shared/focusTest';
|
||||
|
||||
describe('DatePicker', () => {
|
||||
focusTest(DatePicker);
|
||||
|
||||
beforeEach(() => {
|
||||
MockDate.set(new Date('2016-11-22').getTime() + (new Date().getTimezoneOffset() * 60 * 1000));
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
MockDate.reset();
|
||||
});
|
||||
|
||||
it('prop locale should works', () => {
|
||||
const locale = {
|
||||
lang: {
|
||||
@ -55,59 +46,12 @@ describe('DatePicker', () => {
|
||||
placeholder: 'Избор на час',
|
||||
},
|
||||
};
|
||||
MockDate.set(new Date('2016-11-22').getTime() + (new Date().getTimezoneOffset() * 60 * 1000));
|
||||
const birthday = moment('2000-01-01', 'YYYY-MM-DD');
|
||||
const wrapper = mount(
|
||||
<DatePicker open locale={locale} value={birthday} />
|
||||
);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// Fix https://github.com/ant-design/ant-design/issues/8885
|
||||
it('control value after panel closed', () => {
|
||||
class Test extends React.Component {
|
||||
state = {
|
||||
cleared: false,
|
||||
value: moment(),
|
||||
}
|
||||
|
||||
onChange = (value) => {
|
||||
let cleared = this.state.cleared;
|
||||
|
||||
if (cleared) {
|
||||
value = moment(moment(value).format('YYYY-MM-DD 12:12:12'));
|
||||
cleared = false;
|
||||
}
|
||||
|
||||
if (!value) {
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
this.setState({ value, cleared });
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<DatePicker
|
||||
showTime
|
||||
value={this.state.value}
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
onChange={this.onChange}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const wrapper = mount(<Test />);
|
||||
// clear input
|
||||
wrapper.find('.ant-calendar-picker-clear').hostNodes().simulate('click');
|
||||
// open panel
|
||||
wrapper.find('.ant-calendar-picker-input').simulate('click');
|
||||
// select a date
|
||||
selectDate(wrapper, moment('2016-11-13'));
|
||||
expect(wrapper.find('.ant-calendar-input').getDOMNode().value).toBe('2016-11-13 12:12:12');
|
||||
selectDate(wrapper, moment('2016-11-14'));
|
||||
expect(wrapper.find('.ant-calendar-input').getDOMNode().value).toBe('2016-11-14 12:12:12');
|
||||
MockDate.reset();
|
||||
});
|
||||
});
|
||||
|
@ -1,8 +0,0 @@
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
export function selectDate(wrapper, date, index) {
|
||||
let calendar = wrapper;
|
||||
if (index) {
|
||||
calendar = wrapper.find('.ant-calendar-range-part')[index];
|
||||
}
|
||||
calendar.find({ title: date.format('LL') }).simulate('click');
|
||||
}
|
@ -95,10 +95,6 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
|
||||
[`${prefixCls}-month`]: MonthCalendar === TheCalendar,
|
||||
});
|
||||
|
||||
if (value && localeCode) {
|
||||
value.locale(localeCode);
|
||||
}
|
||||
|
||||
let pickerProps: Object = {};
|
||||
let calendarProps: any = {};
|
||||
if (props.showTime) {
|
||||
@ -134,7 +130,6 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
|
||||
monthCellContentRender={props.monthCellContentRender}
|
||||
renderFooter={this.renderFooter}
|
||||
onPanelChange={props.onPanelChange}
|
||||
value={value}
|
||||
/>
|
||||
);
|
||||
|
||||
@ -161,6 +156,10 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
|
||||
</div>
|
||||
);
|
||||
|
||||
const pickerValue = value;
|
||||
if (pickerValue && localeCode) {
|
||||
pickerValue.locale(localeCode);
|
||||
}
|
||||
return (
|
||||
<span
|
||||
className={classNames(props.className, props.pickerClass)}
|
||||
@ -172,7 +171,7 @@ export default function createPicker(TheCalendar: React.ComponentClass): any {
|
||||
{...props}
|
||||
{...pickerProps}
|
||||
calendar={calendar}
|
||||
value={value}
|
||||
value={pickerValue}
|
||||
prefixCls={`${prefixCls}-picker-container`}
|
||||
style={props.popupStyle}
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user