Files
co-lite/solvway-customer-portal/app/components/AppHeader.test.tsx
T
ngqileandClaude Opus 5.5 5ee51d1913 chore: copy kept Tastefully modules and portals into Co-Lite
Backend modules from tastefully 8bd93d15: core-libs, core-session,
api-gateway, mobile-api, services-auth, services-system,
services-counter, services-member, services-log, services-email.
solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal
from tastefully 8bd93d15. Copied as tracked files only.

Literal secrets replaced with environment placeholders:
- services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY,
  MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default)
- services-system: JUMIO_TOKEN, JUMIO_SECRET (optional)
- services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed
- core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default
  removed, ipgeolocation key read from IPGEOLOCATION_API_KEY
- services-system EkycAppConfig: commented Jumio credentials removed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 15:55:45 +08:00

98 lines
3.6 KiB
TypeScript

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 }) => (
<a href={href}>{children}</a>
),
}));
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(<AppHeader />);
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(<AppHeader />);
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(<AppHeader />);
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(<AppHeader />);
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(<AppHeader />);
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(<AppHeader />);
expect(screen.getByRole("button", { name: "Switch to dark mode" })).toBeInTheDocument();
});
});