Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading