import "@testing-library/jest-dom"; import { render, screen } from "@testing-library/react"; import { MemoryRouter } from "react-router"; import { describe, expect, it, vi } from "vitest"; import { SidebarProvider } from "~/components/ui/sidebar"; import { NavSecondary } from "./nav-secondary"; vi.mock("~/hooks/use-mobile", () => ({ useIsMobile: () => false, })); describe("NavSecondary", () => { it("renders permitted collapsible parents as links with separate toggle controls", () => { render( ); expect(screen.getByRole("link", { name: "Settings" })).toHaveAttribute("href", "/settings"); expect(screen.getByRole("link", { name: "Settings" })).toHaveAttribute("data-active", "true"); expect(screen.getByRole("button", { name: "Toggle Settings" })).toBeInTheDocument(); expect(screen.getByRole("link", { name: "Profile" })).toHaveAttribute("href", "/settings/profile"); }); it("hides disabled secondary items and honors redirect targets", () => { render( ); expect(screen.getByRole("link", { name: "Profile" })).toHaveAttribute("href", "/settings/profile"); expect(screen.queryByRole("link", { name: "Disabled Plugin" })).not.toBeInTheDocument(); expect(screen.queryByRole("link", { name: "Disabled Root" })).not.toBeInTheDocument(); }); it("does not turn parents with only disabled children into links", () => { render( ); expect(screen.queryByRole("link", { name: "Settings" })).not.toBeInTheDocument(); expect(screen.queryByRole("button", { name: /Settings/ })).not.toBeInTheDocument(); expect(screen.queryByRole("link", { name: "Disabled Plugin" })).not.toBeInTheDocument(); }); });