Skip to content

Commit

Permalink
Merge pull request #5207 from qburst/issue-5206/fix/onMonthChange-tes…
Browse files Browse the repository at this point in the history
…t-case-fix

🧪 test-fix: Update the test case to use the random month except the current month
  • Loading branch information
martijnrusschen authored Nov 4, 2024
2 parents e7d320b + 71a0b95 commit cba30e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/test/calendar_test.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import DatePicker from "../index";

import {
getKey,
getRandomMonthExcludingCurrent,
SafeElementWrapper,
safeQuerySelector,
safeQuerySelectorAll,
Expand Down Expand Up @@ -1287,11 +1288,10 @@ describe("Calendar", () => {
.safeQuerySelector("select")
.getElement();

const month = getRandomMonthExcludingCurrent();
fireEvent.change(select, {
target: {
value: Array.from<HTMLOptionElement>(
select.querySelectorAll("option"),
).at(-2)?.value,
value: month,
},
});

Expand Down
11 changes: 11 additions & 0 deletions src/test/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export const range = (from: number, to: number): number[] => {
return list;
};

export const getRandomMonthExcludingCurrent = (): number => {
const currentMonth = new Date().getMonth();

let randomMonth;
do {
randomMonth = Math.floor(Math.random() * 12);
} while (randomMonth === currentMonth);

return randomMonth;
};

export const openDateInput = (container: Element) => {
const dateInput = container.querySelector("input")!;
fireEvent.focus(dateInput);
Expand Down

0 comments on commit cba30e2

Please sign in to comment.