// @vitest-environment jsdom import "@testing-library/jest-dom/vitest"; import { act, fireEvent, render, screen } from "@testing-library/react"; import { describe, expect, it, vi } from "vitest"; import { SidebarWithSections } from "."; describe("SidebarWithSections navigation motion", () => { it("uses caller-provided translated names for logo navigation", () => { const onLogoClick = vi.fn(); const { rerender } = render( , ); expect(screen.getByRole("link", { name: "Übersicht" })).toHaveAttribute("href", "/dashboard"); rerender( , ); fireEvent.click(screen.getByRole("button", { name: "Zur Übersicht" })); expect(onLogoClick).toHaveBeenCalledOnce(); }); it("smoothly transitions the full item scale in both directions", () => { const { container } = render(Dashboard); const itemSurface = container.querySelector('[data-slot="app-sidebar-nav-item-surface"]'); expect(itemSurface).toHaveClass( "pointer-events-none", "scale-100", "transition-[background-color,scale]", "duration-150", "ease-[cubic-bezier(0.4,0,0.2,1)]", "motion-reduce:transition-none", "group-hover/2713e17b:scale-[1.065]", "data-[sidebar-sweep-hover=true]:scale-[1.065]", ); }); it("pulses items crossed between fast pointer samples", () => { vi.useFakeTimers(); try { const { container } = render( CRM Leads Boards , ); const sidebar = container.querySelector("nav"); const items = container.querySelectorAll('[data-sidebar-hover-item="true"]'); const surfaces = container.querySelectorAll('[data-sidebar-hover-surface="true"]'); expect(sidebar).not.toBeNull(); expect(items).toHaveLength(3); items.forEach((item, index) => { const top = index * 40; vi.spyOn(item, "getBoundingClientRect").mockReturnValue({ top, bottom: top + 40, left: 0, right: 200, width: 200, height: 40, x: 0, y: top, toJSON: () => ({}), }); }); const movePointerTo = (clientY: number) => { const event = new Event("pointermove", { bubbles: true }); Object.defineProperty(event, "clientY", { value: clientY }); fireEvent(sidebar!, event); }; movePointerTo(20); movePointerTo(100); expect(surfaces[1]).toHaveAttribute("data-sidebar-sweep-hover", "true"); act(() => vi.advanceTimersByTime(150)); expect(surfaces[1]).not.toHaveAttribute("data-sidebar-sweep-hover"); } finally { vi.useRealTimers(); } }); });