Skip to content

Commit 041a96b

Browse files
committed
test: parse date range
1 parent 9a8a4bd commit 041a96b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/test/datepicker_test.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,6 +3221,41 @@ describe("DatePicker", () => {
32213221

32223222
expect(onCalendarCloseSpy).toHaveBeenCalled();
32233223
});
3224+
3225+
it("should select start date and end date if user inputs the range manually in the input box", () => {
3226+
const onChangeSpy = jest.fn();
3227+
let instance: DatePicker | null = null;
3228+
const { container } = render(
3229+
<DatePicker
3230+
selectsRange
3231+
startDate={undefined}
3232+
endDate={undefined}
3233+
onChange={onChangeSpy}
3234+
ref={(node) => {
3235+
instance = node;
3236+
}}
3237+
/>,
3238+
);
3239+
3240+
expect(instance).toBeTruthy();
3241+
const input = safeQuerySelector<HTMLInputElement>(container, "input");
3242+
fireEvent.change(input, {
3243+
target: {
3244+
value: "03/04/2024 - 05/06/2024",
3245+
},
3246+
});
3247+
3248+
expect(onChangeSpy).toHaveBeenCalled();
3249+
expect(Array.isArray(onChangeSpy.mock.calls[0][0])).toBe(true);
3250+
expect(onChangeSpy.mock.calls[0][0][0]).toBeTruthy();
3251+
expect(onChangeSpy.mock.calls[0][0][1]).toBeTruthy();
3252+
expect(formatDate(onChangeSpy.mock.calls[0][0][0], "MM/dd/yyyy")).toBe(
3253+
"03/04/2024",
3254+
);
3255+
expect(formatDate(onChangeSpy.mock.calls[0][0][1], "MM/dd/yyyy")).toBe(
3256+
"05/06/2024",
3257+
);
3258+
});
32243259
});
32253260

32263261
describe("duplicate dates when multiple months", () => {

0 commit comments

Comments
 (0)