|
|
@ -13,19 +13,16 @@ import Button from '../../radio/radioButton'; |
|
|
|
import Select from '../../select'; |
|
|
|
import Header, { type CalendarHeaderProps } from '../Header'; |
|
|
|
|
|
|
|
function calendarProps(): PickerPanelProps<any> { |
|
|
|
return (global as any).calendarProps; |
|
|
|
} |
|
|
|
|
|
|
|
function calendarHeaderProps(): CalendarHeaderProps<any> { |
|
|
|
return (global as any).calendarHeaderProps; |
|
|
|
} |
|
|
|
const ref: { |
|
|
|
calendarProps?: PickerPanelProps<unknown>; |
|
|
|
calendarHeaderProps?: CalendarHeaderProps<unknown>; |
|
|
|
} = {}; |
|
|
|
|
|
|
|
jest.mock('../Header', () => { |
|
|
|
const HeaderModule = jest.requireActual('../Header'); |
|
|
|
const HeaderComponent = HeaderModule.default; |
|
|
|
return (props: CalendarHeaderProps<any>) => { |
|
|
|
(global as any).calendarHeaderProps = props; |
|
|
|
ref.calendarHeaderProps = props; |
|
|
|
return <HeaderComponent {...props} />; |
|
|
|
}; |
|
|
|
}); |
|
|
@ -35,8 +32,8 @@ jest.mock('rc-picker', () => { |
|
|
|
const PickerPanelComponent = RcPicker.PickerPanel; |
|
|
|
return { |
|
|
|
...RcPicker, |
|
|
|
PickerPanel: (props: PickerPanelProps<any>) => { |
|
|
|
(global as any).calendarProps = props; |
|
|
|
PickerPanel: (props: PickerPanelProps<unknown>) => { |
|
|
|
ref.calendarProps = props; |
|
|
|
return <PickerPanelComponent {...props} />; |
|
|
|
}, |
|
|
|
}; |
|
|
@ -152,8 +149,8 @@ describe('Calendar', () => { |
|
|
|
it('getDateRange should returns a disabledDate function', () => { |
|
|
|
const validRange: [Moment.Moment, Moment.Moment] = [Moment('2018-02-02'), Moment('2018-05-18')]; |
|
|
|
render(<Calendar validRange={validRange} defaultValue={Moment('2018-02-02')} />); |
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-06-02'))).toBe(true); |
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-04-02'))).toBe(false); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-06-02'))).toBe(true); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-04-02'))).toBe(false); |
|
|
|
}); |
|
|
|
|
|
|
|
it('validRange should work with disabledDate function', () => { |
|
|
@ -162,11 +159,11 @@ describe('Calendar', () => { |
|
|
|
<Calendar validRange={validRange} disabledDate={data => data.isSame(Moment('2018-02-03'))} />, |
|
|
|
); |
|
|
|
|
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-02-01'))).toBe(true); |
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-02-02'))).toBe(false); |
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-02-03'))).toBe(true); |
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-02-04'))).toBe(false); |
|
|
|
expect(calendarProps().disabledDate?.(Moment('2018-06-01'))).toBe(true); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-02-01'))).toBe(true); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-02-02'))).toBe(false); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-02-03'))).toBe(true); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-02-04'))).toBe(false); |
|
|
|
expect(ref.calendarProps?.disabledDate?.(Moment('2018-06-01'))).toBe(true); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Calendar MonthSelect should display correct label', () => { |
|
|
@ -181,9 +178,9 @@ describe('Calendar', () => { |
|
|
|
const monthMode = 'month'; |
|
|
|
const yearMode = 'year'; |
|
|
|
const wrapper = render(<Calendar />); |
|
|
|
expect(calendarHeaderProps().mode).toEqual(monthMode); |
|
|
|
expect(ref.calendarHeaderProps?.mode).toEqual(monthMode); |
|
|
|
wrapper.rerender(<Calendar mode={yearMode} />); |
|
|
|
expect(calendarHeaderProps().mode).toEqual(yearMode); |
|
|
|
expect(ref.calendarHeaderProps?.mode).toEqual(yearMode); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Calendar should switch mode', () => { |
|
|
@ -191,9 +188,9 @@ describe('Calendar', () => { |
|
|
|
const yearMode = 'year'; |
|
|
|
const onPanelChangeStub = jest.fn(); |
|
|
|
const wrapper = render(<Calendar mode={yearMode} onPanelChange={onPanelChangeStub} />); |
|
|
|
expect(calendarHeaderProps().mode).toEqual(yearMode); |
|
|
|
expect(ref.calendarHeaderProps?.mode).toEqual(yearMode); |
|
|
|
wrapper.rerender(<Calendar mode={monthMode} onPanelChange={onPanelChangeStub} />); |
|
|
|
expect(calendarHeaderProps().mode).toEqual(monthMode); |
|
|
|
expect(ref.calendarHeaderProps?.mode).toEqual(monthMode); |
|
|
|
expect(onPanelChangeStub).toHaveBeenCalledTimes(0); |
|
|
|
}); |
|
|
|
|
|
|
@ -234,7 +231,7 @@ describe('Calendar', () => { |
|
|
|
const date = Moment(new Date(Date.UTC(2017, 7, 9, 8))); |
|
|
|
const wrapper = render(<Calendar onPanelChange={onPanelChange} value={date} />); |
|
|
|
|
|
|
|
expect(calendarHeaderProps().mode).toBe('month'); |
|
|
|
expect(ref.calendarHeaderProps?.mode).toBe('month'); |
|
|
|
expect(wrapper.container.querySelectorAll('.ant-picker-date-panel').length).toBe(1); |
|
|
|
expect(wrapper.container.querySelectorAll('.ant-picker-month-panel').length).toBe(0); |
|
|
|
fireEvent.click(wrapper.container.querySelector('.ant-radio-button-input[value="year"]')!); |
|
|
|