[fix] broken test due to day number dupplication

This commit is contained in:
Camille Moussu
2025-07-28 12:00:55 +02:00
parent 2ad41dc4f5
commit a5c7265884
2 changed files with 14 additions and 4 deletions
@@ -12,6 +12,7 @@ describe("MiniCalendar", () => {
jest.clearAllMocks();
const dispatch = jest.fn() as ThunkDispatch<any, any, any>;
jest.spyOn(appHooks, "useAppDispatch").mockReturnValue(dispatch);
jest.useFakeTimers().clearAllTimers();
});
const renderCalendar = () => {
@@ -63,10 +64,14 @@ describe("MiniCalendar", () => {
for (let i = 0; i < 7; i++) {
const date = new Date(sunday);
date.setDate(sunday.getDate() + i);
const tile = (await screen.findAllByText(date.getDate())).find(
(el) => el.tagName.toLowerCase() === "abbr"
);
const dateTestId = `date-${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
preview.debug();
const tile = screen.getByTestId(dateTestId);
if (date.getTime() !== today.setHours(0, 0, 0, 0)) {
preview.debug();
expect(tile?.parentElement).toHaveClass("selectedWeek");
}
}
+6 -1
View File
@@ -207,7 +207,12 @@ export default function CalendarApp() {
classNames.push("event-dot");
}
return <div className={classNames.join(" ")}></div>;
return (
<div
className={classNames.join(" ")}
data-testid={`date-${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`}
></div>
);
}}
/>
<CalendarSelection