/** * Unit tests for CalendarDay: click opens day detail only for current month; * other-month cells do not call onDayClick and are non-interactive (aria-disabled). */ import { describe, it, expect, beforeEach, vi } from "vitest"; import { render, screen, fireEvent } from "@testing-library/react"; import { CalendarDay } from "./CalendarDay"; import { resetAppStore } from "@/test/test-utils"; describe("CalendarDay", () => { const defaultProps = { dateKey: "2025-02-15", dayOfMonth: 15, isToday: false, duties: [], eventSummaries: [], onDayClick: () => {}, }; beforeEach(() => { resetAppStore(); }); it("calls onDayClick with dateKey and rect when clicked and isOtherMonth is false", () => { const onDayClick = vi.fn(); render( ); const button = screen.getByRole("button", { name: /15/ }); fireEvent.click(button); expect(onDayClick).toHaveBeenCalledTimes(1); expect(onDayClick).toHaveBeenCalledWith( "2025-02-15", expect.objectContaining({ width: expect.any(Number), height: expect.any(Number), top: expect.any(Number), left: expect.any(Number), }) ); }); it("does not call onDayClick when clicked and isOtherMonth is true", () => { const onDayClick = vi.fn(); render( ); const button = screen.getByRole("button", { name: /15/ }); fireEvent.click(button); expect(onDayClick).not.toHaveBeenCalled(); }); it("sets aria-disabled on the button when isOtherMonth is true", () => { render( {}} /> ); const button = screen.getByRole("button", { name: /15/ }); expect(button).toHaveAttribute("aria-disabled", "true"); }); it("is not disabled for interaction when isOtherMonth is false", () => { render( {}} /> ); const button = screen.getByRole("button", { name: /15/ }); expect(button.getAttribute("aria-disabled")).not.toBe("true"); }); });