Skip to content

Commit df2c0c0

Browse files
Add test for timepicker increment limits
1 parent ada61f4 commit df2c0c0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/test/timepicker_test.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,29 @@ describe("TimePicker", () => {
691691
);
692692
});
693693

694+
it("should not go above 23:30 when incrementing with 30-minute intervals", () => {
695+
const initialTime = new Date("February 28, 2018 11:30 PM");
696+
renderDatePickerFor(initialTime, {
697+
showTimeSelectOnly: true,
698+
timeIntervals: 30,
699+
});
700+
701+
if (!instance?.input) {
702+
throw new Error("input is null/undefined");
703+
}
704+
705+
fireEvent.focus(instance.input);
706+
// ArrowDown increments time
707+
fireEvent.keyDown(instance.input, getKey(KeyType.ArrowDown));
708+
709+
// Time should stay at 23:30 since we can't go past the last interval of the day
710+
const expectedTime = new Date("February 28, 2018 11:30 PM");
711+
expect(onChangeMoment).toBeDefined();
712+
expect(formatDate(onChangeMoment!, "MMMM d, yyyy p")).toBe(
713+
formatDate(expectedTime, "MMMM d, yyyy p"),
714+
);
715+
});
716+
694717
it("should update input value when using arrow keys", () => {
695718
const initialTime = new Date("February 28, 2018 4:00 PM");
696719
renderDatePickerFor(initialTime, {

0 commit comments

Comments
 (0)