From 71a0b9513016785250d5fb5e8405daa4e9c69114 Mon Sep 17 00:00:00 2001 From: Balaji Sridharan Date: Tue, 5 Nov 2024 00:27:07 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test-fix:=20Update=20the=20test?= =?UTF-8?q?=20case=20to=20use=20the=20random=20month=20except=20the=20curr?= =?UTF-8?q?ent=20month?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update the logic of selecting the current month as it won't call onMonthChange when we try to select the same month --- src/test/calendar_test.test.tsx | 6 +++--- src/test/test_utils.ts | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/test/calendar_test.test.tsx b/src/test/calendar_test.test.tsx index 9bf6d34e9..e3c2cae9b 100644 --- a/src/test/calendar_test.test.tsx +++ b/src/test/calendar_test.test.tsx @@ -36,6 +36,7 @@ import DatePicker from "../index"; import { getKey, + getRandomMonthExcludingCurrent, SafeElementWrapper, safeQuerySelector, safeQuerySelectorAll, @@ -1287,11 +1288,10 @@ describe("Calendar", () => { .safeQuerySelector("select") .getElement(); + const month = getRandomMonthExcludingCurrent(); fireEvent.change(select, { target: { - value: Array.from( - select.querySelectorAll("option"), - ).at(-2)?.value, + value: month, }, }); diff --git a/src/test/test_utils.ts b/src/test/test_utils.ts index 5e576795b..54f8073c5 100644 --- a/src/test/test_utils.ts +++ b/src/test/test_utils.ts @@ -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);