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