ant-design-vue/components/date-picker/__tests__/other.test.js

89 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-01-12 11:33:27 +08:00
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import moment from 'moment';
import DatePicker from '../';
2019-09-10 18:57:08 +08:00
import LocaleProvider from '../../locale-provider';
import locale from '../../locale-provider/zh_CN';
2018-06-09 13:14:14 +08:00
2019-01-12 11:33:27 +08:00
const { MonthPicker, WeekPicker } = DatePicker;
2018-06-09 13:14:14 +08:00
2019-09-10 18:57:08 +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, async () => {
const wrapper = mount(
{
render() {
return (
<LocaleProvider locale={myLocale}>
<Picker {...{ value: date, ...props }} />
</LocaleProvider>
);
},
},
{ sync: false },
);
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
}
matchPicker('date', DatePicker);
matchPicker('dateTime', DatePicker, { showTime: true });
matchPicker('week', WeekPicker);
matchPicker('month', MonthPicker);
});
2018-06-09 13:14:14 +08:00
describe('MonthPicker and WeekPicker', () => {
it('render MonthPicker', async () => {
2019-01-12 11:33:27 +08:00
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
const wrapper = mount(MonthPicker, { propsData: { open: true }, sync: false });
2018-06-09 13:14:14 +08:00
await asyncExpect(() => {
2019-01-12 11:33:27 +08:00
wrapper.setProps({ value: birthday });
});
2018-06-09 13:14:14 +08:00
2019-01-12 11:33:27 +08:00
const calendarWrapper = mount(
{
render() {
return wrapper.find({ name: 'Trigger' }).vm.getComponent();
},
2018-06-09 13:14:14 +08:00
},
2019-01-12 11:33:27 +08:00
{ sync: false },
);
2018-06-09 13:14:14 +08:00
await asyncExpect(() => {
2019-01-12 11:33:27 +08:00
expect(calendarWrapper.html()).toMatchSnapshot();
});
});
2018-06-09 13:14:14 +08:00
it('render WeekPicker', async () => {
2019-01-12 11:33:27 +08:00
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
const wrapper = mount(WeekPicker, { propsData: { open: true }, sync: false });
2018-06-09 13:14:14 +08:00
await asyncExpect(() => {
2019-01-12 11:33:27 +08:00
wrapper.setProps({ value: birthday });
});
const calendarWrapper = mount(
{
render() {
return wrapper.find({ name: 'Trigger' }).vm.getComponent();
},
2018-06-09 13:14:14 +08:00
},
2019-01-12 11:33:27 +08:00
{ sync: false },
);
2018-06-09 13:14:14 +08:00
await asyncExpect(() => {
2019-01-12 11:33:27 +08:00
expect(calendarWrapper.html()).toMatchSnapshot();
});
});
});