Skip to content

Commit 94457ed

Browse files
test: add edge case test for selectsRange with only end date
1 parent a59fdee commit 94457ed

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/test/timezone_test.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,40 @@ describe("DatePicker with timeZone prop", () => {
575575
expect(changedEndDate).toBeNull();
576576
});
577577

578+
it("should handle time change with timezone and selectsRange with only end date (edge case)", () => {
579+
const endDate = new Date("2024-06-20T14:00:00Z");
580+
const onChangeMock = jest.fn();
581+
582+
const { container } = render(
583+
<DatePicker
584+
selectsRange
585+
startDate={null}
586+
endDate={endDate}
587+
onChange={onChangeMock}
588+
timeZone="America/New_York"
589+
showTimeInput
590+
inline
591+
/>,
592+
);
593+
594+
// Find the end time input and change it
595+
const timeInputs = container.querySelectorAll(
596+
".react-datepicker-time__input input",
597+
);
598+
expect(timeInputs.length).toBe(2);
599+
600+
// Change the end time input
601+
fireEvent.change(timeInputs[1]!, { target: { value: "16:45" } });
602+
603+
// onChange should have been called with timezone conversion
604+
expect(onChangeMock).toHaveBeenCalled();
605+
const [changedStartDate, changedEndDate] = onChangeMock.mock.calls[0][0];
606+
607+
// Start date should be null, end date should be converted
608+
expect(changedStartDate).toBeNull();
609+
expect(changedEndDate).toBeInstanceOf(Date);
610+
});
611+
578612
it("should handle time change with timezone and selectsRange using legacy showTimeSelect (both dates)", () => {
579613
// Mock ResizeObserver
580614
const mockResizeObserver = jest.fn().mockImplementation(() => ({

0 commit comments

Comments
 (0)