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

78 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import moment from 'moment';
import DatePicker from '../';
2019-09-10 10:57:08 +00:00
import LocaleProvider from '../../locale-provider';
import locale from '../../locale-provider/zh_CN';
import { sleep } from '../../../tests/utils';
2018-06-09 05:14:14 +00:00
2019-01-12 03:33:27 +00:00
const { MonthPicker, WeekPicker } = DatePicker;
2018-06-09 05:14:14 +00:00
2019-09-10 10:57:08 +00: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}>
2020-07-28 15:48:15 +00:00
<Picker value={date} {...props} />
2019-09-10 10:57:08 +00:00
</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 05:14:14 +00:00
describe('MonthPicker and WeekPicker', () => {
2020-07-28 15:48:15 +00:00
beforeEach(() => {
document.body.innerHTML = '';
});
2018-06-09 05:14:14 +00:00
it('render MonthPicker', async () => {
2019-01-12 03:33:27 +00:00
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
2020-07-25 07:46:49 +00:00
const wrapper = mount(MonthPicker, { props: { open: true }, sync: false });
2018-06-09 05:14:14 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
wrapper.setProps({ value: birthday });
});
2018-06-09 05:14:14 +00:00
await asyncExpect(() => {
2020-07-28 15:48:15 +00:00
expect(document.body.innerHTML).toMatchSnapshot();
2019-01-12 03:33:27 +00:00
});
});
2018-06-09 05:14:14 +00:00
it('render WeekPicker', async () => {
2019-01-12 03:33:27 +00:00
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
2020-07-28 15:48:15 +00:00
const wrapper = mount(WeekPicker, { props: { open: false }, sync: false });
2018-06-09 05:14:14 +00:00
await asyncExpect(() => {
2020-07-28 15:48:15 +00:00
wrapper.setProps({ value: birthday, open: true });
2019-01-12 03:33:27 +00:00
});
await sleep(50);
2018-06-09 05:14:14 +00:00
await asyncExpect(() => {
2020-07-28 15:48:15 +00:00
expect(document.body.innerHTML).toMatchSnapshot();
2020-09-23 11:36:45 +00:00
}, 0);
2019-01-12 03:33:27 +00:00
});
});