2017-08-31 20:44:22 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount, render } from 'enzyme';
|
|
|
|
import moment from 'moment';
|
2018-06-22 21:05:13 +08:00
|
|
|
import DatePicker from '..';
|
2019-01-15 16:58:40 +08:00
|
|
|
import LocaleProvider from '../../locale-provider';
|
|
|
|
import locale from '../../locale-provider/zh_CN';
|
2018-01-13 19:11:53 +08:00
|
|
|
|
|
|
|
const { MonthPicker, WeekPicker } = DatePicker;
|
2017-08-31 20:44:22 +08:00
|
|
|
|
2019-01-15 16:58:40 +08:00
|
|
|
describe('Picker format by locale', () => {
|
|
|
|
const myLocale = {
|
|
|
|
...locale,
|
|
|
|
DatePicker: {
|
|
|
|
...locale.DatePicker,
|
|
|
|
dateFormat: 'YYYY 年 M 月 D 日',
|
|
|
|
dateTimeFormat: 'YYYY 年 M 月 D 日 H 时 m 分 s 秒',
|
|
|
|
weekFormat: 'YYYY 年 W 周',
|
|
|
|
monthFormat: 'YYYY 年 M 月',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const date = moment('2000-01-01', 'YYYY-MM-DD');
|
|
|
|
function matchPicker(name, Picker, props) {
|
|
|
|
it(name, () => {
|
|
|
|
const wrapper = mount(
|
|
|
|
<LocaleProvider locale={myLocale}>
|
|
|
|
<Picker value={date} {...props} />
|
|
|
|
</LocaleProvider>,
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(wrapper.render()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
matchPicker('date', DatePicker);
|
|
|
|
matchPicker('dateTime', DatePicker, { showTime: true });
|
|
|
|
matchPicker('week', WeekPicker);
|
|
|
|
matchPicker('month', MonthPicker);
|
|
|
|
});
|
|
|
|
|
2017-08-31 20:44:22 +08:00
|
|
|
describe('MonthPicker and WeekPicker', () => {
|
|
|
|
it('render MonthPicker', () => {
|
|
|
|
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<MonthPicker open />);
|
2017-08-31 20:44:22 +08:00
|
|
|
wrapper.setProps({ value: birthday });
|
2018-12-07 20:02:01 +08:00
|
|
|
expect(
|
|
|
|
render(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
),
|
|
|
|
).toMatchSnapshot();
|
2017-08-31 20:44:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('render WeekPicker', () => {
|
|
|
|
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
|
2018-12-07 20:02:01 +08:00
|
|
|
const wrapper = mount(<WeekPicker open />);
|
2017-08-31 20:44:22 +08:00
|
|
|
wrapper.setProps({ value: birthday });
|
2018-12-07 20:02:01 +08:00
|
|
|
expect(
|
|
|
|
render(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
),
|
|
|
|
).toMatchSnapshot();
|
2017-08-31 20:44:22 +08:00
|
|
|
});
|
|
|
|
});
|