2017-08-31 20:44:22 +08:00
|
|
|
import moment from 'moment';
|
2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
2018-06-22 21:05:13 +08:00
|
|
|
import DatePicker from '..';
|
2022-06-22 14:57:09 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2022-08-18 17:40:47 +08:00
|
|
|
import type { Locale } from '../../locale-provider';
|
2019-01-15 16:58:40 +08:00
|
|
|
import LocaleProvider from '../../locale-provider';
|
|
|
|
import locale from '../../locale-provider/zh_CN';
|
2021-05-05 22:28:56 +08:00
|
|
|
import jaJP from '../../locale/ja_JP';
|
|
|
|
import zhTW from '../locale/zh_TW';
|
2022-08-18 17:40:47 +08:00
|
|
|
import { render } from '../../../tests/utils';
|
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');
|
2022-08-18 17:40:47 +08:00
|
|
|
function matchPicker(name: string, Picker: typeof MonthPicker | typeof WeekPicker, props?: any) {
|
2019-01-15 16:58:40 +08:00
|
|
|
it(name, () => {
|
2022-08-18 17:40:47 +08:00
|
|
|
const { container } = render(
|
|
|
|
<LocaleProvider locale={myLocale as Locale}>
|
2019-01-15 16:58:40 +08:00
|
|
|
<Picker value={date} {...props} />
|
|
|
|
</LocaleProvider>,
|
|
|
|
);
|
2022-08-18 17:40:47 +08:00
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2019-01-15 16:58:40 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2022-08-18 17:40:47 +08:00
|
|
|
const { container } = render(<MonthPicker open value={birthday} />);
|
|
|
|
expect(container.querySelector('div.ant-picker-dropdown')?.parentNode).toMatchSnapshot();
|
2017-08-31 20:44:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it('render WeekPicker', () => {
|
|
|
|
const birthday = moment('2000-01-01', 'YYYY-MM-DD').locale('zh-cn');
|
2022-08-18 17:40:47 +08:00
|
|
|
const { container } = render(<WeekPicker open value={birthday} />);
|
|
|
|
expect(container.querySelector('div.ant-picker-dropdown')?.parentNode).toMatchSnapshot();
|
2017-08-31 20:44:22 +08:00
|
|
|
});
|
|
|
|
});
|
2021-05-05 22:28:56 +08:00
|
|
|
|
|
|
|
describe('Override locale setting of the ConfigProvider', () => {
|
|
|
|
it('DatePicker', () => {
|
2022-08-18 17:40:47 +08:00
|
|
|
const { container } = render(
|
2021-05-05 22:28:56 +08:00
|
|
|
<ConfigProvider locale={jaJP}>
|
|
|
|
<DatePicker locale={zhTW} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2022-08-18 17:40:47 +08:00
|
|
|
expect(container.querySelector('input')?.placeholder).toEqual('請選擇日期');
|
2021-05-05 22:28:56 +08:00
|
|
|
});
|
|
|
|
it('RangePicker', () => {
|
2022-08-18 17:40:47 +08:00
|
|
|
const { container } = render(
|
2021-05-05 22:28:56 +08:00
|
|
|
<ConfigProvider locale={jaJP}>
|
|
|
|
<DatePicker.RangePicker locale={zhTW} />
|
|
|
|
</ConfigProvider>,
|
|
|
|
);
|
2022-08-18 17:40:47 +08:00
|
|
|
expect(container.querySelectorAll('input')[0]?.placeholder).toEqual('開始日期');
|
|
|
|
expect(container.querySelectorAll('input')[1]?.placeholder).toEqual('結束日期');
|
2021-05-05 22:28:56 +08:00
|
|
|
});
|
|
|
|
});
|