Skip to content

Commit

Permalink
chore: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dujiaqi committed Sep 18, 2023
1 parent 213d2c5 commit 56a7fc5
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<MomentRangePicker
showTime
onCalendarChange={onCalendarChange}
/>,
);
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(
<MomentRangePicker showTime onCalendarChange={onCalendarChange} />,
);

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(
<MomentRangePicker
showTime
changeOnBlur
onChange={onChange}
onCalendarChange={onCalendarChange}
/>,
);

switchInput(container);

// one of the panel should be open
expect(baseElement.querySelector('.rc-picker-dropdown')).toBeTruthy();

expect(onCalendarChange).toHaveBeenCalled();
expect(onChange).not.toHaveBeenCalled();
});
});
});

0 comments on commit 56a7fc5

Please sign in to comment.