Skip to content

Commit 71a0b95

Browse files
author
Balaji Sridharan
committed
🧪 test-fix: Update the test case to use the random month except the current month
- Update the logic of selecting the current month as it won't call onMonthChange when we try to select the same month
1 parent 47f8457 commit 71a0b95

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

‎src/test/calendar_test.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import DatePicker from "../index";
3636

3737
import {
3838
getKey,
39+
getRandomMonthExcludingCurrent,
3940
SafeElementWrapper,
4041
safeQuerySelector,
4142
safeQuerySelectorAll,
@@ -1287,11 +1288,10 @@ describe("Calendar", () => {
12871288
.safeQuerySelector("select")
12881289
.getElement();
12891290

1291+
const month = getRandomMonthExcludingCurrent();
12901292
fireEvent.change(select, {
12911293
target: {
1292-
value: Array.from<HTMLOptionElement>(
1293-
select.querySelectorAll("option"),
1294-
).at(-2)?.value,
1294+
value: month,
12951295
},
12961296
});
12971297

‎src/test/test_utils.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ export const range = (from: number, to: number): number[] => {
6868
return list;
6969
};
7070

71+
export const getRandomMonthExcludingCurrent = (): number => {
72+
const currentMonth = new Date().getMonth();
73+
74+
let randomMonth;
75+
do {
76+
randomMonth = Math.floor(Math.random() * 12);
77+
} while (randomMonth === currentMonth);
78+
79+
return randomMonth;
80+
};
81+
7182
export const openDateInput = (container: Element) => {
7283
const dateInput = container.querySelector("input")!;
7384
fireEvent.focus(dateInput);

0 commit comments

Comments
 (0)