From 56a7fc5dddc3b05c742b2d968787448e00c02c31 Mon Sep 17 00:00:00 2001 From: dujiaqi Date: Mon, 18 Sep 2023 23:43:02 +0800 Subject: [PATCH] chore: add test case --- tests/range.spec.tsx | 52 ++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/tests/range.spec.tsx b/tests/range.spec.tsx index 52e732b29..c1f47d48e 100644 --- a/tests/range.spec.tsx +++ b/tests/range.spec.tsx @@ -1924,24 +1924,48 @@ describe('Picker.Range', () => { expect(document.querySelectorAll('.rc-picker-input')[1]).toHaveClass('rc-picker-input-active'); }); - it('dateTime mode switch should trigger onCalendarChange', () => { - const onCalendarChange = jest.fn(); - const { container } = render( - , - ); + describe('trigger onCalendarChange', () => { + const switchInput = (container: HTMLElement) => { + openPicker(container, 0); - openPicker(container, 0); + selectCell(8, 0); - selectCell(8, 0); + openPicker(container, 1); - openPicker(container, 1); + // onBlur is triggered when the switch is complete + closePicker(container, 0); + }; + + it('dateTime mode switch should trigger onCalendarChange', () => { + const onCalendarChange = jest.fn(); + const { container } = render( + , + ); + + switchInput(container); - // onBlur is triggered when the switch is complete - closePicker(container, 0); + expect(onCalendarChange).toHaveBeenCalled(); + }); - expect(onCalendarChange).toHaveBeenCalled(); + it('should only trigger onCalendarChange when showTime and changeOnBlur exist', () => { + const onCalendarChange = jest.fn(); + const onChange = jest.fn(); + const { container, baseElement } = render( + , + ); + + switchInput(container); + + // one of the panel should be open + expect(baseElement.querySelector('.rc-picker-dropdown')).toBeTruthy(); + + expect(onCalendarChange).toHaveBeenCalled(); + expect(onChange).not.toHaveBeenCalled(); + }); }); });