import { render, screen } from "@testing-library/react"; import { AnimationProvider, useAnimationConfig } from "./AnimationProvider"; // Mock do useReducedMotion jest.mock("@/app/hooks/useReducedMotion", () => ({ useReducedMotion: jest.fn(), })); // Test component that uses the hook function TestComponent() { const config = useAnimationConfig(); return (
{String(config.reducedMotion)}
{config.easings.easeOut}
{config.durations.normal}
{config.easings.spring.default.stiffness}
); } describe("AnimationProvider", () => { beforeEach(() => { jest.clearAllMocks(); }); it("provides animation config with reducedMotion false", () => { const { useReducedMotion } = jest.requireMock( "@/app/hooks/useReducedMotion", ); useReducedMotion.mockReturnValue(false); render( , ); expect(screen.getByTestId("reduced-motion")).toHaveTextContent("false"); expect(screen.getByTestId("ease-out")).toHaveTextContent( "cubic-bezier(0.16, 1, 0.3, 1)", ); expect(screen.getByTestId("duration-normal")).toHaveTextContent("0.6"); expect(screen.getByTestId("spring-default-stiffness")).toHaveTextContent( "200", ); }); it("provides animation config with reducedMotion true", () => { const { useReducedMotion } = jest.requireMock( "@/app/hooks/useReducedMotion", ); useReducedMotion.mockReturnValue(true); render( , ); expect(screen.getByTestId("reduced-motion")).toHaveTextContent("true"); }); it("provides all easing configurations", () => { const { useReducedMotion } = jest.requireMock( "@/app/hooks/useReducedMotion", ); useReducedMotion.mockReturnValue(false); render( , ); const config = screen.getByTestId("ease-out").textContent; expect(config).toBe("cubic-bezier(0.16, 1, 0.3, 1)"); }); it("provides all duration configurations", () => { const { useReducedMotion } = jest.requireMock( "@/app/hooks/useReducedMotion", ); useReducedMotion.mockReturnValue(false); render( , ); const duration = screen.getByTestId("duration-normal").textContent; expect(duration).toBe("0.6"); }); it("throws error when useAnimationConfig is used outside provider", () => { // Suppress console.error for this test const consoleError = jest .spyOn(console, "error") .mockImplementation(() => {}); expect(() => { render(); }).toThrow("useAnimationConfig must be used within AnimationProvider"); consoleError.mockRestore(); }); }); describe("useAnimationConfig", () => { it("returns config object with correct structure", () => { const { useReducedMotion } = jest.requireMock( "@/app/hooks/useReducedMotion", ); useReducedMotion.mockReturnValue(false); function ConfigStructureTest() { const config = useAnimationConfig(); return (
{String("reducedMotion" in config)}
{String("easings" in config)}
{String("durations" in config)}
{String("spring" in config.easings)}
); } render( , ); expect(screen.getByTestId("has-reduced-motion")).toHaveTextContent("true"); expect(screen.getByTestId("has-easings")).toHaveTextContent("true"); expect(screen.getByTestId("has-durations")).toHaveTextContent("true"); expect(screen.getByTestId("has-spring")).toHaveTextContent("true"); }); });