import { render, screen } from "@testing-library/react"; import { describe, it, expect, vi } from "vitest"; // Non-auth path so the nav renders (it returns null on auth paths). vi.mock("next/navigation", () => ({ usePathname: () => "/", useRouter: () => ({ push: vi.fn(), replace: vi.fn() }), })); vi.mock("@/app/lib/ThemeContext", () => ({ useTheme: () => ({ isDark: false, toggle: vi.fn() }), })); // next/link needs the app-router context; stub it to a plain anchor. vi.mock("next/link", () => ({ default: ({ href, children, className }: { href: string; children: React.ReactNode; className?: string }) => ( {children} ), })); import BottomNav from "./BottomNav"; describe("BottomNav", () => { it("reserves the bottom safe-area inset so controls clear the home indicator", () => { const { container } = render(); const nav = container.querySelector("nav"); expect(nav).not.toBeNull(); expect(nav!.className).toContain("pb-[env(safe-area-inset-bottom)]"); }); it("gives the icon-only centre check-in button an accessible name (TASTE-148)", () => { render(); expect(screen.getByRole("button", { name: "Scan QR to check in" })).toBeInTheDocument(); }); describe("at large device font sizes", () => { // Regression: at 150–200% font the rem-based bar/FAB ballooned, labels touched, and the // right-hand tabs ran off a 390px screen. These guard the intent; the layout itself was // verified in a real browser at 100/150/200%. it("caps each tab label's size so four labels still fit beside the check-in button", () => { render(); for (const label of ["Home", "Events", "Points", "Profile"]) { const el = screen.getByText(label); // jsdom cannot parse min() in inline styles, so the cap is a Tailwind class. expect(el.className).toContain("text-[length:min(0.875rem,20px)]"); expect(el.className).toContain("whitespace-nowrap"); } }); it("lets the bar height follow its content instead of a fixed rem height", () => { const { container } = render(); const row = container.querySelector("nav > div") as HTMLElement; const tokens = row.className.split(/\s+/); expect(tokens).toContain("min-h-[64px]"); expect(tokens).not.toContain("h-16"); }); it("keeps the check-in button and its spacer a fixed 64px so they do not grow with the font", () => { render(); const fab = screen.getByRole("button", { name: "Scan QR to check in" }); expect(fab.className).toContain("w-[64px]"); expect(fab.className).toContain("h-[64px]"); expect(fab.className).not.toMatch(/(^|\s)w-16(\s|$)/); // the spacer column that reserves the FAB's width in the row expect((fab.closest(".relative.flex.justify-center") as HTMLElement).className).toContain("w-[64px]"); }); it("lets a tab shrink (min-w-0) so one long label cannot push its neighbours off screen", () => { render(); expect(screen.getByText("Profile").closest("a")!.className).toContain("min-w-0"); }); }); });