import { render, screen } from "@testing-library/react"; import { describe, it, expect, vi, beforeEach } from "vitest"; const nav = vi.hoisted(() => ({ pathname: "/" })); vi.mock("next/navigation", () => ({ usePathname: () => nav.pathname, useRouter: () => ({ push: vi.fn(), replace: vi.fn(), back: vi.fn() }), })); vi.mock("@/app/lib/ThemeContext", () => ({ useTheme: () => ({ isDark: false, toggle: vi.fn() }), })); vi.mock("next/link", () => ({ default: ({ href, children }: { href: string; children: React.ReactNode }) => ( {children} ), })); beforeEach(() => { nav.pathname = "/"; }); import AppHeader from "./AppHeader"; describe("AppHeader", () => { it("reserves the top safe-area inset so the header clears the notch/status bar", () => { const { container } = render(); const header = container.querySelector("header"); expect(header).not.toBeNull(); expect(header!.className).toContain("pt-[env(safe-area-inset-top)]"); // The height must be additive with the top inset, not a fixed border-box // budget the padding eats into — otherwise a non-zero inset (installed PWA // on a notched/Dynamic-Island device) collapses the content box and the // header contents overflow. Use min-h-14, never a bare fixed h-14. const tokens = header!.className.split(/\s+/); expect(tokens).toContain("min-h-14"); expect(tokens).not.toContain("h-14"); }); }); describe("AppHeader — homepage logo size", () => { const logo = (container: HTMLElement) => container.querySelector('svg[aria-label="Tastefully"]'); it("renders the logo 25% larger (30px) on the homepage", () => { nav.pathname = "/"; const { container } = render(); const svg = logo(container); expect(svg).not.toBeNull(); const cls = svg!.getAttribute("class") ?? ""; expect(cls).toContain("h-[30px]"); expect(cls.split(/\s+/)).not.toContain("h-6"); }); it("keeps the standard 24px logo on other main pages", () => { nav.pathname = "/store"; const { container } = render(); const svg = logo(container); expect(svg).not.toBeNull(); const cls = svg!.getAttribute("class") ?? ""; expect(cls.split(/\s+/)).toContain("h-6"); expect(cls).not.toContain("h-[30px]"); }); }); describe("AppHeader — consistent sub-page header (TASTE-148)", () => { // Every page opened from a Home tile uses back arrow + title, never the logo. const SUB_PAGES: Array<[string, string]> = [ ["/draw", "Lucky Draw"], ["/attendance", "Attendance"], ["/stage", "Stage"], ["/floorplan", "Floor Plan"], ["/goodie-bag", "Welcome Gift"], ]; it.each(SUB_PAGES)("%s shows a back button and the title %s (no logo)", (path, title) => { nav.pathname = path; const { container } = render(); expect(screen.getByRole("button", { name: "Back" })).toBeInTheDocument(); expect(screen.getByText(title)).toBeInTheDocument(); expect(container.querySelector('svg[aria-label="Tastefully"]')).toBeNull(); }); it.each(["/", "/events", "/store", "/settings"])("%s keeps the logo and has no back button", (path) => { nav.pathname = path; const { container } = render(); expect(container.querySelector('svg[aria-label="Tastefully"]')).not.toBeNull(); expect(screen.queryByRole("button", { name: "Back" })).toBeNull(); }); it("names the theme toggle for its next action", () => { nav.pathname = "/"; render(); expect(screen.getByRole("button", { name: "Switch to dark mode" })).toBeInTheDocument(); }); });